Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1 <= i, j <= N).

We can change the matrix in the following way. Given a rectangle whose upper-left corner is (x1, y1) and lower-right corner is (x2, y2), we change all the elements in the rectangle by using "not" operation (if it is a '0' then change it into '1' otherwise change it into '0'). To maintain the information of the matrix, you are asked to write a program to receive and execute two kinds of instructions.

1. C x1 y1 x2 y2 (1 <= x1 <= x2 <= n, 1 <= y1 <= y2 <= n) changes the matrix by using the rectangle whose upper-left corner is (x1, y1) and lower-right corner is (x2, y2). 
2. Q x y (1 <= x, y <= n) querys A[x, y]. 

Input

The first line of the input is an integer X (X <= 10) representing the number of test cases. The following X blocks each represents a test case.

The first line of each block contains two numbers N and T (2 <= N <= 1000, 1 <= T <= 50000) representing the size of the matrix and the number of the instructions. The following T lines each represents an instruction having the format "Q x y" or "C x1 y1 x2 y2", which has been described above.

Output

For each querying output one line, which has an integer representing A[x, y].

There is a blank line between every two continuous test cases.

Sample Input

1
2 10
C 2 1 2 2
Q 2 2
C 2 1 2 1
Q 1 1
C 1 1 2 1
C 1 2 1 2
C 1 1 2 2
Q 1 1
C 1 1 2 1
Q 2 1

Sample Output

1

0

0

1

题意:给一个0,1矩阵,有两种操作一种是把子矩阵进行非,一种是求子矩阵是否有1

题解:二维树状数组,用

add(x1,y1);
add(x1,y2+1);
add(x2+1,y1);
add(x2+1,y2+1);
求解时%2即可
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; int c[N][N]; void add(int x1,int y1)
{
for(int i=x1;i<N;i+=i&(-i))
for(int j=y1;j<N;j+=j&(-j))
c[i][j]++;
}
int sum(int x,int y)
{
int ans=;
for(int i=x;i>;i-=i&(-i))
for(int j=y;j>;j-=j&(-j))
ans+=c[i][j];
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
// cout<<setiosflags(ios::fixed)<<setprecision(2);
int n;
int t,k;
cin>>t;
while(t--){
cin>>n>>k;
memset(c,,sizeof c);
while(k--){
string s;
cin>>s;
if(s[]=='C')
{
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
add(x1,y1);
add(x1,y2+);
add(x2+,y1);
add(x2+,y2+);
}
else
{
int x,y;
cin>>x>>y;
cout<<sum(x,y)%<<endl;
}
}
cout<<endl;
}
return ;
}

poj2155二维树状数组的更多相关文章

  1. POJ2155(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17226   Accepted: 6461 Descripti ...

  2. poj2155二维树状数组区间更新

    垃圾poj又交不上题了,也不知道自己写的对不对 /* 给定一个矩阵,初始化为0:两种操作 第一种把一块子矩阵里的值翻转:0->1,1->0 第二种询问某个单元的值 直接累计单元格被覆盖的次 ...

  3. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  4. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

  5. 【POJ2155】【二维树状数组】Matrix

    Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...

  6. poj2155一个二维树状数组

                                                                                                         ...

  7. 【poj2155】Matrix(二维树状数组区间更新+单点查询)

    Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...

  8. POJ2155 Matrix(二维树状数组||区间修改单点查询)

    Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row an ...

  9. POJ2155/LNSYOJ113 Matrix【二维树状数组+差分】【做题报告】

    这道题是一个二维树状数组,思路十分神奇,其实还是挺水的 题目描述 给定一个N∗NN∗N的矩阵AA,其中矩阵中的元素只有0或者1,其中A[i,j]A[i,j]表示矩阵的第i行和第j列(1≤i,j≤N)( ...

随机推荐

  1. JavaScript当页面关闭时向后台发送请求

    今天做项目时遇上一个需求,当浏览器或页面关闭时将数据存储到数据库内.实现思想是采用js监测onunload然后发送请求.结果失败,刷新可以发送但是关闭并不能,整了一整天并没有解决,最后找到了解决办法. ...

  2. Eclipse配置Struts2.x

    问了我同学现在JavaWeb主流框架是哪些.他说基本框架是SSH,struts2+spring+hibernate,流行的是SSM,springmvc+spring+mybatis,原本计划学下Str ...

  3. python安装图文教程---超详细。。。不过是转的,但有改动

    如果你已安装好python,想安装第三方模块,方法详见如下地址: python安装第三方模块教程----marsggbo 1.想要安装Python,首先当然是去Python的官方网站(www.pyth ...

  4. [Oracle]同义词(synonym)

    (一)同义词的概念 同义词是数据库中表.视图.索引或其他模式对象的别名,与视图相似,同义词不占用实际的存储空间,在数据字典中只存同义词的定义. 在开发数据库时,应尽量避免直接引用表.视图或其他数据库对 ...

  5. 在React中使用CSS Modules设置样式

    最近,一直在看React...那真的是一个一直在学的过程啊,从配置环境webpack,到基础知识jsx,babel,es6,没有一个不是之前没有接触的.其实,我内心是兴奋的啊,毕竟,活着就是要接触一些 ...

  6. JDK中日期和时间的几个常用类浅析(五)

    LocalDateTime   LocalDateTime是JDK8中才引入的类,用来表示不包含时区信息的本地日期和时间.我们可以把LocalDateTime看作是LocalDate和LocalTim ...

  7. Python之路-操作系统&网络基础

    一.为何要有操作系统 没有操作系统的话,计算机同样可以运行,但是程序员要了解到计算机底层各种各样的细节,而操作系统聪明地封装起来了底层这些繁杂的操作,通过向程序员开放一个个的接口,来最终使我们实现对底 ...

  8. JavaWeb之Cookie和Session的区别

    Cookie和Session的区别 一.cookie机制和session机制的区别 ********************************************************** ...

  9. [原]C#与非托管——动机

    Unity3D采用C#作为脚本开发语言,本来是可以直接提供代码局部更新机制的,可惜Mono和Unity3D迫于苹果的压力,在iOS上采用AOT模式运行,断绝了代码局部更新的路(任何一个具有很高知名度的 ...

  10. 老李分享:《Linux Shell脚本攻略》 要点(八)

    老李分享:<Linux Shell脚本攻略> 要点(八)   1.打印进程 [root@localhost program_test]# ps -e | head  PID TTY     ...