ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

[Online] ICPC Ural Regional Contest Qualifier 2026

About     Problems     Submit solution     Judge status     Standings
Contest is over

K. Progressiveness

Time limit: 2.0 second
Memory limit: 256 MB
In one game there are N levels, and for each of them one can earn any integer number of points, including zero and negative values. Vadim can complete the i-th level for ai points.
A progress is a consecutive sequence of levels such that the points strictly increase. For example, if the 2-nd level is completed for −4 points, the 3-rd — for 0 points, and the 4-th — for 3 points, then this sequence of levels and points is a progress.
The progressiveness of a level is the size of the largest progress, by number of levels, not by points, that contains this level. For example, if the levels are completed for [9, 4, 5, 6, 1] points, then the progressiveness of the 3-rd level is 3, since the progress [4, 5, 6] cannot be extended either to the left or to the right.
It is clear that all players are interested only in the total progressiveness of all levels. Vadim computed his own and was a little disappointed. He spent the next Q days changing his strategy. On each of these days, one of two things could happen:
  • Skill change. From level lj to level rj, Vadim gets vj more points. Note that the skill may either increase or decrease.
  • Constancy. Vadim trains constancy from level lj to level rj and now gets exactly vj points on all of them. Note that this value may also be zero or negative.
After each day, Vadim computed the new total progressiveness. In total, he obtained Q+1 records. Your task is to restore all of them from the described strategy changes.

Input

The first line contains an integer N — the number of levels in the game (2 ≤ N ≤ 105).
The second line contains N integers ai — the initial number of points Vadim gets for completing the i-th level (−109 ≤ ai ≤ 109).
The third line contains an integer Q — the number of days with changes (1 ≤ Q ≤ 105).
The following Q lines describe the changes in one of the following formats:
  • + lj rj vj — skill change (character code 43).
  • = lj rj vj — constancy training (character code 61).
For each day, the inequalities 1 ≤ lj ≤ rj ≤ N and −109 ≤ vj ≤ 109 hold.

Output

Print Q+1 integers — the total progressiveness before the changes and after each of them.

Sample

inputoutput
5
3 7 2 5 3
4
+ 2 3 6
= 4 5 10
+ 1 2 -8
= 5 5 21
9
7
9
17
25
Problem Author: Vadim Barinov
Problem Source: The 2026 ICPC Ural Qualification