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
2020-04-14 17:29:29
Ac in one go :p
GSS1 with addition of update function.
2020-04-08 23:04:58
"Wrong Answer #0" How?
After AC:
I used LONG_MIN as default min value.

Last edit: 2020-04-08 23:16:16
2020-03-23 19:52:33
bài hay
2019-11-28 05:45:59
A nice problem to solve...
2019-11-16 17:20:53
AC in 5 go, kept getting Wrong answer #0 , because MIN_VAL i stored in array was too large
2019-08-13 00:00:00
solve GSS1 before this
2019-07-04 10:55:40
Very nice test cases , O(nm) brute force passes in 0.31s....

Except for that very nice question on range queries - AC in one go with segment tree
2019-06-25 12:59:22
you can solve this with sqrt decomposition too.
2019-06-20 18:05:45
GSS1 + Point update
2019-05-17 17:44:58
Works for Java.
Use fast IO. Remove all spaces from the code.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.