QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 125 MB 満点: 100

#7491. Even if the sun is setting

統計

Chtholly wants you to maintain a sequence of $n$ positive integers $a_1, a_2, \ldots, a_n$ and supports modifying the value at a specific position in the sequence.

After each modification, determine how many operations are required to make the entire sequence all $0$s by repeatedly performing the following operation (the sequence remains unchanged after the query and does not actually become all $0$s):

Select the position of the maximum value in the sequence. If there are multiple maximum values, choose the one with the smallest index. Let this position be $x$. Then, decrease the values of $a_{x-1}, a_x, a_{x+1}$ by $1$. If any value in the sequence becomes less than $0$, set it to $0$.

Input

The first line contains an integer $n$.

The next $n$ lines each contain an integer $a_i$.

The next line contains an integer $q$.

The next $q$ lines each contain two space-separated integers $x_i$ and $y_i$, representing that $a_{x_i}$ is modified to $y_i$.

Output

Output $q$ lines, each containing an integer representing the answer.

Examples

Input 1

4
3
6
6
4
3
4 4
3 5
1 8

Output 1

10
10
13

Note

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

$1\leq n,q\leq 10^5$, $1\leq x_i\leq n$, $1\leq a_i,y_i\leq 10^9$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.