KGSS  Maximum Sum
This will be indicated in the input by a 'U' followed by space and then two integers i and x.
U i x, 1 ≤ i ≤ N, and x, 0 ≤ x ≤ 10^8.
This operation sets the value of A[i] to x.
Query:This will be indicated in the input by a 'Q' followed by a single space and then two integers i and j.
Q x y, 1 ≤ x < y ≤ N.
You must find i and j such that x ≤ i, j ≤ y and i != j, such that the sum A[i]+A[j] is maximized. Print the sum A[i]+A[j].
Input
The first line of input consists of an integer N representing the length of the sequence. Next line consists of N space separated integers A[i]. Next line contains an integer Q, Q ≤ 10^5, representing the number of operations. Next Q lines contain the operations.
Output
Output the maximum sum mentioned above, in a separate line, for each Query.
Example
Input: 5 1 2 3 4 5 6 Q 2 4 Q 2 5 U 1 6 Q 1 5 U 1 7 Q 1 5 Output: 7 9 11 12
hide comments
ajeyo:
20170527 18:18:22
AC in one GO! :D Probably the very first time :P


lord_poseidon:
20170527 10:31:39
why not working if the size of tree set to be 2 * n + 10(as minimum no of elements needed are 2 * n  1 for the tree) 

epsilonalpha:
20170411 01:03:04
AC in one go. Recommended! 

alaa seb:
20170324 23:46:21
my first segment tree .. AC in one go :)


shahzada:
20170314 13:56:05
RE(SIGSEGV)  Scanf


nilabja16180:
20170309 11:29:26
AC in ONE GO! 

gauravgb21:
20170228 21:28:02
AC in one go!!! 

akshay31057:
20170114 21:12:57
Excellent problem!!!!!go for structure array...


souvik23:
20170103 06:11:25
@gustavoaca1997 : The max size is 10^5 which is not a power of 2 ...... You have to take the nearest power of 2 greater than 10^5 i.e. 131072 and so your tree size must be 2*131072 which is > 2*10^5.That's why it didn't work:) 

lincolnbf:
20161007 01:51:21
gustavoaca the size of seg tree can go upto 4N for an array of size N. 
Added by:  Swarnaprakash 
Date:  20090110 
Time limit:  0.357s0.857s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL JSRHINO NODEJS PERL6 VB.NET 
Resource:  Kurukshetra 09 OPC 