This page is still under construction.

Parts of this page are still being built. What you see may change.

Household Ledger

Interview

Time limit1sMemory limit512 MB

Summary
Process point additions and range-sum queries on a ledger of N days.
Level

Medium4 of 10

Topics
Prefix sum
Solved
No attempts yet

Problem

Wolgok keeps a ledger of income and spending by day, and wants to check how much the balance moved over a chosen period of days. The ledger application on the phone recomputed everything from scratch on every new entry, so it was too slow, and filling in an entry that had been missed earlier was just as slow. Write a program that handles the two operations below quickly.

The first operation adds an amount xx to the entry for day pp of Wolgok's life. Income is given as a positive number and spending as a negative number. The same day can be added to more than once, and the amounts accumulate.

The second operation reports the sum of the amounts recorded from day pp through day qq, which is the net change of the balance over that period. Wolgok can be in debt, so this value can be negative.

At the start no day has any record, so the amount on every day is 00.

Input

The first line contains the number of days NN that Wolgok has lived and the number of queries QQ. (1≤N≤1061 \le N \le 10^6, 1≤Q≤1051 \le Q \le 10^5)

Each of the next QQ lines contains a query in one of the two forms below.

  • 1 p x : add xx to the entry for day pp. (1≤p≤N1 \le p \le N, −2×109≤x≤2×109-2 \times 10^9 \le x \le 2 \times 10^9)
  • 2 p q : print the net change from day pp through day qq. (1≤p≤q≤N1 \le p \le q \le N)

Output

For each 2 query, print the computed value on its own line, in the order the queries are given.

Examples1

  1. Example 1

    Input
    10 6
    1 3 10000
    1 4 -5000
    1 7 -3000
    2 1 10
    1 6 35000
    2 4 10
    
    Expected output
    2000
    27000