#P3374. 【模板】树状数组 1

【模板】树状数组 1

Description

As stated, given a sequence, you need to perform the following two operations:

  • Add xx to a certain number.
  • Find the sum of all numbers in a given interval.

Input Format

The first line contains two positive integers n,mn, m, representing the number of elements in the sequence and the total number of operations.

The second line contains nn space-separated integers, where the ii-th number is the initial value of the ii-th element of the sequence.

Each of the next mm lines contains 33 integers describing an operation, as follows:

  • 1 x k Meaning: add kk to the xx-th number.
  • 2 x y Meaning: output the sum of all numbers in the interval [x,y][x, y].

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 30%30\% of the testdata, 1n81 \le n \le 8, 1m101 \le m \le 10. For 70%70\% of the testdata, 1n,m1041 \le n, m \le 10^4. For 100%100\% of the testdata, 1n,m5×1051 \le n, m \le 5 \times 10^5.

It is guaranteed that at any time, the sum of any subarray of aa (including subarrays of length 11 and length nn) lies in the range [231,231)[-2^{31}, 2^{31}).

Sample explanation:

Therefore, the output is 1414 and 1616.

Translated by ChatGPT 5