is doing a contest. He comes across the following problem:
You have an array of
elements, indexed from
to
. There are
operations you need to perform on it.
Each operation is one of the following:
C x v
Change the-th of the array to
.
S l r
Output the sum of all the elements from the-th to the
-th index, inclusive.
Q v
Output how many elements are less than or equal toin the array.
At any time, every element in the array is between and
(inclusive).
knows that one fast solution uses a Binary Indexed Tree. He practices that data structure every day, but still somehow manages to get it wrong. Will you show him a working example?
Input Specification
The first line has and
.
The second line has integers, the original array.
The next lines each contain an operation in the format described above.
Output Specification
For each S
or Q
operation, output the answer on its own line. Note that you may need to use 64-bit integers to store the answer.
Sample Input
10 10
4 8 4 5 6 3 2 2 8 1
C 7 6
Q 7
S 2 3
S 1 4
C 4 9
S 2 3
Q 6
C 3 9
S 6 7
Q 6
Sample Output
8
12
21
12
7
9
6
Comments