【模板】树状数组单点修改、区间查询

/*
单点修改,区间查询
*/
#include<bits/stdc++.h>

using namespace std;

int n, m;
long long a[10000010], b[10000010];

int lb(int x)
{
	return x & (-x);
}

void updata(int pos, int val)
{
	for(int i = pos; i <= n; i += lb(i))
	{
		b[i] += val;
	}
}

long long getsum(int pos)
{
	long long ans = 0;
	for(int i = pos; i > 0; i -= lb(i))
	{
		ans += b[i];
	}
	return ans;
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		updata(i, a[i]);
	}
	for(int i = 1, q, c, d; i <= m; i++)
	{
		scanf("%d%d%d", &q, &c, &d);
		if(q == 1) updata(c, d);
		else printf("%d\n", getsum(d) - getsum(c - 1));
	}
	return 0;
}
0%