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)

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int a[100000];
int leaf_num = 1; // 一番下にある頂点の個数
int seg[400000];
 
int func(int x, int y) {
    return x + y;
}

int identity_element() {
    return 0;
}

void init(int n) {
    while(leaf_num < n) {
        leaf_num *= 2;
    }
    for(int i = 0 ; i < n; i++) {
        seg[i + leaf_num - 1] = a[i];
    }
    for(int i = leaf_num - 2; i >= 0; i--) {
        seg[i] = func(seg[i * 2 + 1], seg[i * 2 + 2]);
    }
}
 
void update(int k, int x) {
    k--;
    k += leaf_num - 1;
    seg[k] += x;
    while(k != 0) { //  親に到達するまで
        k = (k - 1) / 2; // 頂点をひとつ上に移動
        seg[k] = func(seg[k * 2 + 1], seg[k * 2 + 2]);
    }
}
 
int _get_interval(int a, int b, int k, int l, int r) {
    if(b <= l || r <= a) return identity_element();
    if(a <= l && r <= b) {
        return seg[k];
    }
    int lch = _get_interval(a, b, k * 2 + 1, l, (l + r) / 2);
    int rch = _get_interval(a, b, k * 2 + 2, (l + r) / 2, r);
    return func(lch, rch);
}
 
int get_interval(int l, int r) {
    return _get_interval(l - 1, r, 0, 0, leaf_num);
}



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int N, Q;
	cin >> N >> Q;
	init(N);

	rep(i, Q) {
		int com, x, y;
		cin >> com >> x >> y;
		
		if(com == 0) {
			update(x, y);
		} else {
			cout << get_interval(x, y) << endl;
		}
	}
	return 0;
}