Codeforces 390 E. Inna and Large Sweet Matrix
来源:互联网 发布:如何手机关闭淘宝店 编辑:程序博客网 时间:2024/05/25 12:22
主要是树状数组的改段求段操作。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long int LL;const int maxn=4000400;int n,m,w,nm;LL B[2][maxn],C[2][maxn];int lowbit(int x){return x&(-x);}void add_b(int id,int p,LL v){for(int i=p;i;i-=lowbit(i)) B[id][i]+=v;}void add_c(int id,int p,LL v){for(int i=p;i<=nm;i+=lowbit(i)) C[id][i]+=v*p;}LL sum_b(int id,int p){LL sum=0;for(int i=p;i<=nm;i+=lowbit(i)) sum+=B[id][i];return sum;}LL sum_c(int id,int p){LL sum=0;for(int i=p;i;i-=lowbit(i)) sum+=C[id][i];return sum;}void ADD(int id,int l,int r,LL v){add_b(id,r,v);add_c(id,r,v);if(l-1){add_b(id,l-1,-v);add_c(id,l-1,-v);}}LL sUm(int id,int p){if(p)return sum_b(id,p)*p+sum_c(id,p-1);else return 0;}LL SUM(int id,int l,int r){return sUm(id,r)-sUm(id,l-1);}int main(){scanf("%d%d%d",&n,&m,&w);nm=max(n,m)+10;while(w--){int c,x1,x2,y1,y2,v,dx,dy;scanf("%d%d%d%d%d",&c,&x1,&y1,&x2,&y2);dx=x2-x1+1;dy=y2-y1+1;if(c==0){scanf("%d",&v);ADD(0,x1,x2,v*dy);ADD(1,y1,y2,v*dx);}else{printf("%I64d\n",SUM(1,y1,y2)-SUM(0,1,x1-1)-SUM(0,x2+1,nm));}}return 0;}
0 0
- Codeforces 390 E. Inna and Large Sweet Matrix
- CodeForces 390E Inna and Large Sweet Matrix
- CF 390E - Inna and Large Sweet Matrix(TODO)
- Codeforces 390E Inna and Large Sweet Matrix(树状数组)
- Codeforces 390E Inna and Large Sweet Matrix 树状数组改段求段
- CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段)
- codeforces 390d Inna and Sweet Matrix
- Codeforces 390D Inna and Sweet Matrix(贪心)
- Codeforces #229 D2D: Inna and Sweet Matrix
- CF 390D:Inna and Sweet Matrix
- codeforces Inna and New Matrix of Candies
- codeforces Inna and Huge Candy Matrix
- CodeForces 400E Inna and Binary Logic
- codeforces 400B. Inna and New Matrix of Candies
- Codeforces 400 C. Inna and Huge Candy Matrix
- Codeforces 400C Inna and Huge Candy Matrix(模拟)
- codeforces 400B - Inna and New Matrix of Candies
- codeforces 400C - Inna and Huge Candy Matrix
- C# PropertyGrid控件应用心得
- 模块使用计数
- JS 数字 、中文、 英文、判断
- Docker: 利用Linux容器实现可移植的应用部署
- N皇后源代码
- Codeforces 390 E. Inna and Large Sweet Matrix
- SLM7.1SR1SP05 配置(configuration guide+ link help) - 03 initial configuration part2
- dma_alloc_writecombine
- 8、SSH整合续
- shell 中的括号()[] {} (()) [[]]
- 将文件移动到指定目录下,并且加上时间戳进行重命名
- 【翻译】【西川善司】GPU和Shader技术的基础知识 (一共有99回,翻译中)
- 时间都去哪里了
- C# 输出格式化