#P11696. [JRKSJ ExR] 七影蝶

[JRKSJ ExR] 七影蝶

Background

Problem Description

Kyujima Kamome gives you a non-negative integer sequence a1na_{1\sim n} of length nn.

Then there are qq queries. Each query gives non-negative integers L,RL, R. You need to compute

$$\max_{x=L}^R\left(\sum_{i=1}^n\mathrm{popcount}(a_i+x)\right)$$

where popcount(x)\mathrm{popcount}(x) denotes the number of 11 bits in the binary representation of xx.

Input Format

The first line contains two integers n,qn, q.
The second line contains nn integers representing the sequence a1na_{1\sim n}.
The following qq lines each contain two integers L,RL, R, representing one query.

Output Format

Output qq lines. The ii-th line contains one integer representing the answer to the ii-th query.

6 6
1 1 4 5 1 4
1 10
1 5
3 6
4 7
3 9
2 5
19
13
16
16
16
13
10 10
765 523 255 781 647 98 451 636 109 771
394 405
128 161
332 565
996 1003
3 116
403 486
255 582
744 861
399 408
528 996
58
59
69
68
66
62
69
75
58
75

Hint

Sample Explanation

For sample 11, the maximum is achieved when x=10x = 10 in the first query, that is, $\mathrm{popcount}(11)\times 3+\mathrm{popcount}(14)\times 2+\mathrm{popcount}(15)=3\times 3+2\times 3+4=19$.

It is easy to verify that choosing other values of xx within the range cannot make the answer larger.

Constraints

This problem uses bundled subtasks.

Let VV be the maximum value among the array elements and the query endpoints.

::cute-table | Subtask\text{Subtask} | nn\le | qq\le | VV\le |Score\text{Score} | | :-----------: | :-----------: | :-----------: | :---------: | :----------: | |11 | 1010| 1010 | 1010 | 55 | 22 |22 | 10510^5| 5×1055\times 10^5 | 10310^3 | 55 | 22 |33 | ^| 10510^5 | 10510^5 | 1515 | 22 |44 | 10410^4| 10410^4 | 10910^9 | 1010 | 22 |55 | 10510^5| 11 | ^ | 1515 | 22 |66 | ^| 5×1055\times 10^5 | ^ | 2020 | 55 | 77 | 5×1055\times 10^5 | 10510^5 | ^ | 2020 | 55 | 88 | ^ | 5×1055\times 10^5 | ^ | 1010 | 22 | | 99 | ^ | ^ | 101110^{11} | 00 |

For all testdata, it is guaranteed that 1n,q5×1051\le n, q\le 5\times 10^5, 0LR10110\le L\le R\le 10^{11}, and 0ai10110\le a_i\le 10^{11}.

The time limit for subtasks 6,7,96, 7, 9 is 55 seconds, and for the other subtasks it is 33 seconds.

Translated by ChatGPT 5