#P8864. 「KDOI-03」序列变换

    ID: 9890 远端评测题 4000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP2022洛谷原创O2优化动态规划优化矩阵加速四边形不等式

「KDOI-03」序列变换

Problem Description

You are given a 01\tt01 sequence aa of length nn and qq queries, with query parameter kk.

In each query, you are given L,RL, R with 1LRn1 \le L \le R \le n. You may perform the following operation:

  • Choose an index L<iRL < i \le R.
  • Set ai1a_{i-1} to ai1aia_{i-1} \oplus a_i, and set ai+1a_{i+1} to ai+1aia_{i+1} \oplus a_i. If i=ni = n, then ai+1a_{i+1} is not changed. Here \oplus denotes the bitwise XOR operation.

Find the minimum number of operations needed so that there are at most kk 1\tt1's in the interval [L,R][L, R]. 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 n,k,qn, k, q.

The second line contains nn non-negative integers a1,a2,,ana_1, a_2, \cdots, a_n.

The next qq lines each contain two positive integers L,RL, R, representing one query.

Output Format

Write output to standard output.

Output qq 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 0\tt0 and red represents 1\tt1. The initial sequence is as follows:

For the 1st query, choose i=3i = 3, and the sequence becomes:

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

[Sample 2 Explanation]

For the 1st query, since among a12,a13,a14,a15a_{12}, a_{13}, a_{14}, a_{15} there are only 22 1\tt1's, no operation is needed.

For the 6th query, you can choose i={7,8,9,10,11,12}i = \{7, 8, 9, 10, 11, 12\} in order.

[Sample 3]

See control/control3.in and control/control3.ans in the contestant files.

This sample satisfies the constraints of test points 7107 \sim 10.

[Sample 4]

See control/control4.in and control/control4.ans in the contestant files.

This sample satisfies the constraints of test points 151715 \sim 17.

[Sample 5]

See control/control5.in and control/control5.ans in the contestant files.

This sample satisfies the constraints of test points 182118 \sim 21.


[Constraints]

For 100%100\% of the testdata: 2n3 0002 \le n \le 3~000, 1kmin(n,1 000)1 \le k \le \min(n, 1~000), 1q5×1051 \le q \le 5 \times 10^5, 0ai10 \le a_i \le 1.

Test Point ID nn \le kk \le qq \le Special Property
131 \sim 3 8080 5050 2 0002~000 None
464 \sim 6 400400 300300 11 kk is even
7107 \sim 10 22 10 00010~000 None
111411 \sim 14 300300
151715 \sim 17 3 0003~000 1010 5×1055 \times 10^5
182118 \sim 21 1 0001~000 kk is even
222522 \sim 25 None

Translated by ChatGPT 5