Matrix
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 26650   Accepted: 9825

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

Source

POJ Monthly,Lou Tiancheng
题意:
一个n*n的矩阵初始每个元素值为0,左上角行列号最小,右下角行列号最大,两种操作:c x1 y1 x2 y2,将区间内的每个元素取非运算,Q x y表示询问xy点的值。
代码:
//可以画个图看一下,每次更新(x1,y1),(x2+1,y1),(x1,y2+1),(x2+1,y2+1)这4个点的值
//时所有的点都不会被影响。求每个点的sum(并不真实),奇数是1,偶数是0.
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=;
int A[maxn][maxn];
int cas,n,m,x1,x2,y1,y2;
int Lowbit(int x){
return x&(-x);
}
void Add(int x,int y,int val)
{
for(int i=x;i<=;i+=Lowbit(i)){
for(int j=y;j<=;j+=Lowbit(j)){
A[i][j]+=val;
}
}
}
int Query(int x,int y)
{
int s=;
for(int i=x;i>;i-=Lowbit(i)){
for(int j=y;j>;j-=Lowbit(j)){
s+=A[i][j];
}
}
return s;
}
int main()
{
scanf("%d",&cas);
while(cas--){
scanf("%d%d",&n,&m);
memset(A,,sizeof(A));
char ch[];
while(m--){
scanf("%s",ch);
if(ch[]=='C'){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
Add(x1,y1,);
Add(x1,y2+,);
Add(x2+,y2+,);
Add(x2+,y1,);
}
else{
scanf("%d%d",&x1,&y1);
int ans=Query(x1,y1);
//cout<<ans<<endl;
printf("%d\n",ans&);
}
}
printf("\n");
}
return ;
}

POJ2155 树状数组的更多相关文章

  1. poj2155 树状数组 Matrix

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 14826   Accepted: 5583 Descripti ...

  2. POJ-2155 Matrix---二维树状数组+区域更新单点查询

    题目链接: https://vjudge.net/problem/POJ-2155 题目大意: 给一个n*n的01矩阵,然后有两种操作(m次)C x1 y1 x2 y2是把这个小矩形内所有数字异或一遍 ...

  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二维树状数组

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

  7. poj2155一个二维树状数组

                                                                                                         ...

  8. POJ2155(二维树状数组)

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

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

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

随机推荐

  1. Maven编译Java项目

    Spring在线参考文档: http://spring.io/guides/gs/maven/ 下载安装 Downloadand unzip the source repository for thi ...

  2. 几个常见移动平台浏览器的User-Agent

    之前介绍的手机站跳转url的一片文稿中提到,依据User Agent判断终端的方法.(文章地址:http://www.cnblogs.com/dereksunok/p/3664169.html ) 若 ...

  3. python 文件编译成exe可执行文件。

    pyinstaller打包方法: pyinstaller安装参考地址:http://www.pyinstaller.org/ pywin32的下载地址:https://sourceforge.net/ ...

  4. Tunnel上传遇到字符[NUL]问题

    模拟生产环境下数据格式,再现异常情景:   Notepad++怎样输入字符[NUL]? 安装 Hex-Editor 插件: HexEditor插件用于在notepad++中查看16进制文件,只需要将此 ...

  5. day21 TFRecord格式转换MNIST并显示

    首先简要介绍了下TFRecord格式以及内部实现protobuf协议,然后基于TFRecord格式,对MNIST数据集转换成TFRecord格式,写入本地磁盘文件,再从磁盘文件读取,通过pyplot模 ...

  6. jQuery 调用后台方法(net)

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs ...

  7. POJ 1655 Balancing Act(求树的重心)

    Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any nod ...

  8. mysql数据库配置主从同步

    MySQL主从同步的作用 .可以作为一种备份机制,相当于热备份 .可以用来做读写分离,均衡数据库负载 MySQL主从同步的步骤 一.准备操作 .主从数据库版本一致,建议版本5.5以上 .主从数据库数据 ...

  9. 《JavaScript 高级程序设计》总结

    一.JS基本概念 1.命名规则 变量名区分大小写(test和Test是两个不同的变量名),标识符采用驼峰命名格式,即:第一个字母小写,剩下的每个有意义的单词首字母大写: 标识符第一个字符必须是以字母. ...

  10. # ML学习小笔记—Classification

    关于本课程的相关资料http://speech.ee.ntu.edu.tw/~tlkagk/courses_ML17.html 通过模型可以分类输入,此时根据分类结果的正确与否会有一个Loss函数.找 ...