POJ2155 Matrix(二维树状数组)
2015-09-05 11:08
381 查看
题意:给出矩阵左上角和右下角坐标,矩阵里的元素 1变0 ,0 变1,然后给出询问,问某个点是多少。
#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <cstdio> #define MAXN 1010 int c[MAXN][MAXN],n; int lowbit(int x) { return x&(-x); } void update(int x,int y) { for(int i=x; i<=n; i+=lowbit(i)) for(int j=y; j<=n; j+=lowbit(j)) c[i][j]++; } int getSum(int x,int y) { int s=0; for(int i=x; i>0; i-=lowbit(i)) for(int j=y; j>0; j-=lowbit(j)) s+=c[i][j]; return s; } int main() { int t,m,x1,x2,y1,y2; char ch[2]; scanf("%d",&t); while(t--) { memset(c,0,sizeof(c)); scanf("%d%d",&n,&m); while(m--) { scanf("%s",ch); if(ch[0]=='C') { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); x1++; y1++; x2++; y2++; update(x2,y2); update(x1-1,y1-1); update(x1-1,y2); update(x2,y1-1); } else { scanf("%d%d",&x1,&y1); printf("%d\n",getSum(x1,y1)%2); } } printf("\n"); } return 0; }
相关文章推荐
- 使用busybox制作微Linux系统
- Ubuntu12.04执行脚本程序的方法
- STM32通过USB实现Bootlader/IAP功能
- ActionScript 3.0 学习(十一) AS3 模拟接金币小游戏
- 综合案例:运算符的使用
- Linux异步I/O
- 值得推荐的C/C++框架和库 (真的很强大)
- ML_SVM的菜鸟实现
- 在配置Grunt的Task时通配符支持和动态生成文件名详解
- parseInt和valueOf
- 1.OA系统概述
- android 的service
- CSS基础知识
- 分层 分割(优秀)
- 动画演示10个超有趣的Linux命令
- C++ vector用法
- 中国移动手机阅读基地社会招聘笔试面试全过程
- c语言复杂数据类型
- 用Java语言编写一个金字塔程序
- mysql允许远程访问 root