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++14 (judge verdict: Accepted)

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll n, q, s, t;

struct RSQ
{
	ll gt;
	ll seg[201000 * 2];
	void init(int n) {
		gt = 1;
		while (gt < n)gt *= 2;
		rep(i, n * 2)seg[i] = 0;
	}
	void update(int k, int x) {
		k += gt - 1;
		seg[k] += x;
		while (k) {
			k = (k - 1) / 2;
			seg[k] += x;
		}
	}
	void update_2(ll k, ll x) {
		k += gt - 1;
		ll tt = seg[k];
		ll h;
		if (seg[k] < 0)h = seg[k] / (-s);
		else h = seg[k] / (-t);
		h += x;
		if (h < 0)seg[k] = h*(-t);
		else seg[k] = h*(-s);
		tt = seg[k] - tt;
		while (k) {
			k = (k - 1) / 2;//???????????????
			seg[k] += x;
		}
	}
	ll query(int a, int b) {
		return query(a, b, 0, 0, gt);
	}
	ll query(int a, int b, int k, int l, int r) {//[a,b)???????????????,k=0,l=0,r=gt
		if (r <= a || b <= l)return 0;
		if (a <= l&&r <= b) {
			return seg[k];
		}
		else return query(a, b, k * 2 + 1, l, (l + r) / 2)
			+ query(a, b, k * 2 + 2, (l + r) / 2, r);
	}
	void print() {
		rep(i, 2 * gt)cout << "!" << i << " " << seg[i] << endl;
	}
};

RSQ rsq;

int main() {
	cin >> n >> q;
	rsq.init(n + 1);
	rep(i, q) {
		int a, b, c;
		cin >> a >> b >> c;
		b--;
		if (a == 0) {
			rsq.update(b, c);
		}
		else {
			cout << rsq.query(b, c) << endl;
		}
	}
}