#P3368. 【模板】树状数组 2

【模板】树状数组 2

Description

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

  1. Add xx to every number in a given interval.
  2. Query the value of a specific element.

Input Format

The first line contains two integers NN and MM, 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 22 or 44 integers describing an operation, as follows:

Operation 1: Format: 1 x y k Meaning: add kk to every number in the interval [x,y][x,y].

Operation 2: Format: 2 x Meaning: output the value of the xx-th number.

Output Format

Output several lines of integers, which are the results of all type 2 operations.

5 5
1 5 4 2 3
1 2 4 2
2 3
1 1 5 -1
1 3 5 7
2 4
6
10

Hint

Explanation for Sample 1:

Therefore, the outputs are 66 and 1010.


Constraints

For 30%30\% of the testdata: N8N\le8, M10M\le10.

For 70%70\% of the testdata: N104N\le 10^4, M104M\le10^4.

For 100%100\% of the testdata: 1N,M5×1051 \leq N, M\le 5\times10^5, 1x,yn1 \leq x, y \leq n. It is guaranteed that at any time, the absolute value of any element in the sequence does not exceed 2302^{30}.

Translated by ChatGPT 5