POJ 1195 (Mobile phones) 二维树状数组
来源:互联网 发布:java 文件md5校验 编辑:程序博客网 时间:2024/04/25 09:43
题目链接:http://poj.org/problem?id=1195
题意:给出一个矩阵及一些操作,求一些子矩阵的和。
思路:二维树状数组裸题,要注意下标从0开始,所以可以在输入后对每个坐标值都加1。
#include<cstdio>#include<cstring>#include<string>#include<cctype>#include<iostream>#include<set>#include<map>#include<cmath>#include<sstream>#include<vector>#include<stack>#include<queue>#include<bitset>#include<algorithm>#define fin(a) freopen("a.txt","r",stdin)#define fout(a) freopen("a.txt","w",stdout)typedef long long ll;using namespace std;const int maxn = 1050;int a[maxn][maxn];int lowbit(int x) { return x & -x;}void add(int x, int y, int v, int n) { for(int i = x; i <= n; i += lowbit(i)) for(int j = y; j <= n; j += lowbit(j)) a[i][j] += v;}ll sum(int x, int y) { ll ans = 0; for(int i = x; i >= 1; i -= lowbit(i)) for(int j = y; j >= 1; j -= lowbit(j)) ans += (ll)a[i][j]; return ans;}int main() { int op, n; scanf("%d%d", &op, &n); while(scanf("%d", &op) && op != 3) { if(op == 1) { int x, y, z; scanf("%d%d%d", &x, &y, &z); x++, y++; add(x, y, z, n); } else { int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); x1++, y1++, x2++, y2++; ll ans = sum(x2, y2) - sum(x1-1, y2) - sum(x2, y1-1) + sum(x1-1, y1-1); printf("%lld\n", ans); } } 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 (二维树状数组)
- 多态 向上转型
- 【整理篇】数据结构与算法
- ubuntu系统, 在终端中使用代理
- MVC模型
- iOS runtime
- POJ 1195 (Mobile phones) 二维树状数组
- 查看 php-cgi 进程数
- bzoj 1941 kd-tree求最大最小曼哈顿距离
- Eclipse配置小结
- Python入门——流程控制
- Java学习记录--java面向对象的理解
- java-BlockingQueue 使用说明
- 凸多边形最优三角剖分(polygon decomposition)
- Final and static