1.单点加
2.前缀和查询
int n, m;
int a[N];
int tr[N];
int lowbit(int x){
return x&(-x);
}
void add(int pos,int k){
for(int i=pos;i<=n;i+=lowbit(i))tr[i]+=k;
}
int query(int x){
int res=0;
for(int i=x;i;i-=lowbit(i))res+=tr[i];
return res;
}
void solve(){
cin>>n;cin>>m;
for(int i=1;i<=n;i++){
int x;cin>>x;
add(i,x);
}
while(m--){
int op;cin>>op;
if(op==1){
int pos,val;cin>>pos>>val;
add(pos,val);
}
else {
int l,r;cin>>l>>r;
cout<<query(r)-query(l-1)<<endl;
}
}
}
标签:val,树状,int,基础,cin,pos,add,数组,op
From: https://www.cnblogs.com/mathiter/p/18086286