Matrix
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 33682   Accepted: 12194

Description

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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string> using namespace std;
const int N=1e3+;
int s[N][N];
int n;
int lowbit(int x)
{
return x&(-x);
}
void updata(int x,int y,int z)
{
for(int i=x;i<=n;i+=lowbit(i)){
for(int j=y;j<=n;j+=lowbit(j)){
s[i][j]+=z;
}
}
} int sum(int x,int y)
{
int res=;
for(int i=x;i>;i-=lowbit(i)){
for(int j=y;j>;j-=lowbit(j)){
res+=s[i][j];
}
}
return res;
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
memset(s,,sizeof(s));
int m;
scanf("%d %d",&n,&m);
while(m--){
char t[];
scanf("%s",t);
if(t[]=='C'){
int x1,y1,x2,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
updata(x1,y1,);
updata(x2+,y2+,);
updata(x2+,y1,-);
updata(x1,y2+,-);
}
else{
int x,y;
scanf("%d %d",&x,&y);
printf("%d\n",sum(x,y)%);
}
}
if(T) printf("\n");
} return ;
}

poj 2155 (二维树状数组 区间修改 求某点值)的更多相关文章

  1. 【bzoj5173】[Jsoi2014]矩形并 扫描线+二维树状数组区间修改区间查询

    题目描述 JYY有N个平面坐标系中的矩形.每一个矩形的底边都平行于X轴,侧边平行于Y轴.第i个矩形的左下角坐标为(Xi,Yi),底边长为Ai,侧边长为Bi.现在JYY打算从这N个矩形中,随机选出两个不 ...

  2. 【bzoj3132】上帝造题的七分钟 二维树状数组区间修改区间查询

    题目描述 “第一分钟,X说,要有矩阵,于是便有了一个里面写满了0的n×m矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为(a,b),右下角为(c,d)的一个矩形区域内的全部数字加上一个值的操作. ...

  3. 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 ...

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

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

  5. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

  6. 牛客网 暑期ACM多校训练营(第二场)J.farm-STL(vector)+二维树状数组区间更新、单点查询 or 大暴力?

    开心.jpg J.farm 先解释一下题意,题意就是一个n*m的矩形区域,每个点代表一个植物,然后不同的植物对应不同的适合的肥料k,如果植物被撒上不适合的肥料就会死掉.然后题目将每个点适合的肥料种类( ...

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

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

  8. POJ 1195 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18489   Accepted: 8558 De ...

  9. poj 2029 二维树状数组

    思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...

随机推荐

  1. Knowledge Point 20180308 拔下forEach的外衣

    剖析加强for 很长一段时间对于foreach都有一种误解,那就是foreach只是普通for的包装,底层还是普通for循环,直到深入了解迭代器的时候,才发现自己错了,本节就来探讨一下foreach, ...

  2. iOS | 解决中文乱码

    在iOS开发中,多多少少的朋友在开发的过程中,测试数据的时候可能会碰到后台打印的时候不能正确的打印出正常的汉字,打印出一些影响判断的字符,经常需要查看数组中得元素是否是自己想要的,但是苹果并没有对直接 ...

  3. 第一个electron

    1 开发环境:node环境 2 下载electron:npm install electron --save-dev 3 package.json配置如下: { "name": & ...

  4. thinkphp5配置讲解

    一.thinkphp配置类型有哪些? 1.在thinkphp中,有6种配置.即惯例配置,应用配置.扩展配置.模块配置.场景配置.动态配置. 2.惯例配置就是系统默认的配置. 3.应用配置就是我们自己开 ...

  5. PHP DES加密解密

    自定义密码加密解密函数,源自网友,记录保存一下. <?php /** * DES加密解密 */ class Mcrypt{ public function __construct(){} fun ...

  6. mac安装ruby-oci8

    1.安装xcode 2.从oracle官网下载以下安装包 instantclient-basic-macos.x64-12.1.0.2.0.zip instantclient-sdk-macos.x6 ...

  7. C语言#ifdef等宏的妙用

    这几个宏是为了进行条件编译.一般情况下,源程序中所有的行都参加编译.但是有时希望对其中一部分内容只在满足一定条件才进行编译,也就是对一部分内容指定编译的条件,这就是“条件编译”.有时,希望当满足某条件 ...

  8. vuetify.js框架 下拉框数据改变DOM原数据未清除

    今天遇到一个奇怪的bug 需求很简单,就是将“引擎能力”下拉框选中的值作为筛选条件传入到“样本类型”下拉框中,默认“样本类型”下拉框显示所有样本类型 看图: 如图所示,功能很简单. 其实还是对vuet ...

  9. 成都优步uber司机第五组奖励政策

    7月14日,成都优步uber团队发布了第五组用户分组.在传言要推出第四组的时候,心想事不过三吧,意外,现在第五组都出来了.一起看看成都优步司机第五组的详细内容!滴滴快车单单2.5倍,注册地址:http ...

  10. 北京Uber优步司机奖励政策(10月26日~11月1日)

    用户组:优步北京人民优步A组(适用于10月26日-11月1日) 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/ ...