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 static Assistant.Input;
using System.Linq;
using Assistant;
using System.Text;

namespace Temp20200521
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = ReadInt;
            int q = ReadInt;

            BIT bit = new BIT(n);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < q; i++)
            {
                if (ReadInt == 0)
                {
                    int k = ReadInt;
                    bit.Add(k, k, ReadInt);
                }
                else
                {
                    sb.AppendLine(bit.Sum(ReadInt, ReadInt).ToString());
                }
            }

            Console.Write(sb);
        }


    }

    class BIT
    {
        long[] bit0, bit1;  //1-indexed
        int n;
        public BIT(int n)
        {
            bit0 = new long[n + 1];
            bit1 = new long[n + 1];
            this.n = n;
        }

        public long Sum(int l, int r)
        {
            long ret = 0;
            ret += Sum(bit0, r) + Sum(bit1, r) * r;
            ret -= Sum(bit0, l - 1) + Sum(bit1, l - 1) * (l - 1);
            return ret;
        }

        long Sum(long[] bit, int i)
        {
            long s = 0;
            while (i > 0)
            {
                s += bit[i];
                i -= i & -i;
            }
            return s;
        }

        public void Add(int l, int r, int a)
        {
            Add(bit0, l, -a * (l - 1));
            Add(bit1, l, a);
            Add(bit0, r + 1, a * r);
            Add(bit1, r + 1, -a);
        }

        void Add(long[] bit, int i, int a)
        {
            while (i <= n)
            {
                bit[i] += a;
                i += i & -i;
            }
        }
    }

}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
}