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(这是什么奇葩原因啊)

 

  1 type
  2     aa=array[1..8]of boolean;
  3     node=record
  4       lson,rson,left,right:longint;
  5       flag:aa;
  6     end;
  7 const
  8     maxn=200010;
  9 var
 10     tree:array[0..maxn*2]of node;
 11     n,tot,x1,y1,x2,y2,ll,rr:longint;
 12     ans,save,k1,k2:aa;
 13     s:char;
 14  
 15 procedure swap(var x,y:longint);
 16 var
 17     t:longint;
 18 begin
 19     t:=x;x:=y;y:=t;
 20 end;
 21  
 22 procedure build(l,r:longint);
 23 var
 24     mid,now:longint;
 25 begin
 26     inc(tot);
 27     now:=tot;
 28     with tree[now] do
 29       begin
 30         left:=l;
 31         right:=r;
 32         if l=r then
 33         begin
 34           flag[1]:=true;
 35           flag[3]:=true;
 36           exit;
 37         end;
 38       end;
 39     mid:=(l+r)>>1;
 40     with tree[now] do
 41       begin
 42         lson:=tot+1;
 43         build(l,mid);
 44         rson:=tot+1;
 45         build(mid+1,r);
 46       end;
 47 end;
 48  
 49 procedure update(var a,b,c:aa);
 50 begin
 51     fillchar(save,sizeof(save),false);
 52     save[7]:=c[7];
 53     save[8]:=c[8];
 54     if (b[1] and b[7] and c[1])or(b[5] and b[8] and c[6]) then save[1]:=true;
 55     if b[2] or (b[1] and b[7] and c[2] and b[8] and b[3]) then save[2]:=true;
 56     if (b[3] and b[8] and c[3])or(b[6] and b[7] and c[5]) then save[3]:=true;
 57     if c[4] or (c[1] and b[7] and b[4] and b[8] and c[3]) then save[4]:=true;
 58     if (b[1] and b[7] and c[5])or(b[5] and b[8] and c[3]) then save[5]:=true;
 59     if (b[3] and b[8] and c[6])or(b[6] and b[7] and c[1]) then save[6]:=true;
 60     a:=save;
 61 end;
 62  
 63 procedure change(now:longint);
 64 var
 65     mid:longint;
 66 begin
 67     with tree[now] do
 68       begin
 69         if left=right then
 70         begin
 71           if y1=y2 then
 72           begin
 73             flag[2]:=s='n';
 74             flag[4]:=s='n';
 75             flag[5]:=s='n';
 76             flag[6]:=s='n';
 77           end
 78           else flag[x1+6]:=s='n';
 79           exit;
 80         end;
 81         mid:=(left+right)>>1;
 82         if y1<=mid then change(lson)
 83         else change(rson);
 84         update(flag,tree[lson].flag,tree[rson].flag);
 85       end;
 86 end;
 87  
 88 procedure dfs(now:longint);
 89 var
 90     mid:longint;
 91 begin
 92     with tree[now] do
 93       begin
 94         if (left=ll)and(right<=rr) then
 95         begin
 96           ans:=flag;
 97           exit;
 98         end;
 99         if (left>=ll)and(right<=rr) then
100         begin
101           update(ans,ans,flag);
102           exit;
103         end;
104         mid:=(left+right)>>1;
105         if ll<=mid then dfs(lson);
106         if rr>mid then dfs(rson);
107       end;
108 end;
109  
110 procedure work;
111 var
112     i:longint;
113 begin
114     read(s);
115     if s='E' then halt;
116     if s='O' then
117     begin
118       for i:=1 to 3 do
119         read(s);
120       readln(x1,y1,x2,y2);
121       if y1>y2 then
122       begin
123         swap(x1,x2);
124         swap(y1,y2);
125       end;
126       change(1);
127     end
128       else
129         if s='C' then
130         begin
131           for i:=1 to 4 do
132             read(s);
133           readln(x1,y1,x2,y2);
134           if y1>y2 then
135           begin
136             swap(x1,x2);
137             swap(y1,y2);
138           end;
139           change(1);
140         end
141         else
142           if s='A' then
143           begin
144             for i:=1 to 2 do
145               read(s);
146             readln(x1,y1,x2,y2);
147             if y1>y2 then
148             begin
149               swap(x1,x2);
150               swap(y1,y2);
151             end;
152             ll:=1;
153             rr:=y1;
154             dfs(1);
155             k1:=ans;
156             ll:=y2;
157             rr:=n;
158             dfs(1);
159             k2:=ans;
160             ll:=y1;
161             rr:=y2;
162             dfs(1);
163             if k1[4] then
164             begin
165               fillchar(k1,sizeof(k1),true);
166               update(ans,k1,ans);
167             end;
168             if k2[2] then
169             begin
170               fillchar(k2,sizeof(k2),true);
171               ans[7]:=true;
172               ans[8]:=true;
173               update(ans,ans,k2);
174             end;
175             if x1=1 then
176               if x2=1 then
177               begin
178                 if ans[1] then writeln('Y')
179                 else writeln('N');
180               end
181               else
182                 begin
183                   if ans[5] then writeln('Y')
184                   else writeln('N');
185                 end
186             else
187               if x2=1 then
188               begin
189                 if ans[6] then writeln('Y')
190                 else writeln('N');
191               end
192               else
193                 begin
194                   if ans[3] then writeln('Y')
195                   else writeln('N');
196                 end;
197           end;
198 end;
199  
200 begin
201     readln(n);
202     build(1,n);
203     while true do
204       work;
205 end.
View Code

 

转载于:https://www.cnblogs.com/Randolph87/p/3615886.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值