#FT0000003. Cộng một phần tử, tính tổng đoạn (Point Add Range Sum)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cộng một phần tử, tính tổng đoạn (Point Add Range Sum)
Point Add Range Sum
Source: Library Checker
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of nonnegative integers indexed . Process operations that may repeatedly add to an individual element or request a range sum.
There are two forms of operations: 0 p x increases by ; 1 l r returns . The query interval is half-open and therefore contains exactly elements. When , the last element is included.
Multiple updates may affect the same index, and range sums may exceed the signed 32-bit integer range. An addition must not be confused with replacing the current value.
Input
- Line 1:
n qgives array length and operation count. - Line 2:
a_0 a_1 ... a_(n-1)gives the initial values in index order. - Next lines: each line contains one of the following commands, in execution order:
0 p x: add at index .1 l r: query the half-open range sum .
Output
For each 1 l r command, print the requested integer computed from the current state on its own line, in query order. Update commands produce no output.
Subtasks
Subtask 1 (20 points):
- .
- .
- .
- .
- .
Subtask 2 (30 points):
- .
- .
- .
- .
- .
Subtask 3 (50 points):
- .
- .
- .
- .
- .
Examples
Input
4 5
1 2 3 4
1 0 4
0 2 5
1 1 3
0 0 7
1 0 2
Output
10
10
10
Explanation
There are elements. The initial values are [1, 2, 3, 4].
-
Command 1 —
1 0 4: Half-open includes indices through , namely[1, 2, 3, 4]; the sum is . Index is excluded. -
Command 2 —
0 2 5: Add to (previously ), obtaining . Current array:[1, 2, 8, 4]. -
Command 3 —
1 1 3: Half-open includes indices through , namely[2, 8]; the sum is . Index is excluded. -
Command 4 —
0 0 7: Add to (previously ), obtaining . Current array:[8, 2, 8, 4]. -
Command 5 —
1 0 2: Half-open includes indices through , namely[8, 2]; the sum is . Index is excluded.
Collect the answers to output-producing commands in their input order, printing one answer per line.