#P5069. [Ynoi Easy Round 2015] 纵使日薄西山

[Ynoi Easy Round 2015] 纵使日薄西山

Description

Chtholly wants you to maintain a positive integer sequence of length nn, a1,a2,,ana_1,a_2,\ldots,a_n, supporting updates that modify the value at some position.

After each update, you are asked: if we repeatedly perform the following operation on the sequence, how many operations are needed to make the sequence become all 00 (after the query, the sequence is the same as before the query; it will not actually become all 00)?

Choose a position where the maximum value in the sequence occurs. If there are multiple maximum values, choose the one with the smallest index. Let the position be xx. Then decrease ax1,ax,ax+1a_{x-1},a_x,a_{x+1} by 11. If there exists a number less than 00 in the sequence, change that number to 00.

Input Format

The first line contains an integer nn.

The next nn lines each contain one integer aia_i.

The next line contains an integer qq.

The next qq lines each contain two integers xi,yix_i,y_i separated by a space, meaning to modify axia_{x_i} to yiy_i.

Output Format

Output qq lines, each containing one integer representing the answer.

4
3
6
6
4
3
4 4
3 5
1 8
10
10
13

Hint

Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078

Constraints: 1n,q1051\leq n,q\leq 10^5, 1xin1\leq x_i\leq n, 1ai,yi1091\leq a_i,y_i\leq 10^9.

Translated by ChatGPT 5