操作:区间和询问,单点增加
#include<iostream> #include<cstdio> #define ri register int #define u int namespace opt { inline u in() { u x(0),f(1); char s(getchar()); while(s<'0'||s>'9') { if(s=='-') f=-1; s=getchar(); } while(s>='0'&&s<='9') { x=(x<<1)+(x<<3)+s-'0'; s=getchar(); } return x*f; } } using opt::in; #define NN 500005 namespace mainstay { u N,K; u c[NN]; inline u ask(const u &x){ u _re(0); for(ri i(x);i;i-=i&-i) _re+=c[i]; return _re; } inline void add(const u &x,const u &y){ for(ri i(x);i<=N;i+=i&-i) c[i]+=y; } inline void solve() { N=in(),K=in(); for(ri i(1);i<=N;++i){ u _a(in()); add(i,_a); } for(ri i(1);i<=K;++i){ u _k(in()),_a(in()),_b(in()); if(_k==1){ add(_a,_b); } else printf("%d\n",ask(_b)-ask(_a-1)); } } } int main() { //freopen("x.txt","r",stdin); std::ios::sync_with_stdio(false); mainstay::solve(); }