1018: [SHOI2008]堵塞的交通traffic - BZOJ
Description
有一天,由于某种穿越现象作用,你来到了传说中的小人国。小人国的布局非常奇特,整个国家的交通系统可以被看成是一个2行C列的矩形网格,网格上的每个点代表一个城市,相邻的城市之间有一条道路,所以总共有2C个城市和3C-2条道路。 小人国的交通状况非常槽糕。有的时候由于交通堵塞,两座城市之间的道路会变得不连通,直到拥堵解决,道路才会恢复畅通。初来咋到的你决心毛遂自荐到交通部某份差事,部长听说你来自一个科技高度发达的世界,喜出望外地要求你编写一个查询应答系统,以挽救已经病入膏肓的小人国交通系统。 小人国的交通部将提供一些交通信息给你,你的任务是根据当前的交通情况回答查询的问题。交通信息可以分为以下几种格式: Close r1 c1 r2 c2:相邻的两座城市(r1,c1)和(r2,c2)之间的道路被堵塞了; Open r1 c1 r2 c2:相邻的两座城市(r1,c1)和(r2,c2)之间的道路被疏通了; Ask r1 c1 r2 c2:询问城市(r1,c1)和(r2,c2)是否连通。如果存在一条路径使得这两条城市连通,则返回Y,否则返回N;
Input
第一行只有一个整数C,表示网格的列数。接下来若干行,每行为一条交通信息,以单独的一行“Exit”作为结束。我们假设在一开始所有的道路都是堵塞的。 对30%测试数据,我们保证C小于等于1000,信息条数小于等于1000; 对100%测试数据,我们保证 C小于等于100000,信息条数小于等于100000。
Output
对于每个查询,输出一个“Y”或“N”。
Sample Input
2
Open 1 1 1 2
Open 1 2 2 2
Ask 1 1 2 2
Ask 2 1 2 2
Exit
Sample Output
Y
N
又见恶心题
用线段树维护这一个区间四个角的连通性,这个满足区间可加性
特殊情况:询问的两个点不一定是从中间联通,它可能从外面绕一个大弯子
所以还要检查一下(1,c1)和(c2,C)的连通性
今天上午终于准备写这道恶心题了,果然恶心
无语了....最后这个错误真奇葩,虽然已经是第二次了
因为这个字符串只有4种情况,很多人应该都是判三个然后最后一个放在最后那个else那里
可是我在最后在最后那个else那里加了一句if s='A' then就神奇的从WA变成了AC(这是什么奇葩原因啊)
type
aa=array[..]of boolean;
node=record
lson,rson,left,right:longint;
flag:aa;
end;
const
maxn=;
var
tree:array[..maxn*]of node;
n,tot,x1,y1,x2,y2,ll,rr:longint;
ans,save,k1,k2:aa;
s:char; procedure swap(var x,y:longint);
var
t:longint;
begin
t:=x;x:=y;y:=t;
end; procedure build(l,r:longint);
var
mid,now:longint;
begin
inc(tot);
now:=tot;
with tree[now] do
begin
left:=l;
right:=r;
if l=r then
begin
flag[]:=true;
flag[]:=true;
exit;
end;
end;
mid:=(l+r)>>;
with tree[now] do
begin
lson:=tot+;
build(l,mid);
rson:=tot+;
build(mid+,r);
end;
end; procedure update(var a,b,c:aa);
begin
fillchar(save,sizeof(save),false);
save[]:=c[];
save[]:=c[];
if (b[] and b[] and c[])or(b[] and b[] and c[]) then save[]:=true;
if b[] or (b[] and b[] and c[] and b[] and b[]) then save[]:=true;
if (b[] and b[] and c[])or(b[] and b[] and c[]) then save[]:=true;
if c[] or (c[] and b[] and b[] and b[] and c[]) then save[]:=true;
if (b[] and b[] and c[])or(b[] and b[] and c[]) then save[]:=true;
if (b[] and b[] and c[])or(b[] and b[] and c[]) then save[]:=true;
a:=save;
end; procedure change(now:longint);
var
mid:longint;
begin
with tree[now] do
begin
if left=right then
begin
if y1=y2 then
begin
flag[]:=s='n';
flag[]:=s='n';
flag[]:=s='n';
flag[]:=s='n';
end
else flag[x1+]:=s='n';
exit;
end;
mid:=(left+right)>>;
if y1<=mid then change(lson)
else change(rson);
update(flag,tree[lson].flag,tree[rson].flag);
end;
end; procedure dfs(now:longint);
var
mid:longint;
begin
with tree[now] do
begin
if (left=ll)and(right<=rr) then
begin
ans:=flag;
exit;
end;
if (left>=ll)and(right<=rr) then
begin
update(ans,ans,flag);
exit;
end;
mid:=(left+right)>>;
if ll<=mid then dfs(lson);
if rr>mid then dfs(rson);
end;
end; procedure work;
var
i:longint;
begin
read(s);
if s='E' then halt;
if s='O' then
begin
for i:= to do
read(s);
readln(x1,y1,x2,y2);
if y1>y2 then
begin
swap(x1,x2);
swap(y1,y2);
end;
change();
end
else
if s='C' then
begin
for i:= to do
read(s);
readln(x1,y1,x2,y2);
if y1>y2 then
begin
swap(x1,x2);
swap(y1,y2);
end;
change();
end
else
if s='A' then
begin
for i:= to do
read(s);
readln(x1,y1,x2,y2);
if y1>y2 then
begin
swap(x1,x2);
swap(y1,y2);
end;
ll:=;
rr:=y1;
dfs();
k1:=ans;
ll:=y2;
rr:=n;
dfs();
k2:=ans;
ll:=y1;
rr:=y2;
dfs();
if k1[] then
begin
fillchar(k1,sizeof(k1),true);
update(ans,k1,ans);
end;
if k2[] then
begin
fillchar(k2,sizeof(k2),true);
ans[]:=true;
ans[]:=true;
update(ans,ans,k2);
end;
if x1= then
if x2= then
begin
if ans[] then writeln('Y')
else writeln('N');
end
else
begin
if ans[] then writeln('Y')
else writeln('N');
end
else
if x2= then
begin
if ans[] then writeln('Y')
else writeln('N');
end
else
begin
if ans[] then writeln('Y')
else writeln('N');
end;
end;
end; begin
readln(n);
build(,n);
while true do
work;
end.
1018: [SHOI2008]堵塞的交通traffic - BZOJ的更多相关文章
- 数据结构(线段树):BZOJ 1018: [SHOI2008]堵塞的交通traffic
1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 2638 Solved: 864 Descri ...
- BZOJ 1018 [SHOI2008]堵塞的交通traffic
1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 2247 Solved: 706[Submit ...
- BZOJ 1018: [SHOI2008]堵塞的交通traffic [线段树 区间信息]
1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 3064 Solved: 1027[Submi ...
- 1018: [SHOI2008]堵塞的交通traffic
1018: [SHOI2008]堵塞的交通traffic 链接 分析: 用线段树维护区间的四个端点的联通情况,然后查询的时候,把所有覆盖到的区间合并起来即可. 六种情况左上到右上(左边到右边的情况)… ...
- [BZOJ 1018] [SHOI2008] 堵塞的交通traffic 【线段树维护联通性】
题目链接:BZOJ - 1018 题目分析 这道题就说明了刷题少,比赛就容易跪..SDOI Round1 Day2 T3 就是与这道题类似的..然而我并没有做过这道题.. 这道题是线段树维护联通性的经 ...
- 【BZOJ】1018: [SHOI2008]堵塞的交通traffic
http://www.lydsy.com/JudgeOnline/problem.php?id=1018 题意:有2行,每行有c(c<=100000)个城市,则一共有c-1个格子,现在有q(q& ...
- BZOJ 1018: [SHOI2008]堵塞的交通traffic(线段树)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1018 用线段树维护区间连通性,对于每一个区间记录6个域表示(左上,左下)(左上,右上)(右上, ...
- BZOJ 1018: [SHOI2008]堵塞的交通traffic(线段树分治+并查集)
传送门 解题思路 可以离线,然后确定每个边的出现时间,算这个排序即可.然后就可以线段树分治了,连通性用并查集维护,因为要撤销,所以要按秩合并,时间复杂度\(O(nlog^2 n)\) 代码 #incl ...
- bzoj千题计划108:bzoj1018: [SHOI2008]堵塞的交通traffic
http://www.lydsy.com/JudgeOnline/problem.php?id=1018 关键点在于只有两行 所以一个2*m矩形连通情况只有6种 编号即对应代码中的a数组 线段树维护 ...
随机推荐
- Java Concurrency - Concurrent Collections
Data structures are a basic element in programming. Almost every program uses one or more types of d ...
- HttpClient(4.3.5) - HttpClient Proxy Configuration
Even though HttpClient is aware of complex routing scemes and proxy chaining, it supports only simpl ...
- Objective-C中一个方法如何传递多个参数的理解
原来如此 Objective-C语法中多参数传递方法经常是初学者最容易犯困的地方.我自己也是刚刚悟出来与大家分享. 分析 由于我们已有的语言经验告诉我们定义方法都是: 一个类型匹配一个参数(动态语言甚 ...
- Eclipse 调试maven test
在eclipse中调试maven test 一般情况下,使用如下方式都不能使myeclipse检测到程序中的断点: 项目 -> Run As -> maven test 或 项目 -> ...
- CCM加密学习
这几天终于搞定了AES硬件加密工具的使用,几种简单的加密模式也都实验通过了,比较麻烦的一种是CCM模式的加密,它是CTR加密模式和CMAC认证算法的混合使用.本文先介绍CCM模式的原理与基本实现,然后 ...
- WSAEventSelect模型详解
WSAEventSelect 是 WinSock 提供的一种异步事件通知I/O模型,与 WSAAsyncSelect模型有些类似. 该模型同样是接收 FD_XXX 之类的网络事件,但是是通 ...
- HTML5之 Microdata微数据
- 为何需要微数据 长篇加累版牍,不好理解 微标记来标注其中内容,让其容易识辨 - RDFa Resource Description Framework http://www.w3.org/TR/m ...
- 【ASP.NET+MVC4+Web+编程】读书笔记
模型:数据和业务逻辑 视图:展示 控制器:接收视图输入数据,通过模型层业务逻辑处理后 返回给视图 分离关注点(模型 视图 控制器).惯例优先原则 browser-->routing-->c ...
- C# 学习之旅(1)
第一, 输入输出流都来自控制台. using System; using System.Collections.Generic; using System.Linq; using System.Tex ...
- scrapy-redis使用详解
描述: 1.使用两台机器,一台是win10,一台是centos7,分别在两台机器上部署scrapy来进行分布式抓取一个网站 2.centos7的ip地址为192.168.1.112,用来作为redis ...