KGSS - Maximum Sum

You are given a sequence A[1], A[2], ..., A[N] ( 0 ≤ A[i] ≤ 10^8 , 2 ≤ N ≤ 10^5 ). There are two types of operations and they are defined as follows:

Update:

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

Warning: large Input/Output data, be careful with certain languages

Được gửi lên bởi:Swarnaprakash
Ngày:2009-01-10
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:Kurukshetra 09 OPC

hide comments
2021-05-27 18:01:09
Tham khảo: https://vnspoj.github.io/problems/KGSS
2019-12-22 02:36:29
Segment tree
CLQD K12
2019-12-06 10:25:47
heap cũng AC =)))
2019-11-01 12:58:04
:)) bài này n<=10^5 nhé, do các bạn ko đặt đúng giới hạn 4*n của cây IT nên mới bị Runtime nhé :))
2019-10-19 10:41:59
Bài này dễ vlon 1 đấm AC.
IKurumiI
2019-10-12 17:06:10
Ai cho e hỏi là vì rg để n<=10^6 mà nó cứ bị RUNTIME khi build nhỉ??, phần get đúng nhưng build vs update sai mặc dù e chạy vx tốt
2019-07-09 19:17:06
Giới hạn n<=10^6 chứ không phải 10^5 nha
2018-10-26 17:12:37
min max quá ảo :D
2018-10-18 05:11:07
Để maxx = -1 mất toi mấy đấm =))))).
CYB =))))))))))
2018-08-08 16:16:59
how to kruscal vậy bn bên dưới?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.