c++
@[蒋中翼](/user/150125)
```cpp
#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
using namespace std;
int tree[10000001],a[10000001],n;
void add(int x,int y){
for(int i=x;i<=n;i+=lowbit(i)){
tree[i]+=y;
}
}
int sum(int x){
int ans=0;
for(int i=x;i;i-=lowbit(i)){
ans+=tree[i];
}
return ans;
}
int query(int l,int r){
return sum(r)-sum(l-1);
}
int q,op,k,x,l,r;
int main(){
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
add(i,a[i]);
}
for(int i=1;i<=q;i++){
cin>>op;
if(op==1){
cin>>k>>x;
add(k,x);
}
else{
cin>>l>>r;
cout<<query(l,r)<<"\n";
}
}
return 0;
}
```
by zjr2014 @ 2024-10-17 17:22:55
@[蒋中翼](/user/150125)
`python` TLE 不是正常吗,常数那么大。
by masonxiong @ 2024-11-01 11:18:17