Problem:
Range Sum Query

Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:

add(i, x): add x to ai.

getSum(s, t): print the sum of as, as+1,...,at.

Note that the initial values of ai (i = 1, 2, . . . , n) are 0.

Input

n q
com1 x1 y1
com2 x2 y2
...
comq xq yq

In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi).

Output

For each getSum operation, print the sum in a line.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 100000

If comi is 0, then 1 ≤ xi ≤ n, 0 ≤ yi ≤ 1000.

If comi is 1, then 1 ≤ xi ≤ n, 1 ≤ yi ≤ n.

Sample Input 1

3 5
0 1 1
0 2 2
0 3 3
1 1 2
1 2 2

Sample Output 1

3
2

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        SetOut(new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        var n = FastIO.Int();
        var q = FastIO.Int();
        var st = new SegmentTree<int>(n, (x, y) => x + y, 0);
        for (int i = 0; i < q; i++)
        {
            if (FastIO.Int() == 0)
            {
                var p = FastIO.Int() - 1;
                st[p] += FastIO.Int();
            }
            else
            {
                WriteLine(st.Query(FastIO.Int() - 1, FastIO.Int()));
            }
        }
        Out.Flush();
    }
}

struct L
{
    public long a;
    public long b;
}

public class SegmentTree<T>
{
    T[] buffer;
    Func<T, T, T> F;
    T TI;
    int N;
    public int Length => N;

    public SegmentTree(int length, Func<T, T, T> f, T ti)
    {
        N = length;
        buffer = new T[N * 2];
        for (int i = 0; i < buffer.Length; i++) buffer[i] = ti; //Array.Fill
        F = f;
        TI = ti;
    }

    public SegmentTree(T[] init, Func<T, T, T> f, T ti)
    {
        N = init.Length;
        buffer = new T[N * 2];
        Array.Copy(init, 0, buffer, N, init.Length);
        for (int i = N - 1; i > 0; i--)
        {
            buffer[i] = f(buffer[i * 2 + 0], buffer[i * 2 + 1]);
        }
        F = f;
        TI = ti;
    }

    public void Update(int i, T v)
    {
        i += N;
        buffer[i] = v;
        while ((i >>= 1) != 0)
        {
            buffer[i] = F(buffer[i * 2 + 0], buffer[i * 2 + 1]);
        }
    }

    public T Query(int l, int r)
    {
        var lv = TI;
        var rv = TI;
        for (l += N, r += N; l < r; l >>= 1, r >>= 1)
        {
            if ((l & 1) == 1) lv = F(lv, buffer[l++]);
            if ((r & 1) == 1) rv = F(buffer[--r], rv);
        }
        return F(lv, rv);
    }

    public T this[int i]
    {
        set { Update(i, value); }
        get { return buffer[i + N]; }
    }
}

public static class FastIO
{
    static System.IO.Stream str = System.Console.OpenStandardInput();
    const int size = 1024;
    static byte[] buffer = new byte[size];
    static int ptr;
    static int len;

    static byte Read()
    {
        if (ptr == len)
        {
            len = str.Read(buffer, 0, size);
            if (len == 0) return 0;
            ptr = 0;
        }
        return buffer[ptr++];
    }

    public static int Int()
    {
        var c = Read();
        while (c < 0x21)
        {
            c = Read();
        }
        var n = false;
        if (c == '-')
        {
            n = true;
            c = Read();
        }
        var ret = 0;
        while (c > 0x20)
        {
            ret = ret * 10 + c - '0';
            c = Read();
        }
        return n ? -ret : ret;
    }

    public static long Long()
    {
        var c = Read();
        while (c < 0x21)
        {
            c = Read();
        }
        var n = false;
        if (c == '-')
        {
            n = true;
            c = Read();
        }
        var ret = 0L;
        while (c > 0x20)
        {
            ret = ret * 10 + c - '0';
            c = Read();
        }
        return n ? -ret : ret;
    }
}