树状数组1【模板】
洛谷P3374
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 500000;
int n,m,d,x,y;
int a[N + 5],c[N + 5]; //分别用来存储原始序列和树状数组
void update(int x,int y){ //更新数组c
for(;x <= n;x += x & -x)
c[x] += y;
}
void build(){ //建立数组c
for(int i = 1;i <= n;++i){
cin>>a[i];
update(i,a[i]);
}
}
int get(int x){ //得到前缀和
int ans = 0;
for(;x;x -= x & -x)
ans += c[x];
return ans;
}
signed main(){
cin>>n>>m;
build();
while(m--){
cin>>d>>x>>y;
if(d == 1){
a[x] += y;
update(x,y);
}
else
cout<<get(y) - get(x - 1)<<"\n";
}
return 0;
}