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

hide comments
codefucker1307: 2020-08-05 21:15:06

a lot of WA attempts at GSS1 helped me in doing it in ONE go.

anonymousamigo: 2020-08-03 06:52:25

help for those who got stuck
8
-1 -1 -1 20 20 -1 -1 -1
1
1 3 6

FYI: copied from past comment and it worked for me

vandan6500: 2020-07-13 09:19:39

GSS1 before this is a must

ronythakur: 2020-06-03 08:40:24

AC in a go, love solving segment trees problem

silent_1: 2020-05-30 16:28:29

@dhruv gheewala change min value with -1e10
update : i checked with -1e6 -> AC
i think some problem with your implementation.

Last edit: 2020-05-30 17:07:29
dhruvgheewala: 2020-05-25 21:37:37

"Wrong Answer #0", Anyone can tell me, why i am getting like this, while my code works perfect for GSS1(AC) and i have checked my point update previously(it is also correct).
and changed min value to -1000000.
But getting WA.

aman5898: 2020-04-14 17:29:29

Ac in one go :p
GSS1 with addition of update function.

abu_rifat: 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
huyquang2005: 2020-03-23 19:52:33

bài hay

fardin_abir: 2019-11-28 05:45:59

A nice problem to solve...


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