#P8864. 「KDOI-03」序列变换
「KDOI-03」序列变换
Problem Description
You are given a sequence of length and queries, with query parameter .
In each query, you are given with . You may perform the following operation:
- Choose an index .
- Set to , and set to . If , then is not changed. Here denotes the bitwise XOR operation.
Find the minimum number of operations needed so that there are at most 's in the interval . The queries are independent, meaning that after each query, the sequence is reset to the initial sequence.
Input Format
Read input from standard input.
The first line contains three positive integers .
The second line contains non-negative integers .
The next lines each contain two positive integers , representing one query.
Output Format
Write output to standard output.
Output lines in total, each containing one integer, the answer for the corresponding query.
5 1 2
1 1 1 0 1
2 3
1 3
1
1
20 3 22
0 0 1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 1 0 1
12 15
1 6
5 10
2 5
9 18
6 17
2 13
4 16
2 8
9 19
10 15
7 15
1 3
14 18
6 17
12 14
7 16
14 18
11 12
3 5
3 6
3 15
0
1
0
0
0
6
3
5
1
0
0
0
0
0
6
0
0
0
0
0
1
3
Hint
[Sample 1 Explanation]
As shown in the figure, green represents and red represents . The initial sequence is as follows:

For the 1st query, choose , and the sequence becomes:

For the 2nd query, choose , and the sequence becomes:

[Sample 2 Explanation]
For the 1st query, since among there are only 's, no operation is needed.
For the 6th query, you can choose in order.
[Sample 3]
See control/control3.in and control/control3.ans in the contestant files.
This sample satisfies the constraints of test points .
[Sample 4]
See control/control4.in and control/control4.ans in the contestant files.
This sample satisfies the constraints of test points .
[Sample 5]
See control/control5.in and control/control5.ans in the contestant files.
This sample satisfies the constraints of test points .
[Constraints]
For of the testdata: , , , .
| Test Point ID | Special Property | |||
|---|---|---|---|---|
| None | ||||
| is even | ||||
| None | ||||
| is even | ||||
| None |
Translated by ChatGPT 5