Captain Huang's secret background

Time Limit
2s
Memory Limit
32768KB
Judge Program
Standard
Ratio(Solve/Submit)
7.69%(1/13)
Description:

Captain Huang is an active thinker and good at geometry, math.But the most amazing characteristic of Captain Huang is her secret background .Due to the seriousness and secrecy of her background,we have to define a query to explain it.


Given integer sequence a1,a2,...,an, you can choose a pair of integers (x,y) (1<=x<=y<=n),such that the sum of ax+ax+1+..+ay is positive and as large as possible.The subsegment ax, ax+1, .., ay is called positive maximum subsegment(PMS) of sequence a1,a2,...,an.


Now,we define a CRH query. In reply to it you should reverse  a PMS (x,y) of sequence a1,a2,...,an (i.e. a[i]=-a[i],(x<=i<=y)) and print the sum of PMS of the modified sequence a1,a2,...,an which is called CRH and should be as large as possible.


You should run instructions of three types:
"0 i val" means performing ai=val
"1 l r" means performing ai=-ai for all ai such that l<=i<=b

"2 l r" means querying CRH of al,al+1,..,ar. If you can not find PMS or CRH ,just print "0". Note that the reversing operation in querying CRH will not affect the original sequence.


Hint(you can read it after solving the problem because it is irrelevant to the problem):

If you succeed in solving the problem ,Congratulations! I suggested that you can have a try on the following problem after the contest. Because the similarity of solution code of the two problem are up to 99%.
The query of the challenging problem is that you should choose at most k pairs of integers (x1,y1),(x2,y2),...,(xt,yt) (l≤x1≤y1< x2 ≤ y2 < ... < xt ≤ yt ≤ r; t ≤ k)such that ax1+ax1+1+...+ay1+ax2+ax2+1+...+ay2.+...+axt+axt+1+...+ayt is as large as possible.Note you can choose 0 subsegments whose sum is 0.
There is a interesting proof of the problem based on flow!


Input:

The first line contains integer n (1≤n≤1e5), showing how many numbers the sequence has. The next line contains n integers a1,a2,...,an (|ai|≤500).

The third line contains integer m (1≤m≤1e5) — the number of instructions. The next m lines contain the instructions in the format, given in the statement.

All changing queries fit into limits: 1≤i≤n, |val|≤500.

Output:

For each query to count CRH print the reply . Print the answers to the queries in the order, in which the queries follow the input.

Sample Input:
15
-4 8 -3 -10 10 4 -7 -7 0 -6 3 8 -10 7 2
8
2 6 12
0 6 5
0 10 -7
1 4 9
1 7 9
0 10 -3
2 4 10
2 1 15
Sample Output:
4
0
11
Hint:

In the first query of the first example the first PMS pair is(11,12) and after reversing the second PMS pair is (6,6). So the CRH will be 4. In the second query of the first example the first PMS pair is(4,4) and after reversing the second PMS pair is none. So the CRH will be 0. In the third query of the first example the first PMS pair is(2,4) and after reversing the second PMS pair is (11,12). So the CRH will be 11.


Submit