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 ...
随机推荐
- dtd对xml没有起到约束作用
问题如题. dtd: xml: BUG很明显,但是xml并没有提示错误信息.xml文档校验设置正常. 此处原因: dtd中元素与子元素设置之间缺少空格: 加上空格后正常报错:
- 计算机网络系统--TCP/IP OSI模型
- 自己定义View实现水平滚动控件
前几天项目中须要使用到一个水平可滚动的选择条,类似下图效果(图片是从简书上一位作者那儿找来的,本篇也是在这位作者的文章的基础上改动的,站在大神的肩膀上,哈哈,因为原文没有提供demo,并且实现的效果跟 ...
- 积跬步,聚小流------java信息生成图片
需求: 是在做证书的时候碰到的这个问题. 当时需求是能够进行在线打印证书,第一次进行的操作是直接打印html,并且已经排好版(用jqprint插件)进行打印.在打印时碰到了兼容的问题,另外因为背景图片 ...
- 解决 Eclipse 导入项目后 Maven Dependencies missing jar 问题
转自:https://yq.aliyun.com/ziliao/314086 话不多说直接上图 上图是我通过git导入项目后, Maven Dependencies Library中很多包出现miss ...
- 关于HTML与CSS与class
在web前端开发中接触的一直是html.css.javascript. 在这个过程中,经常使用的是html中的span.div元素以及css的选择器. 为了方便查找在这里将这些内容的基础知识记录下来. ...
- POJ 1155 树形DP
题意:电视台发送信号给很多用户,每个用户有愿意出的钱,电视台经过的路线都有一定费用,求电视台不损失的情况下最多给多少用户发送信号. 转自:http://www.cnblogs.com/andre050 ...
- web前端页面优化——个人见解
web前端页面优化,我们从JavaScript.css.html这3个方面说下,我的见解,希望大神们能有刚好优化方法,一起探讨. 一. 有关javascript方面 优化见解. 1. 首先举个例子: ...
- pixhawk入门知识
Pixhawk是一种先进的自动驾驶仪,由PX4开放硬件项目设计和3D机器人制造.它具有来自ST公司先进的处理器和传感器技术,以及NuttX实时操作系统,能够实现惊人的性能,灵活性和可靠性控制任何自主飞 ...
- HTTP+XML接口客户端 结合策略模式实现总结
在项目中,我们经常会使用到http+xml的接口,而且不仅仅的是一个,可能会有多个http的接口需要实时的交互.但是http接口的发送消息的公共部分是一样的,只有每个接口的报文解析和返回报文是不同的, ...