GSS3 - Can you answer these queries III

You are given a sequence A of N (N <= 50000) integers between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations:
modify the i-th element in the sequence or for given x y print max{Ai + Ai+1 + .. + Aj | x<=i<=j<=y }.

Input

The first line of input contains an integer N. The following line contains N integers, representing the sequence A1..AN.
The third line contains an integer M. The next M lines contain the operations in following form:
0 x y: modify Ax into y (|y|<=10000).
1 x y: print max{Ai + Ai+1 + .. + Aj | x<=i<=j<=y }.

Output

For each query, print an integer as the problem required.

Example

Input:
4
1 2 3 4
4
1 1 3
0 3 -3
1 2 4
1 3 3

Output:
6
4
-3

Added by:Bin Jin
Date:2007-08-03
Time limit:1s
Source limit:5000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: CPP
Resource:own problem

hide comments
2018-07-30 03:19:35
Key points:
1) Do GSS1 first
2)Implement update function
Thus concept building question.
2018-07-06 11:06:48
This is a very nice problem for someone who wants a good foundational problem in segment trees. Thanks!
2018-03-07 08:45:17
For java, use fast I/O. If the size of your file exceeds 5000 bytes, use java code minifier to remove spaces and newlines.

Check output for this case,

10
-200 -3 -4 -200 6 2 4 -200 5 6
1
1 5 10

Answer should be 12.

Last edit: 2018-03-07 08:45:30
2018-01-21 06:53:00
Did anyone ever solved this in JAVA???
2018-01-03 16:50:28
kgss + gss1 = gss3
solve gss1 before this
2017-12-14 10:36:35
can anybody explain the 3rd query why output is 4 please
2017-12-03 18:19:23
Easy after doing gss1 first.
2017-11-25 07:11:08
GSS! + point update=AC!
2017-10-10 13:33:06
finally did it......:)
2017-10-04 17:01:06
How come my same java code gives TLE to gss1 ,but pass gss3 ;)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.