AcWing 1264. 动态求连续区间和
原题链接
简单
作者:
xybh
,
2020-08-26 20:15:47
,
所有人可见
,
阅读 419
#include<iostream>
#include<cstdio>
using namespace std;
const int N = 100050;
int a[N], tr[N];
int n, m;
int lowbit(int x){
return x & -x;
}
void add(int x, int v){
for(int i = x; i <= n; i += lowbit(i)) tr[i] += v;
}
int query(int x){
int res = 0;
for(int i = x; i; i -= lowbit(i)) res += tr[i];
return res;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
for(int i = 1; i <= n; i++) add(i, a[i]);
while(m--){
int k, x, y;
scanf("%d%d%d", &k, &x, &y);
if(k == 0){
printf("%d\n", query(y) - query(x-1));
}else{
add(x, y);
}
}
return 0;
}