bzoj 3155 Preprefix sum 树状数组
来源:互联网 发布:普拉提的作用 知乎 编辑:程序博客网 时间:2024/06/05 18:43
非常神奇的题目啊,我语文不好,所以不写题解了。
#include<iostream>#include<cstdio>#define LL long longusing namespace std;int n,m;LL a[100005];LL c[100005];void change1(int x,LL d){ while(x<=n) { c[x]+=d; x+=x&(-x); }}LL ask1(int x){ LL ans=0; while(x>0) { ans+=c[x]; x-=x&(-x); } return ans;}LL s[100005];void change2(int x,LL d){ while(x<=n) { s[x]+=d; x+=x&(-x); }}LL ask2(int x){ LL ans=0; while(x>0) { ans+=s[x]; x-=x&(-x); } return ans;}char q[10];int main(){ scanf("%d%d",&n,&m); int x,y; for(int i=1;i<=n;i++) { scanf("%d",&x); a[i]=x; change1(i,(LL)x); change2(i,(LL)x*(n-i+1)); } LL ans; int w; for(int i=1;i<=m;i++) { scanf("%s",q+1); if(q[1]=='Q') { scanf("%d",&x); ans=ask2(x); ans-=ask1(x)*(n-x); printf("%lld\n",ans); } else { scanf("%d%d",&x,&y); w=y-a[x]; change1(x,(LL)w); change2(x,(LL)w*(n-x+1)); a[x]=y; } } return 0;}
4 0
- bzoj 3155 Preprefix sum 树状数组
- BZOJ 3155: Preprefix sum 树状数组
- [bzoj 3155] Preprefix sum(树状数组)
- BZOJ 3155: Preprefix sum 树状数组题解
- bzoj 3155: Preprefix sum 树状数组
- 【BZOJ】【P3155】【Preprefix sum】【题解】【树状数组】
- 【BZOJ】3155 Preprefix Sum
- bzoj 3155 Preprefix sum
- BZOJ 3155 Preprefix sum
- 【bzoj3155】【Preprefix sum】【树状数组】
- 【BZOJ3155】Preprefix sum【树状数组】
- bzoj3155: Preprefix sum 树状数组
- [bzoj-3155]Preprefix sum 题解
- BZOJ Preprefix sum
- 3155: Preprefix sum
- 3155: Preprefix sum
- bzoj 3155 树状数组
- bzoj3155: Preprefix sum
- SQLite.Net使用入门(三)【增删改查】
- 如何使用指向类的成员函数的指针(详解!)
- 同比与环比——财务小知识点
- 第五周项目5 后缀表达式
- 【<meta name="description" content=">】作用讲解
- bzoj 3155 Preprefix sum 树状数组
- 深入理解内部类
- 文章标题
- (第五周项目5)后缀表达式
- Secure CRT 自动记录日志和时间戳功能配置
- windows 命令行打印
- npm start
- 1111111111111111111
- 第五周 项目4: 后缀表达式