#includeiostream #include cstdio using namespace std; int pd,c[ 500001 ],a[ 500001 ],x,y,k,n,m; int lowbit( int xx) { return xx- xx; } void update( int xx, int yy) { while (xx= n) { c[xx] += yy; xx += lowbit(xx); } } int getsum( int xx) { i
#include<iostream> #include<cstdio>
using namespace std; int pd,c[500001],a[500001],x,y,k,n,m; int lowbit(int xx) { return xx&-xx; } void update(int xx,int yy) { while(xx<=n) { c[xx]+=yy; xx+=lowbit(xx); } } int getsum(int xx) { int sum=0; while(xx>0) { sum+=c[xx]; xx-=lowbit(xx); } return sum; } int main() { cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a[i]; update(i,a[i]); } for(int i=1;i<=m;i++) { cin>>pd; if(pd==1) { cin>>x>>k; update(x,k); } if(pd==2) { cin>>x>>y; cout<<getsum(y)-getsum(x-1)<<endl; } } return 0; }
2019-09-09 By十四日的夏