#P3374. 【模板】树状数组 1
【模板】树状数组 1
Description
As stated, given a sequence, you need to perform the following two operations:
- Add to a certain number.
- Find the sum of all numbers in a given interval.
Input Format
The first line contains two positive integers , representing the number of elements in the sequence and the total number of operations.
The second line contains space-separated integers, where the -th number is the initial value of the -th element of the sequence.
Each of the next lines contains integers describing an operation, as follows:
1 x kMeaning: add to the -th number.2 x yMeaning: output the sum of all numbers in the interval .
Output Format
Output several lines of integers, which are the results of all type 2 operations.
5 5
1 5 4 2 3
1 1 3
2 2 5
1 3 -1
1 4 2
2 1 4
14
16
Hint
Constraints
For of the testdata, , . For of the testdata, . For of the testdata, .
It is guaranteed that at any time, the sum of any subarray of (including subarrays of length and length ) lies in the range .
Sample explanation:

Therefore, the output is and .
Translated by ChatGPT 5
京公网安备 11011102002149号