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
amank12345:
2022-06-13 23:04:13
Java Users, Please take a note!!!!
|
|
zayady:
2021-11-09 23:12:52
i solve it usint sqrt decom , and i got AC , but this test case breaked my solution ( corner case when the size of block is equal 1 )
|
|
fuadul_hasan:
2021-09-28 10:43:38
simple problem... best one for start learning segtree |
|
mortal_beast:
2021-06-06 15:17:15
Good for begineers |
|
rimuru_404:
2021-06-05 05:38:54
After some silly mistakes AC. Nice problem for segment tree beginners |
|
mukund007:
2021-05-30 08:43:03
Fenwick Tree go go |
|
saurabh_kl:
2021-02-11 21:05:39
Accepting Java solution, I don't know it gives TLE with Scanner or not but FastReader is okay Last edit: 2021-02-11 21:06:32 |
|
kanisht09:
2021-01-22 21:47:48
Solved it using segment trees 2 different ways |
|
saurav7192:
2020-08-06 10:56:08
Aced finally.............................. Last edit: 2020-08-06 12:30:50 |
|
skj_helloworld:
2020-08-04 12:34:34
accepted in one go |
Added by: | Swarnaprakash |
Date: | 2009-01-10 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | Kurukshetra 09 OPC |