HDU 2155 Matrix
Matrix
This problem will be judged on PKU. Original ID: 2155
64-bit integer IO format: %lld Java class name: Main
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 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
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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct subtree{
int lt,rt;
bool val;
};
struct node{
int lt,rt;
subtree sb[maxn<<];
};
node tree[maxn<<];
int n,m,ans;
void sub(int lt,int rt,int v,subtree *sb){
sb[v].lt = lt;
sb[v].rt = rt;
sb[v].val = false;
if(lt == rt) return;
int mid = (lt + rt)>>;
sub(lt,mid,v<<,sb);
sub(mid+,rt,v<<|,sb);
}
void build(int lt,int rt,int v){
tree[v].lt = lt;
tree[v].rt = rt;
sub(,n,,tree[v].sb);
if(lt == rt) return;
int mid = (lt + rt)>>;
build(lt,mid,v<<);
build(mid+,rt,v<<|);
}
void subupdate(int lt,int rt,int v,subtree *sb){
if(sb[v].lt >= lt && sb[v].rt <= rt){
sb[v].val ^= ;
return;
}
if(lt <= tree[v<<].rt) subupdate(lt,rt,v<<,sb);
if(rt >= tree[v<<|].lt) subupdate(lt,rt,v<<|,sb);
}
void update(int lt,int rt,int y1,int y2,int v){
if(tree[v].lt >= lt && tree[v].rt <= rt){
subupdate(y1,y2,,tree[v].sb);
return;
}
if(lt <= tree[v<<].rt) update(lt,rt,y1,y2,v<<);
if(rt >= tree[v<<|].lt) update(lt,rt,y1,y2,v<<|); }
void subquery(int y,int v,subtree *sb){
ans ^= sb[v].val;
if(sb[v].lt == sb[v].rt) return;
if(y <= sb[v<<].rt) subquery(y,v<<,sb);
else subquery(y,v<<|,sb);
}
void query(int x,int y,int v){
subquery(y,,tree[v].sb);
if(tree[v].lt == tree[v].rt) return;
if(x <= tree[v<<].rt) query(x,y,v<<);
else query(x,y,v<<|);
}
int main(){
int t,x1,y1,x2,y2;
char s[];
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
build(,n,);
for(int i = ; i < m; ++i){
scanf("%s",s);
if(s[] == 'Q'){
ans = ;
scanf("%d %d",&x1,&y1);
query(x1,y1,);
printf("%d\n",ans);
}else if(s[] == 'C'){
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
update(x1,x2,y1,y2,);
}
}
puts("");
}
return ;
}
HDU 2155 Matrix的更多相关文章
- POJ 2155 Matrix (D区段树)
http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 1 ...
- POJ poj 2155 Matrix
题目链接[http://poj.org/problem?id=2155] /* poj 2155 Matrix 题意:矩阵加减,单点求和 二维线段树,矩阵加减,单点求和. */ using names ...
- POJ 2155 Matrix【二维树状数组+YY(区间计数)】
题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- HDU 4920 Matrix multiplication(bitset)
HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...
- HDU 2686 Matrix 3376 Matrix Again(费用流)
HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...
- hdu 2686 Matrix 最小费用最大流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...
- hdu 5569 matrix dp
matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5569 D ...
- hdu 2119 Matrix(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119 Matrix Time Limit: 5000/1000 MS (Java/Others) ...
- HDU 5671 Matrix 水题
Matrix 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5671 Description There is a matrix M that has ...
随机推荐
- ie固定table单元格宽度
<table border="0" style="width:690px; table-layout:fixed;"> <tr> < ...
- nodejs-基础大杂烩(待整理)
优点:安装简易,能自动配置环境变量 缺点:更新和更换版本需重新安装(这个可以用包管理器解决,不是问题) 高手推荐使用开源的NVM包管理器来更新和安装node,可能这个包在linux平台上比较好用吧 g ...
- 【Web API系列教程】3.4 — 实战:处理数据(处理实体关系)
前言 本部分描写叙述了EF怎样载入相关实体的细节,而且怎样在你的模型类中处理环形导航属性.(本部分预备了背景知识,而这不是完毕这个教程所必须的.你也能够跳到第五节) 预载入和延迟载入 预载入和延迟载入 ...
- “System.IO.FileNotFoundException”类型的未经处理的异常在 mscorlib.dll 中发生
这个错误是我在打包的时候.发现的,由于我移动了我的project的位置(从C盘移动到了D盘),看一下出错的代码: Dim strDB As String = System.Configuration. ...
- JavaScript 获取小数任一小数点后的位数的小数
用Javascript取float型小数点后两位,例22.127456取成22.13,怎样做? 1.这样的方法最不推荐: function get(){ var s = 22.127456 + &qu ...
- Node.js:连接 MySQL
ylbtech-Node.js:连接 MySQL 1.返回顶部 1. Node.js 连接 MySQL 本章节我们将为大家介绍如何使用 Node.js 来连接 MySQL,并对数据库进行操作. 如果你 ...
- Centos6.5添加Epel和Remi源安装Lamp环境
想搭建一个Lamp环境,因为编译安装太麻烦,对于我这样的新手来说,太过于复杂.而CentOS自带的Apache.MySql和PHP的版本都太低,不想用.上百度搜了一轮,原来可以通过添加Epel和Rem ...
- APNs推送
消息推送是可以指定声音的.譬如你可以对正面的反馈使用欢快的声音,对负面的反馈使用低沉一点的声音,都可以达到别出心裁让人眼前一亮的目的.你需要先放一些aiff.wav或者caf音频文件到app的资源文件 ...
- ROS集成开发环境RoboWare Studio安装教程
前言:很多人说vim是最快的,所以我选择用roboware. ROS 自带的编辑器vim增加插件,效果如下: RoboWare Studio,效果如下: 下面开始安装. 一.安装 去官网 http:/ ...
- hadoop配置历史服务器
此文档不建议当教程,仅供参考 配置历史服务器 我是在hadoop1机器上配置的 配置mapred-site.xml <property> <name>mapreduce.job ...