POJ 1195 解题报告
来源:互联网 发布:万捷网络验证系统 编辑:程序博客网 时间:2024/05/18 00:38
这道题是二维树状数组(BIT)的基本应用。之前已经写过2155,那道题是区域更新,单点输出,比较异常。这道题是基本的单点更新,区域输出,所以比较好理解,一次就过了。
thestoryofsnow1195Accepted4276K594MSC++/* ID: thestor1 LANG: C++ TASK: poj2155 */#include <iostream>#include <fstream>#include <cmath>#include <cstdio>#include <cstring>#include <limits>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <algorithm>#include <cassert>using namespace std;const int MAXN = 1000;int N, T;int C[MAXN + 1][MAXN + 1];inline int lowbit(int x){return x & (-x);}void updateBIT(int x, int y, int delta){for (int i = x; i <= N; i += lowbit(i)){for (int j = y; j <= N; j += lowbit(j)){C[i][j] += delta;}}}int queryBIT(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 += C[i][j];}}return sum;}int main(){int X;scanf("%d", &X);char type;int x1, y1, x2, y2;for (int x = 0; x < X; ++x){scanf("%d%d", &N, &T);for (int i = 1; i <= N; ++i){for (int j = 1; j <= N; ++j){C[i][j] = 0;}}for (int t = 0; t < T; ++t){scanf(" %c ", &type);if (type == 'C'){scanf("%d%d%d%d", &x1, &y1, &x2, &y2);updateBIT(x2, y2, 1);updateBIT(x1 - 1, y2, -1);updateBIT(x2, y1 - 1, -1);updateBIT(x1 - 1, y1 - 1, 1);}else if (type == 'Q'){scanf("%d%d", &x1, &y1);printf("%d\n", queryBIT(x1, y1) % 2);}else{assert(false);}}// There is a blank line between every two continuous test cases. printf("\n");}return 0; }
0 0
- POJ 1195 解题报告
- 【POJ 1195 Mobile phones】解题报告
- poj数百篇解题报告
- poj 1141解题报告
- poj 1001解题报告
- poj 1011 解题报告
- poj 1087 解题报告
- poj 2153解题报告
- poj 2051解题报告
- POJ 1167 解题报告
- poj 1026 解题报告
- POJ 1077 解题报告
- POJ 1042 解题报告
- POJ 1095 解题报告
- POJ 1159解题报告
- poj 2312解题报告
- POJ 1001解题报告
- POJ 1002解题报告
- 自我探讨 国王和狱吏(合数)
- eclipse启动tomcat无法访问
- test
- 大数据学习篇:hadoop深入浅出系列之HDFS(三) ——HDFS读文件和写文件
- HDU - 2191 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活(多重背包)
- POJ 1195 解题报告
- Javascript高级程序设计第20章(JSON)
- poj 1466 Girls and Boys
- Vollery 框架之StringRequest二次封装
- pointer on C_1 基本概念
- spring的学习历程之利用MessageSource实现国际化占位符直接输出原因(一)
- 给定一个数组,返回最大子数组的累加和并且返回该子数组
- HDU - 1059 Dividing(完全背包+多重背包)
- C和指针(学习之旅)