poj2155
来源:互联网 发布:mac 音乐播放器 编辑:程序博客网 时间:2024/05/21 19:28
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int T,n,m,c[1005][1005];int bit(int& x){ return x&(-x);}void update(int x,int y){ for(int i=x;i<=n;i+=bit(i)) for(int j=y;j<=n;j+=bit(j)) { c[i][j]++; }}int sum(int x,int y){ int ans=0; for(int i=x;i>0;i-=bit(i)) for(int j=y;j>0;j-=bit(j)) ans+=c[i][j]; return ans;}int main(){ cin>>T; while(T--) { cin>>n>>m; memset(c,0,sizeof(c)); char op; int x1,x2,y1,y2; for(int i=0;i<m;i++) { cin>>op; if(op=='C') { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); update(x1,y1); update(x1,y2+1); update(x2+1,y1); update(x2+1,y2+1); } else { scanf("%d%d",&x1,&y1); printf("%d\n",sum(x1,y1)%2); } } printf("\n"); } return 0;}
此题使用二维树状数组比较方便,维护更新其实是对(x,y,n,n)的更新由于两次操作会抵消,所以四次更新就会达到效果。
另外,此题是我的第一个二维树状数组,做着还是有点痛苦的,希望自己以后越来越熟练
0 0
- POJ2155
- poj2155
- poj2155
- poj2155
- POJ2155
- poj2155
- poj2155
- poj2155
- POJ2155
- poj2155
- POJ2155
- poj2155
- POJ2155 Matrix
- POJ2155:Matrix
- poj2155 Matrix
- poj2155 Matrix
- poj2155 Matrix
- POJ2155 Matrix
- Android 通过ContentProvider数据库更新UI
- UNIX环境C语言编程(15)-终端IO
- ORACLE函数大全
- POJ3311 Hie with the Pie ACM解题报告(Floyd+状压dp)
- 三大编码的由来总结
- poj2155
- textfield自动输入
- JQuery基础
- 巧用Drawable 实现Android UI 元素间距效果
- Oracle闪回查询总结
- fibonacci数列的递归和非递归解法
- js数组对象的方法
- Oracle 闪回特性(FLASHBACK DATABASE)
- 如何计算时间复杂度