Recently Segment Tree Test. After a long battle with his feelings, he realized he could no longer keep them bottled up.revisited his long lost love,
After many sleepless nights of browsing the internet, he finally came up with the problem. However, try as he might, the solution of the problem did not meet his standards, nor did they meet those of the other contestants.
Being extremely persistent,has decided to try once more in projecting his emotions onto his problems. Please free him from the burden of his emotions by answering the following queries:
U pos val- Change the value from position
G x- Revert to revision
P x y- Output the maximum prefix sum on the interval from
S x y- Output the maximum suffix sum on the interval from
At this point in time,
U). The initial structure has the revision index .
On the first line of input you will find the integer , representing the size of the array.
On the second line of input you will find space-separated integers, representing the initial array. It is guaranteed that the total sum of the given numbers does not exceed .
On the third line of input, you will find the integer , representing the number of queries.
On the next lines of input, you will find queries formatted as specified above.
For each of the
S queries, output its result on a single line by itself in order according to the input.
5 -1 -2 -3 -2 9 5 P 2 3 U 1 8 S 1 5 G 0 S 1 5
-2 10 9