POJ 2155 Matrix(二维树状数组)
来源:互联网 发布:电子罗盘 数据 使用 编辑:程序博客网 时间:2024/05/17 05:12
题目链接:http://poj.org/problem?id=2155
这个题目和上面一题一样,不过这个还简单点
先理解一维的再来理解二维的就好多了
看算法合集之《浅谈信息学竞赛中的“0”和“1”》上面讲的比较清楚
#include <string.h>#include <algorithm>#include <iostream>#include <stdio.h>using namespace std;const int maxn = 1005;int tree[maxn][maxn];int n,m;char str[10];int lowbit(int x){ return (-x)&x;}int sum(int i,int j){ int ans=0,now; while(i>0){ now=j; while(now>0){ ans+=tree[i][now]; now-=lowbit(now); } i-=lowbit(i); } return ans;}int update(int i,int j){ int now; while(i<=n){ now=j; while(now<=n){ tree[i][now]++; now+=lowbit(now); } i+=lowbit(i); } return 0;}int main(){ int i,j,k,t,x1,y1,x2,y2,x11,y11,x22,y22; scanf("%d",&t); while(t--){ memset(tree,0,sizeof(tree)); scanf("%d%d",&n,&m); for(i=0;i<m;i++){ scanf("%s",str); if(str[0]=='C'){ scanf("%d%d%d%d",&x11,&y11,&x22,&y22); x1=min(x11,x22); x2=max(x11,x22); y1=min(y11,y22); y2=max(y11,y22); 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;}
- poj 2155 Matrix(二维树状数组)
- POJ 2155 Matrix (二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- 【树状数组(二维)】poj 2155 Matrix
- POJ 2155 Matrix (二维树状数组)
- [poj 2155] Matrix(二维树状数组)
- POJ 2155 Matrix (二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- [POJ 2155] Matrix (二维树状数组)
- poj 2155 - Matrix(二维树状数组)
- poj 2155 Matrix (二维树状数组)
- POJ 2155 Matrix (二维树状数组)
- poj 2155 Matrix(二维树状数组)
- poj 2155 Matrix (二维树状数组)
- 九度OJ 1003
- 动态规划 --- hdu 1176 **
- 山东理工大学ACM平台题答案 1170 C语言实验——最值
- 常用字符串哈希函数(网上收集)
- ubuntu启动流程及定制
- POJ 2155 Matrix(二维树状数组)
- AJAX状态值与状态码
- linux:vi 替换命令
- HDU 4612 桥数-缩点后树的直径
- sublime python的一些使用命令
- 考试系统——可输入并自动匹配的下拉框(三)——Html,Web控件级联
- uva--401 Palindromes
- 大数定律---频率代替概率
- discuz论坛开启帖子内容下方的“顶”“踩”功能