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
beowulf_rohan: 2020-09-29 23:22:04

Can someone explain "Wrong Answer #0"...?

harry_shit: 2020-09-17 05:43:03

use long long int instead of int for ac

sabal_nrl322: 2020-09-07 16:16:58

If your code is giving the correct ans in your IDE but while submitting wrong ans on 8/9 Test Case
Keep the the of the TREE 3 or 4 times the size of Array

Last edit: 2020-09-07 16:57:12
kushal_0189: 2020-09-02 16:23:44

Use concept of Prefix and Suffix array sum

ankhang277: 2020-08-27 13:11:59

Test for some one stuck
5
20 -20 20 1 2
1
1 2 3

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

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