poj 1195
来源:互联网 发布:淘宝网店装修设计师 编辑:程序博客网 时间:2024/06/05 07:28
很裸的二维树状数组。。
注意下标要加 1
//============================================================================// Name : hello.cpp// Author : lxw// Version :// Copyright : Your copyright notice// Description : Hello World in C++, Ansi-style//============================================================================#include<iostream>#include<algorithm>using namespace std;#define MAXN 1050#define LL __int64LL c[MAXN][MAXN];int N;int lowbit(int x){return x&(-x);}void update(int x,int y,int v){for(int i=x;i<=N+5;i+=lowbit(i)){for(int j=y;j<=N+5;j+=lowbit(j)){c[i][j]+=v;}}}LL getsum(int x,int y){LL sum=0;for(int i=x;i>0;i-=lowbit(i)){for(int j=y;j>0;j-=lowbit(j)){sum+=c[i][j];}}return sum;}int main(){//setbuf(stdout,NULL);int op,v;int x1,y1,x2,y2;while(scanf("%d",&op)&&op!=3){if(op==0){scanf("%d",&N);memset(c,0,sizeof(c));continue;}if(op==1){scanf("%d%d%d",&x1,&y1,&v);update(x1+1,y1+1,v);}if(op==2){scanf("%d%d%d%d",&x1,&y1,&x2,&y2);x1++;y1++;x2++;y2++;LL ans=getsum(x2,y2)-getsum(x1-1,y2)-getsum(x2,y1-1)+getsum(x1-1,y1-1);printf("%I64d\n",ans);}}}
- POJ 1195
- poj 1195
- POJ 1195
- poj 1195
- poj 1195
- poj 1195
- poj 1195
- poj 1195
- poj 1195
- POJ 1195
- poj-1195
- poj 1195
- poj 1195
- POJ 1195
- poj 1195
- 树状数组(poj 1195,poj 3321)
- POJ 1195 Mobile phones
- poj 1195 Mobile phones
- 测试stl
- MySQL常用语句
- C++ 使用模板 实现单例模式
- 导入外部类库自动生成各自的R类(选摘)
- perfmon 的counter 含义描述
- poj 1195
- 秒杀多线程第三篇 原子操作 Interlocked系列函数
- Java基础:三步学会Java Socket编程
- android--Handler
- Struts中常见的错误
- Git服务器在Ubuntu中的搭建
- 图片应用Fotopedia与Expedia公司合作 通过Expedia应用订酒店
- twm 窗口管理器
- android 命令行常用命令