树状数组区间更新区间查询

 1 void ins(int k,int x,int t){
 2     for (; x<=tot; x+=x&-x) c[k][x]+=t;
 3 }
 4 ll getsum(int k,int x){
 5     ll t=0; for (; x; x-=x&-x) t+=c[k][x]; return t;
 6 }
 7 void mdy(int x,int y,int z){
 8     ins(0,x,z); ins(1,x,z*(x-1)); ins(0,y+1,-z); ins(1,y+1,-z*y);
 9 }
10 ll qry(int x,int y){
11     return getsum(0,y)*y-getsum(1,y)-getsum(0,x-1)*(x-1)+getsum(1,x-1);
12 }

 

posted @ 2016-06-29 22:29  Kurokey  阅读(155)  评论(0编辑  收藏  举报