rt,这样全WA
树状数组,代码如下
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[500005];
int n,m;
int lowbit(int x){return (x&(-x));}
void update(int pos,ll x){
while(pos<=n){
a[pos]+=x;
pos+=lowbit(pos);
}
}
ll query(int pos){
ll num=0;
while(pos>0){
num+=a[pos];
pos-=lowbit(pos);
}
return num;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
update(i,x);
}
for(int i=0;i<m;i++){
int op,x;
ll y;
scanf("%d%d%lld",&op,&x,&y);
if(op==1)update(x,y);
else printf("%lld\n",query(y)-query(x-1));
}
return 0;
}
太神奇了