#P15762. [JAG 2025 Summer Camp #1] Inside Yamanote

[JAG 2025 Summer Camp #1] Inside Yamanote

题目描述

There are NN cities numbered from 00 to N1N - 1. A railway goes around all NN cities, and city ii and city (i+1)modN(i + 1) \bmod N can be traveled between in LiL_i time units.

You will implement the following policy:

  • You may construct any number of railways that allow travel between any two cities in any non-negative time.
  • You then select one city among the NN cities to be the capital. The minimum travel time from the capital to city ii using the railways is defined as that city's undevelopment index did_i.

The reputation of this policy will be determined by word of mouth from the MM residents who will move this year. Resident jj will move from city XjX_j to city YjY_j after the policy is implemented. The reputation will be the sum of dXjdYjd_{X_j} - d_{Y_j}.

Your goal is to maximize the reputation of the policy. However, renovation work on the existing railway is also in progress, and you must revise the policy accordingly.

The travel times of existing railways will change QQ times. At the kk-th change, the travel time between city TkT_k and city (Tk+1)modN(T_k + 1) \bmod N changes to ZkZ_k. These changes are persistent. After each change, output the maximum possible reputation of the policy under the new conditions.

输入格式

The input is given in the following format:

$$\begin{aligned} & N \ M \ Q \\ & L_0 \ L_1 \ \ldots \ L_{N-1} \\ & X_1 \ Y_1 \\ & X_2 \ Y_2 \\ & \vdots \\ & X_M \ Y_M \\ & T_1 \ Z_1 \\ & T_2 \ Z_2 \\ & \vdots \\ & T_Q \ Z_Q \end{aligned}$$
  • 3N200 0003 \leq N \leq 200\ 000
  • 1M200 0001 \leq M \leq 200\ 000
  • 1Q200 0001 \leq Q \leq 200\ 000
  • 0Li1060 \leq L_i \leq 10^6 (1iN1 \leq i \leq N)
  • 0Xj,YjN10 \leq X_j, Y_j \leq N - 1 (1jM1 \leq j \leq M)
  • XjYjX_j \neq Y_j (1jM1 \leq j \leq M)
  • 0TkN10 \leq T_k \leq N - 1 (1kQ1 \leq k \leq Q)
  • 0Zk1060 \leq Z_k \leq 10^6 (1kQ1 \leq k \leq Q)
  • All input values are integers.

输出格式

Output QQ lines. On the kk-th line (1kQ1 \leq k \leq Q), output the answer for the query kk. It can be proven that the answer is an integer.

5 3 4
1 5 2 1 3
0 2
1 3
4 2
4 0
1 3
4 2
3 9
8
7
8
15