POJ 2155 (二维树状数组)
来源:互联网 发布:diy美工刀架 编辑:程序博客网 时间:2024/06/05 01:52
题目点我点我点我
题目大意:矩阵里面开始全是0,‘C x1,y1,x2,y2’就是将左上角为x1,y1,右下角为x2,y2,的这个矩阵内的数字进行变换,0变1,1变0;'Q x1 y1',输出a[x1][y1]的值。
解题思路:经典的二维树状数组,重叠消元,利用0和1之间变换特性,答案对2取余即可。
/* ***********************************************┆ ┏┓ ┏┓ ┆┆┏┛┻━━━┛┻┓ ┆┆┃ ┃ ┆┆┃ ━ ┃ ┆┆┃ ┳┛ ┗┳ ┃ ┆┆┃ ┃ ┆┆┃ ┻ ┃ ┆┆┗━┓ 马 ┏━┛ ┆┆ ┃ 勒 ┃ ┆ ┆ ┃ 戈 ┗━━━┓ ┆┆ ┃ 壁 ┣┓┆┆ ┃ 的草泥马 ┏┛┆┆ ┗┓┓┏━┳┓┏┛ ┆┆ ┃┫┫ ┃┫┫ ┆┆ ┗┻┛ ┗┻┛ ┆************************************************ */#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>using namespace std;#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)#define pb push_back#define mp make_pairconst int inf_int = 2e9;const long long inf_ll = 2e18;#define inf_add 0x3f3f3f3f#define mod 1000000007#define LL long long#define ULL unsigned long long#define MS0(X) memset((X), 0, sizeof((X)))#define SelfType intSelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);}SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;}#define Sd(X) int (X); scanf("%d", &X)#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}//#pragma comment(linker, "/STACK:102400000,102400000")int n,m;int c[1005][1005];int lowbit(int x){ return x & (-x);}void update(int x,int y,int val){ for(int i=x;i<=n;i+=lowbit(i)) { for(int j=y;j<=n;j+=lowbit(j)) { c[i][j] += val; } }}int sum(int x,int y){ int ans = 0; for(int i=x;i;i-=lowbit(i)) { for(int j=y;j;j-=lowbit(j)) { ans += c[i][j]; } } return ans;}int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);ios::sync_with_stdio(0);cin.tie(0);Sd(t);while(t--) { MS0(c); n = read(),m = read(); while(m--) { char c; scanf("%c",&c); if(c=='C') { int x1,x2,y1,y2; x1 = read(),y1 = read(); x2 = read(),y2 = read(); update(x1,y1,1); update(x2+1,y1,1); update(x1,y2+1,1); update(x2+1,y2+1,1); } else { int x,y; x = read(),y = read(); printf("%d\n",sum(x,y)%2); } } printf("\n"); }return 0;}
0 0
- poj 2155 Matrix(二维树状数组)
- poj 2155(二维树状数组)
- poj 2155 (二维树状数组)
- POJ 2155 Matrix (二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- 【树状数组(二维)】poj 2155 Matrix
- POJ 2155 Matrix (二维树状数组)
- [poj 2155] Matrix(二维树状数组)
- POJ 2155 Matrix (二维树状数组)
- POJ-2155(二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- POJ 2155(二维树状数组模板)
- POJ 2155 Matrix(二维树状数组)
- POJ 2155 二维树状数组(插块问点)
- POJ 2155 Matrix(二维树状数组)
- POJ 2155 (二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- statement的四个执行方法---executeQuery/executeUpdate/execute/executeBatch---和早期数据库防黑技术
- 刘汝佳白书 10-3-4危险的组合(统计(数位dp))
- Spring MVC 深入及对注解的详细讲解
- linux【进程学习】笔记——PCB、进程环境、进程原语、虚拟地址……
- 菲波拉契数列的通项公式
- POJ 2155 (二维树状数组)
- hadoop面试百题
- mybaties 映射注解 详情
- 测试用例设计综合策略
- LeetCode-97.Interleaving String
- deeplearning论文学习笔记(1)Convolutional Neural Networks for Sentence Classification
- isKindOfClass 与 isMemberOfClass的区别
- wm8976的初始化函数、写寄存器函数和音量控制函数分析
- rror LNK2001: unresolved external symbol _cvExtractSURF