有lalao可以帮最蒟蒻看一下吗

P3368 【模板】树状数组 2

**感觉是加的时候时有问题~**
by 小豹12138 @ 2018-11-06 22:37:59


lalao
by qsmoonzh @ 2018-11-06 22:48:07


@[小豹12138](/space/show?uid=134109) 这题要差分做 你这样更新会重
by Hono @ 2018-11-06 22:53:08


```cpp #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n,m; const int N=5e5+5; int c[N]; int lowbit(int x) { return x&(-x); } void update(int x,int y) { for(;x<=n;x+=lowbit(x)) { c[x]+=y; } } int num(int x) { int ans=0; for(;x;x-=lowbit(x)) { ans+=c[x]; } return ans; } int main() { scanf("%d %d ",&n,&m); int v1=0,v2=0; for(int i=1;i<=n;i++) { scanf("%d",&v1); update(i,v1-v2); v2=v1; } while(m--) { int pan; scanf("%d",&pan); if(pan==1) { int a,b,vi; scanf("%d %d %d",&a,&b,&vi); //for(int i=a;i<=b;i++) update(a,vi); update(b+1,-vi); } else if(pan==2) { int e;scanf("%d ",&e); printf("%d\n",num(e)); } } return 0; } ```
by 小豹12138 @ 2018-11-06 22:58:15


@[保登心爱](/space/show?uid=27115) **100了 谢谢额~**
by 小豹12138 @ 2018-11-06 22:59:07


~~**lalao???**~~ 谁有UKE代码?(最好带上题号)**学术版讨论被删除了QWQ**
by 持之以珩 @ 2019-01-27 22:55:30


|