#P9790. [ROIR 2020] 海报 (Day 2)
[ROIR 2020] 海报 (Day 2)
Problem Description
Translated from ROIR 2020 Day2 T4. Плакаты, translator: ksyx.
Your friends have prepared many nice posters to welcome the national team members returning from IOI, and now they only need to work out some details.
To welcome these contestants, your friends will stand in a circle holding posters. For convenience, they are numbered as friends . For , friend stands next to friend , and friend stands next to friend .
Each poster has a beauty value. The beauty value of the poster held by friend is . When the celebration starts, some friends will raise their posters. For appearance, there must not be or more consecutive friends raising their posters at the same time.
To make the celebration more interesting, your friends also plan to change posters times during the celebration. After each change, the beauty value of poster will become . Your friends want to know, after each change, the maximum possible sum of beauty values under the rule above.
Your task is: given the initial beauty values, output the maximum sum for the initial state and after each change.
Translator’s note: The statement omits some unnecessary details that are hard to understand.
Input Format
The first line contains an integer , the number of friends.
The next line contains integers , the initial beauty values.
The third line contains an integer , the number of poster changes.
The next lines each contain two integers , describing one change.
Output Format
Output lines, representing the maximum sum of beauty values for the initial state and after each change.
6
1 2 3 4 5 6
2
6 0
2 5
17
13
15
Hint
Sample 1 Explanation
In the initial state, the best plan is to let friends raise their posters, and the sum of beauty values is .
After the first change, the beauty value of friend ’s poster becomes . In this case, the best plan is to let friends raise their posters, and the sum is .
After the second change, the beauty value of friend ’s poster becomes . In this case, the best plan is to let friends raise their posters, and the sum is .
Constraints
For of the testdata, $4\le n\le 40000,~0\le a_i,~v_i\le 10^9,~1\le p_i\le n,~0\le q\le 40000$.
The subtasks are as follows:
| Subtask ID | Points | Limits |
|---|---|---|
Translated by ChatGPT 5