LearnPy Hub
← Arena
AdvancedRating 1700

Update and Sum

Process q commands on the list: 'U i x' sets position i to x; 'S l r' prints the sum of positions l … r. Use a Fenwick (binary indexed) tree.

Input

n and q; n integers; q commands.

Output

One line per S.

Sample 1

Input
5 4
1 2 3 4 5
S 1 5
U 3 10
S 2 4
S 3 3
Output
15
16
10

Sample 2

Input
2 38
-31 -28
U 1 15
U 1 -49
U 2 20
S 1 2
U 2 -28
U 2 -21
S 1 2
S 1 2
U 2 11
S 2 2
U 2 -15
S 1 2
S 1 2
U 2 4
U 2 -44
U 1 33
U 2 38
U 1 6
U 2 22
S 1 2
U 1 36
U 2 -44
U 1 46
S 1 1
S 2 2
U 1 2
U 2 -17
U 2 -28
S 1 1
S 2 2
U 1 -17
S 1 2
S 2 2
S 1 2
S 2 2
U 1 -41
U 2 -41
S 1 2
Output
-29
-70
-70
11
-64
-64
28
46
-44
2
-28
-45
-28
-45
-28
-82
solution.py
Output appears here
Update and Sum · Python Arena problem · LearnPy Hub