比赛 |
10.10.18noip模拟 |
评测结果 |
WWWTTTTTTT |
题目名称 |
罪犯问题D |
最终得分 |
0 |
用户昵称 |
maxiem |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-10-18 21:30:48 |
显示代码纯文本
program criminald;
var
cf:array [1..50000] of integer;
s:array [1..400000] of record
a,b:longint;
end;
ta,tb,code,tmp,sn,i,n,m,a,b:longint;
st:string;
flag:boolean;
procedure check;
var
sa,sb,ta,tb,i:longint;
flag:boolean;
begin
repeat
flag:=false;
for i:=1 to sn do begin
ta:=abs(s[i].a);tb:=abs(s[i].b);
sa:=abs(a);sb:=abs(b);
if (ta=sa) or (ta=sb) then begin
if (cf[ta]<>-1) and (cf[tb]=-1) then begin
flag:=true;
if cf[ta]=1 then tb:=-s[i].b else tb:=s[i].b;
if tb>0 then cf[tb]:=1 else cf[-tb]:=0;
end;
end
else if (tb=sa) or (tb=sb) then begin
if (cf[tb]<>-1) and (cf[ta]=-1) then begin
flag:=true;
if (cf[tb]=1) and (s[i].a>0) then cf[ta]:=0;
if (cf[tb]=1) and (s[i].a<0) then cf[ta]:=1;
if (cf[tb]=0) and (s[i].a>0) then cf[ta]:=1;
if (cf[tb]=0) and (s[i].a<0) then cf[ta]:=0;
end;
end;
end;
until flag=false;
end;
begin
sn:=0;
fillchar (cf,sizeof(cf),$FF);
assign (input,'criminald.in');
reset (input);
readln (n,m);
for i:=1 to m do begin
read (tmp);
cf[tmp]:=1;
end;
readln;
assign (output,'criminald.out');
rewrite (output);
readln (st);
while st[1]<>'E' do begin
case st[1] of
'A':begin
delete (st,1,2);
val (st,a,code);
if cf[a]=1 then writeln ('Yes') else if cf[a]=0 then writeln ('No') else writeln ('Unknown');
end;
'S':begin
delete (st,1,2);
val(copy(st,1,pos(' ',st)-1),a,code);
val(copy(st,pos(' ',st)+1,length(s)-pos(' ',st)),b,code);
flag:=false;
ta:=abs(a);tb:=abs(b);
if (cf[ta]<>-1) and (cf[tb]=-1) then begin
flag:=true;
if cf[ta]=1 then b:=-b;
if b>0 then cf[tb]:=1 else cf[tb]:=0;
end;
if (cf[tb]<>-1) and (cf[ta]=-1) then begin
flag:=true;
if (cf[tb]=1) and (a>0) then cf[ta]:=0;
if (cf[tb]=1) and (a<0) then cf[ta]:=1;
if (cf[tb]=0) and (a>0) then cf[ta]:=1;
if (cf[tb]=0) and (a<0) then cf[ta]:=0;
end;
if flag=false then begin
inc(sn);
s[sn].a:=a;
s[sn].b:=b;
end
else check;
end;
end;
readln(st);
end;
close (input);
close (output);
end.