POJ1195 Mobile phones 二维树状数组
来源:互联网 发布:手机直播软件大全 编辑:程序博客网 时间:2024/05/16 08:22
题目链接:http://poj.org/problem?id=1195
题目大意:给出一个n*n的矩阵,两种操作:“1 x y v”表示将矩阵上的点(x,y)加上v;“2 x1 y1 x y”表示查询矩阵的和。
分析:和HDU2645 Stars类似,很裸的二维树状数组的题。
实现代码如下:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int M=1100;int a[M][M],n;int lowbit(int i){ return i&(-i);}void update(int x,int y,int v){ for(int i=x;i<M;i+=lowbit(i)) for(int j=y;j<M;j+=lowbit(j)) a[i][j]+=v;}int query(int x,int y){ int sum=0; for(int i=x;i>0;i-=lowbit(i)) for(int j=y;j>0;j-=lowbit(j)) sum+=a[i][j]; return sum;}int main(){ int op,x,y,v,x1,y1; while(true) { scanf("%d",&op); switch(op) { case 0:scanf("%d",&n); memset(a,0,sizeof(a)); break; case 1:scanf("%d%d%d",&x,&y,&v); update(x+1,y+1,v); break; case 2:scanf("%d%d%d%d",&x1,&y1,&x,&y); x++; y++; x1++; y1++; printf("%d\n",query(x,y)-query(x,y1-1)-query(x1-1,y)+query(x1-1,y1-1)); break; case 3:return 0; } }}
0 0
- POJ1195 Mobile phones, 二维树状数组
- poj1195 Mobile phones 二维树状数组
- POJ1195--Mobile phones--二维树状数组
- poj1195 mobile phones 【二维树状数组】
- POJ1195 Mobile phones 【二维树状数组】
- poj1195--Mobile phones(二维树状数组)
- poj1195 Mobile phones 二维树状数组
- POJ1195 Mobile phones【树状数组】【二维】
- POJ1195:Mobile phones(二维树状数组)
- POJ1195 Mobile phones 二维树状数组
- (POJ1195)Mobile phones <二维树状数组>
- poj1195 Mobile phones(二维树状数组)
- poj1195~Mobile phones(二维树状数组)
- poj1195 Mobile phones(二维树状数组)
- POJ1195 Mobile phones(树状数组)
- [树状数组] poj1195 Mobile phones
- POJ1195 Mobile phones 二维树状数组 更新节点,查询区域
- POJ1195 Mobile phones(简单二维树状数组)
- java 读取系统配置文件
- 第6周、项目5—后缀表达式
- 第7周 项目2-建立链队算法库
- 第七周上机实践项目2——建立链队算法库
- 黑马程序员——Java基础--------正则表达式
- POJ1195 Mobile phones 二维树状数组
- 数据库mysql学习笔记1
- 我心中的Android REST Client--9gag
- Android 开源项目分类汇总
- PoissonImageEdit实验报告
- java初学者对异常链的总结
- EPLAN使用技巧总结
- 建立顺序栈算法库
- 第六周 项目1 -- 建立顺序栈算法库