90分求助!!!

P3374 【模板】树状数组 1

希望更丰富的展现?使用Markdown
by aminoas @ 2019-03-03 11:49:07


希望更丰富的展现?[使用Mark♂down](https://www.luogu.org/wiki/show?name=%E5%B8%AE%E5%8A%A9%EF%BC%9Amarkdown)
by aminoas @ 2019-03-03 11:49:46


```cpp int c[550000]; int lowbit(int x) { return x&(-x); } void update(int x,int y,int n) { for(int i=x;i<=n;i+=lowbit(i)) c[i] += y; } int getsum(int x) { int ans = 0; for(int i=x;i!=0;i-=lowbit(i)) ans += c[i]; return ans; } int main() { int n,m; cin >> n >> m; for(int i=1;i<=n;i++) { int x; cin >> x; update(i,x,n); } while(m--) { int op,x,y; cin >> op >> x >> y; if(op==1) update(x,y,n); else cout << getsum(y) - getsum(x-1) << endl; } return 0; } ```
by Countjoyyauldly @ 2019-03-03 11:52:10


@[2018J1605](/space/show?uid=143834) ```cpp int c[550000]; int lowbit(int x) { return x&(-x); } void update(int x,int y,int n) { for(int i=x;i<=n;i+=lowbit(i)) c[i] += y; } int getsum(int x) { int ans = 0; for(int i=x;i!=0;i-=lowbit(i)) ans += c[i]; return ans; } int main() { int n,m; cin >> n >> m; for(int i=1;i<=n;i++) { int x; cin >> x; update(i,x,n); } while(m--) { int op,x,y; cin >> op >> x >> y; if(op==1) update(x,y,n); else cout << getsum(y) - getsum(x-1) << endl; } return 0; } ```
by Countjoyyauldly @ 2019-03-03 11:53:14


@[名探偵コナン](/space/show?uid=124143) 还是找我大号@[2018C1605](/space/show?uid=188183) 吧
by aminoas @ 2019-03-03 11:54:36


@[2018C1605](/space/show?uid=188183)
by Countjoyyauldly @ 2019-03-03 11:56:02


@[2018J1605](/space/show?uid=143834) 你的大号。。。认真的吗
by Countjoyyauldly @ 2019-03-03 11:57:07


@[名探偵コナン](/space/show?uid=124143) 把cin改成scanf试试
by mcyqwq @ 2019-03-03 12:14:45


@[名探偵コナン](/space/show?uid=124143) 当然是真的
by aminoas @ 2019-03-03 12:24:06


你这个程序有点慢啊,常数比较大吧估计。。。 总耗时2590ms,我的总耗时也才459ms。。 ~~要不你试试用scanf?或者快读?~~
by xzlhxc_ed @ 2019-03-03 12:24:12


| 下一页