poj 1195 Mobile phones (二维树状数组)
来源:互联网 发布:淘宝发布宝贝没有项 编辑:程序博客网 时间:2024/04/28 17:12
题目:http://poj.org/problem?id=1195
题意:给你N*N的矩阵,修改点,查矩阵的和。
分析:很裸的题了。。。
代码:
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int maxn = 1048;int tree[maxn][maxn],lowbit[maxn];void Init(){for(int i=1;i<maxn;i++)lowbit[i]=(i&-i);}void update(int x,int y,int c){for(int i=x;i<maxn && i;i+=lowbit[i])for(int j=y;j<maxn && j;j+=lowbit[j])tree[i][j]+=c;}int query(int x,int y){int ret(0);for(int i=x;i>0;i-=lowbit[i])for(int j=y;j>0;j-=lowbit[j])ret+=tree[i][j];return ret;}int main(){int N,q,R,T,L,B,x,y,v;Init();while(1){scanf("%d",&q); if(q==1){scanf("%d%d%d",&x,&y,&v);x++,y++;update(x,y,v);}else if(q==2){scanf("%d%d%d%d",&L,&B,&R,&T);L++,B++,R++,T++;printf("%d\n",query(R,T)-query(L-1,T)-query(R,B-1)+query(L-1,B-1));}else if(q==3)return 0;else{scanf("%d",&N);for(int i=1;i<=N+3;i++)memset(tree[i],0,sizeof(tree[0][0])*(N+3));}}return 0;}
0 0
- POJ 1195 Mobile phones 二维树状数组
- POJ 1195 Mobile phones【二维树状数组】
- POJ 1195 Mobile phones 二维树状数组
- poj 1195 Mobile phones 二维树状数组
- POJ 1195 Mobile phones 二维树状数组
- poj 1195 Mobile phones +二维树状数组
- POJ 1195 Mobile phones 二维树状数组
- Mobile Phones poj 1195--二维树状数组
- POJ 1195 Mobile phones【二维树状数组】
- POJ 1195 Mobile phones(二维树状数组)
- POJ 1195 Mobile phones(二维树状数组)
- POJ 1195 Mobile phones(二维树状数组)
- poj 1195 mobile phones 二维树状数组
- POJ 1195 Mobile phones 二维树状数组
- Poj 1195 Mobile phones 二维树状数组
- poj 1195 Mobile phones(二维树状数组)
- poj 1195 Mobile phones 二维树状数组
- POJ 1195 Mobile phones (二维树状数组)
- Linux建立文件目录链接的方法
- 输出字符串与数字时的小差异
- 文章标题
- 输入字符串反序输出
- 小胖学PHP总结3-----PHP的循环语句
- poj 1195 Mobile phones (二维树状数组)
- 【百度实习录】串讲考核
- VS项目属性的一些配置项的总结(important)
- HDU 3555 Bomb(数位DP模板啊两种形式)
- 循环结构 函数的定义
- 逻辑回归与softmax回归
- Hibernate3学习笔记(9)—— HQL实现查询对象部分属性
- 数组 (例:int[] x,y[]; //定义了一维数组x,二维数组y)
- Armadillo C++ linear algebra library 学习笔记(4)——矩阵的运算