【树状数组 区间更新区间查询】code
来源:互联网 发布:明基显示器调节软件 编辑:程序博客网 时间:2024/05/16 10:35
Link:http://codevs.cn/problem/1082/
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;//c[i] = a[i]-a[i-1]//c2[i] = (i-1)*c[i]//树状数组维护c,c2//ans[1-n]: n*sigma(c,n) - sigma(c2,n)const int N = 200010;#define lowbit(i) (i&(-i))LL c[N],c2[N];LL n;void up(LL *r,LL x,LL val){ while(x<=n){ r[x] += val; x += lowbit(x); }}LL down(LL *r,LL x){ LL ans = 0; while(x){ ans += r[x]; x -= lowbit(x); } return ans;}int main(){ LL q; scanf("%lld",&n); for(int i = 1; i <= n; i++){ LL f; scanf("%lld",&f); up(c,i,f); up(c,i+1,-f); up(c2,i,f*(i-1)); up(c2,i+1,-f*(i)); } scanf("%lld",&q); while(q--){ int type; scanf("%d",&type); LL a,b,f; if(type==1){ scanf("%lld%lld%lld",&a,&b,&f); up(c,a,f); up(c,b+1,-f); up(c2,a,f*(a-1)); up(c2,b+1,-f*b); } else{ scanf("%lld%lld",&a,&b); LL l = (a-1)*down(c,a-1) - down(c2,a-1); LL r = b*down(c,b) - down(c2,b); printf("%lld\n",r-l); } } return 0;}
阅读全文
0 0
- 【树状数组 区间更新区间查询】code
- 树状数组(区间更新区间查询)
- 树状数组区间更新+区间查询+单点查询
- poj2155树状数组 区间更新 单点查询
- 树状数组的单点更新,区间查询。
- poj3468-树状数组 一维 区间更新 区间查询
- 2017.8.23-------树状数组---区间更新+区间查询
- hdu1166 树状数组模板:单点更新,区间求和(区间查询)
- 树状数组 区间更新
- 树状数组区间更新
- 树状数组模板区间更新 区间询问
- 树状数组 区间更新 区间求和
- 树状数组 区间更新 区间求和
- 树状数组模板区间更新 区间询问
- POJ 3468 A Simple Problem with Integers (树状数组解法 树状数组区间更新 区间查询)
- 树状数组~poj3468~区间修改 区间查询
- 树状数组 --区间查询+区间修改
- 【codevs1082】【树状数组】 区间修改 区间查询
- 蚂蚁路径问题
- poj_2142_欧几里得扩展解延伸_理解过程紧张刺激
- C#清除系统日志
- 家用无线路由器哪个品牌好?分享值得推荐的无线路由器给你无线选得好,网络没烦恼
- leetcode01. Two SumII
- 【树状数组 区间更新区间查询】code
- 【MPI学习4】MPI并行程序设计模式:非阻塞通信MPI程序设计
- 面试题:模拟实现strcpy函数
- listview + imageloder多条目加载
- triangulation method中的midpoint method and Linear triangulation method
- scala的trait之我见
- java的回调函数
- hdu———2955”Robberies”
- OpenGL中VBO及VAO区别