#P11696. [JRKSJ ExR] 七影蝶
[JRKSJ ExR] 七影蝶
Background

Problem Description
Kyujima Kamome gives you a non-negative integer sequence of length .
Then there are queries. Each query gives non-negative integers . You need to compute
$$\max_{x=L}^R\left(\sum_{i=1}^n\mathrm{popcount}(a_i+x)\right)$$where denotes the number of bits in the binary representation of .
Input Format
The first line contains two integers .
The second line contains integers representing the sequence .
The following lines each contain two integers , representing one query.
Output Format
Output lines. The -th line contains one integer representing the answer to the -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 , the maximum is achieved when 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 within the range cannot make the answer larger.
Constraints
This problem uses bundled subtasks.
Let be the maximum value among the array elements and the query endpoints.
::cute-table | | | | | | | :-----------: | :-----------: | :-----------: | :---------: | :----------: | | | | | | | | | | | | | | | ^| | | | | | | | | | | | | | ^ | | | | ^| | ^ | | | | | | ^ | | | | ^ | | ^ | | | | | ^ | ^ | | |
For all testdata, it is guaranteed that , , and .
The time limit for subtasks is seconds, and for the other subtasks it is seconds.
Translated by ChatGPT 5