#P8539. 「Wdoi-2」来自地上的支援
「Wdoi-2」来自地上的支援
Description
Brief Statement
You are given positive integers , , and an array of length .
There is an array of length , initially equal to .
Perform operations. In the -th operation, choose a positive integer in by the following rules, then change to :
- Choose the with the maximum .
- If ties, choose the with the maximum .
- If both and tie, choose the smaller .
We say that is selected once.
There are queries. Each query gives . You need to find the minimum such that, if the initial value of is changed to (note that the initial value of will also change accordingly), then is selected at least times, or report that it does not exist (the result is ). Note that if has no minimum, you should also report that it does not exist (the result is ).
Queries are independent. That is, each query does not make any actual change to or .
Original Statement
After arriving at the control center, the protagonists and Utsuho Reiuji engaged in a fierce dogfight contest. The kappa in charge of technical maintenance must receive instructions from Nitori, coming from the surface command, to ensure production safety.
Specifically, there are nuclear reactor units lined up in order. The activity intensity of the -th unit is . To maintain balance, the control system performs operations in order. In the -th operation, it finds among the first units the unit with the currently highest activity, performs one balancing adjustment on it, and increases its activity by . If multiple units have the highest activity, choose the one with the largest initial activity; if still indistinguishable, choose the one with the smallest index.
To adjust balance on top of the automatic control system, Nitori will issue commands. Each time she gives two integers , meaning she will modify the initial activity of the -th unit. She hopes that after the modification (it must be changed to a non-negative integer ), unit will be balanced at least times. If it is impossible no matter what, the result is ; otherwise, output the minimum that satisfies the condition.
Input Format
- The first line contains three integers .
- The next line contains integers describing .
- The next lines each contain two integers , describing a query.
Output Format
- Output one line with two integers, representing the xor sum and the sum of all results.
7 2 3
1 4 1 5 4 1 1
3 3
6 4
7 7
10 10 9
14 91 84 13 97 92 23 64 31 10
5 2
5 5
9 1
2 6
9 1
5 4
3 5
2 8
8 2
5 4
245 1177
Hint
Explanation for Sample 1
For the first query, we modify to .
- The first operation chooses position , so becomes .
- The second operation chooses position , so becomes . Although before the operation , we have , so position is chosen.
- The third operation chooses position , so becomes .
- The fourth operation chooses position , so becomes .
- The fifth operation chooses position , so becomes .
- The sixth operation chooses position , so becomes .
- The seventh operation chooses position , so becomes .
Thus position is selected times in total, satisfying the requirement. It can be proven that if the initial value of is set to , the requirement cannot be met. Therefore the answer to this query is .
For the second query, it is easy to see that it is impossible to have or more operations selecting position . Therefore the answer to this query is .
, , so the output is .
Constraints
$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|}\hline \textbf{Subtask} & \bm{n,m\le} & \bm {a_i\le } & \bm{v\le} & \textbf{分值} \cr\hline 1 & 10 & 100 & 10 & 10 \cr\hline 2 & 100 & 5\times 10^3 & 50 & 20 \cr\hline 3 & 10^3 & 10^9 & 100 & 10 \cr\hline 4 & 10^5 & 10^9 & 100 & 25 \cr\hline 5 & 2\times 10^6 & 10^9 & 100 & 35 \cr\hline \end{array}$$For all testdata, , , , .
The I/O volume of this problem is large. Please choose an appropriate input method.
Translated by ChatGPT 5
京公网安备 11011102002149号