luogu_P3374 【模板】树状数组 1
操作:区间和询问,单点增加 #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); }