PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000006. Cộng đoạn và truy vấn phần tử (Range Update Queries)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

3 lộ trình

Cộng đoạn và truy vấn phần tử (Range Update Queries)

Range Update Queries

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Start with an array of nn integers and process qq operations in their given order. Type 1 a b u adds uu to every array entry in the inclusive interval [a,b][a,b]. Type 2 k asks for the current value at position kk. All additions accumulate, including overlapping updates.

Input

The first line contains n,qn,q and the second line the initial array. Each of the following qq lines is 1 a b u (add uu on an inclusive range) or 2 k (query the current value at index kk).

Output

For each query requesting a result, output one integer on its own line in input order. Update operations produce no output.

Subtasks

  • Subtask 1 (15 points): 1≤n≤401\le n\le 40; 1≤q≤501\le q\le 50; 1≤a≤b≤n1\le a\le b\le n, 1≤k≤n1\le k\le n, and 1≤xi,u≤1091\le x_i,u\le 10^9 for all relevant input values.
  • Subtask 2 (20 points): 1≤n≤20001\le n\le 2000; 1≤q≤20001\le q\le 2000; 1≤a≤b≤n1\le a\le b\le n, 1≤k≤n1\le k\le n, and 1≤xi,u≤1091\le x_i,u\le 10^9 for all relevant input values.
  • Subtask 3 (25 points): 1≤n≤200001\le n\le 20000; 1≤q≤200001\le q\le 20000; 1≤a≤b≤n1\le a\le b\le n, 1≤k≤n1\le k\le n, and 1≤xi,u≤1091\le x_i,u\le 10^9 for all relevant input values.
  • Subtask 4 (40 points): 1≤n≤2000001\le n\le 200000; 1≤q≤2000001\le q\le 200000; 1≤a≤b≤n1\le a\le b\le n, 1≤k≤n1\le k\le n, and 1≤xi,u≤1091\le x_i,u\le 10^9 for all relevant input values.

Examples

Input

8 3
3 2 4 5 1 1 5 3
2 4
1 2 5 1
2 4

Output

5
6

Explanation

Initially x4=5x_4=5. Adding 11 at every position from 22 through 55 changes x4x_4 to 66. Thus the two outputs are 55 and 66.