#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int MAXN=500005;
int n,m,a[MAXN],c[MAXN],k,x,y,z;
int look(int u){return u&(-u);}
void work(int u,int v){
for(int i=u;i<=n;i+=look(i)) c[i]+=v;
}
int getsum(int u){
int ans=0;
for(int i=u;i>0;i-=look(i))
ans+=c[i];
return ans;
}
int main(){
//freopen("stack.in","r",stdin);
//freopen("stack.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++){
k=look(i);
for(int j=1;j<=k;j++) c[i]+=a[i-k+j];
}
while(m--){
scanf("%d%d%d",&x,&y,&z);
if(x==1) work(y,z);
if(x==2) printf("%d\n",getsum(z)-getsum(y-1));
}
return 0;
}
P3374 【模板】树状数组 1
最新推荐文章于 2020-09-14 22:52:58 发布