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

#FT0000003. Cộng một phần tử, tính tổng đoạn (Point Add Range Sum)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

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 aa of nn nonnegative integers indexed 0,1,…,n−10,1,\ldots,n-1. Process qq operations that may repeatedly add to an individual element or request a range sum.

There are two forms of operations: 0 p x increases apa_p by xx; 1 l r returns ∑i=lr−1ai\sum_{i=l}^{r-1}a_i. The query interval [l,r)[l,r) is half-open and therefore contains exactly r−lr-l elements. When r=nr=n, the last element an−1a_{n-1} 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 q gives array length and operation count.
  • Line 2: a_0 a_1 ... a_(n-1) gives the initial values in index order.
  • Next qq lines: each line contains one of the following commands, in execution order:
    • 0 p x: add xx at index pp.
    • 1 l r: query the half-open range sum [l,r)[l,r).

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):

  • 1≤n≤241\le n\le 24.
  • 1≤q≤301\le q\le 30.
  • 0≤ai,x≤1090\le a_i,x\le 10^9.
  • 0≤p<n0\le p<n.
  • 0≤l<r≤n0\le l<r\le n.

Subtask 2 (30 points):

  • 1≤n≤12001\le n\le 1200.
  • 1≤q≤16001\le q\le 1600.
  • 0≤ai,x≤1090\le a_i,x\le 10^9.
  • 0≤p<n0\le p<n.
  • 0≤l<r≤n0\le l<r\le n.

Subtask 3 (50 points):

  • 1≤n≤5000001\le n\le 500000.
  • 1≤q≤5000001\le q\le 500000.
  • 0≤ai,x≤1090\le a_i,x\le 10^9.
  • 0≤p<n0\le p<n.
  • 0≤l<r≤n0\le l<r\le n.

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 n=4n=4 elements. The initial values are [1, 2, 3, 4].

  1. Command 1 — 1 0 4: Half-open [0,4)[0,4) includes indices 00 through 33, namely [1, 2, 3, 4]; the sum is 1+2+3+4=101 + 2 + 3 + 4=10. Index 44 is excluded.

  2. Command 2 — 0 2 5: Add 55 to a2a_2 (previously 33), obtaining 88. Current array: [1, 2, 8, 4].

  3. Command 3 — 1 1 3: Half-open [1,3)[1,3) includes indices 11 through 22, namely [2, 8]; the sum is 2+8=102 + 8=10. Index 33 is excluded.

  4. Command 4 — 0 0 7: Add 77 to a0a_0 (previously 11), obtaining 88. Current array: [8, 2, 8, 4].

  5. Command 5 — 1 0 2: Half-open [0,2)[0,2) includes indices 00 through 11, namely [8, 2]; the sum is 8+2=108 + 2=10. Index 22 is excluded.

Collect the answers to output-producing commands in their input order, printing one answer per line.