#P8539. 「Wdoi-2」来自地上的支援

    ID: 7584 远端评测题 2000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心线段树洛谷原创O2优化洛谷月赛

「Wdoi-2」来自地上的支援

Background

Beneath the shimmering summit lake and the solemn, sacred shrine lies a composite active volcano.
Going down along the Gensokyo Vent, you can reach the long-abandoned former site of Hell beneath the volcano.

In Old Hell, there is a large metropolis. It was where the oni who worked there lived when it was still called Hell or Old Hell, and only there the dead could not set foot. Later, after a reform of the Hell system, the organizations moved away from this place.
For this reason, this part of Hell became ruins, but some youkai took a liking to it and occupied it without permission, and thus it became today’s Old Hell.
There is even less order here than on the surface. Bandits and bullies, especially those disliked by humans, all like to move here and settle down.

The geysers erupting from Old Hell bring excellent hot springs to Youkai Mountain, and also spew out a large number of vengeful spirits.

To resolve this incident, the shrine maiden of Paradise and an ordinary magician travel together. With support from the surface, they charge straight into the underground from the Gensokyo Vent.

After meeting (and fighting) the bright web in the dark cave, the jealousy beneath the crust, and the strange gods and demons people talk about, the two arrive at the mansion in the center of the ruins, Chireiden.

Guided by the master of this place, they reach the underground center of the geyser deep within.

Problem Description

Brief Statement

You are given positive integers nn, vv, and an array {Ai}\{A_i\} of length nn.

There is an array BB of length nn, initially equal to AA.
Perform nn operations. In the ii-th operation, choose a positive integer jj in [1,i][1,i] by the following rules, then change BjB_j to Bj+vB_j+v:

  • Choose the jj with the maximum BjB_j.
  • If BjB_j ties, choose the jj with the maximum AjA_j.
  • If both AjA_j and BjB_j tie, choose the smaller jj.

We say that jj is selected once.

There are mm queries. Each query gives xi,kix_i, k_i. You need to find the minimum ss such that, if the initial value of AxiA_{x_i} is changed to ss (note that the initial value of BxiB_{x_i} will also change accordingly), then xix_i is selected at least kik_i times, or report that it does not exist (the result is 00). Note that if ss has no minimum, you should also report that it does not exist (the result is 00).

Queries are independent. That is, each query does not make any actual change to AxiA_{x_i} or BxiB_{x_i}.

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 nn nuclear reactor units lined up in order. The activity intensity of the ii-th unit is AiA_i. To maintain balance, the control system performs nn operations in order. In the ii-th operation, it finds among the first ii units the unit with the currently highest activity, performs one balancing adjustment on it, and increases its activity by vv. 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 mm commands. Each time she gives two integers xi,kix_i, k_i, meaning she will modify the initial activity of the xix_i-th unit. She hopes that after the modification (it must be changed to a non-negative integer ss), unit xix_i will be balanced at least kik_i times. If it is impossible no matter what, the result is 00; otherwise, output the minimum ss that satisfies the condition.

Input Format

  • The first line contains three integers n,m,vn, m, v.
  • The next line contains nn integers describing aia_i.
  • The next mm lines each contain two integers xi,kix_i, k_i, 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 A3A_3 to 77.

  • The first operation chooses position 11, so B1B_1 becomes 44.
  • The second operation chooses position 22, so B2B_2 becomes 77. Although before the operation B1=B2B_1=B_2, we have A2>A1A_2>A_1, so position 22 is chosen.
  • The third operation chooses position 33, so B3B_3 becomes 1010.
  • The fourth operation chooses position 33, so B3B_3 becomes 1313.
  • The fifth operation chooses position 33, so B3B_3 becomes 1616.
  • The sixth operation chooses position 33, so B3B_3 becomes 1919.
  • The seventh operation chooses position 33, so B3B_3 becomes 2222.

Thus position 33 is selected 55 times in total, satisfying the requirement. It can be proven that if the initial value of A3A_3 is set to 66, the requirement cannot be met. Therefore the answer to this query is 77.

For the second query, it is easy to see that it is impossible to have 44 or more operations selecting position 66. Therefore the answer to this query is 00.

70=77\oplus 0=7, 7+0=77+0=7, so the output is 7,77,7.

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, 1n,m2×1061 \le n,m \le 2\times 10^6, 1v1001 \le v \le 100, 1ai1091 \le a_i \le 10 ^ 9, 1x,kn1 \le x,k \le n.

The I/O volume of this problem is large. Please choose an appropriate input method.

Translated by ChatGPT 5