Pagini recente » Cod sursa (job #1680963) | Cod sursa (job #2184840) | Cod sursa (job #1041246) | Cod sursa (job #722521) | Cod sursa (job #410053)
Cod sursa(job #410053)
{DINH QUANG DAT TIN 07-10}
{HASHURI}
{$inline on}
{$mode objfpc}
CONST
TFI='hashuri.in';
TFO='hashuri.out';
MAX=1000000;
e=301013;
TYPE
arr1int=array[0..MAX] of longint;
VAR
fi,fo:text;
i,m,n,x,task:longint;
next,f:array[0..MAX] of longint;
last,head:array[0..e] of longint;
PROCEDURE add;inline;
var
u,v:longint;
begin
u:=x mod e;
if head[u]=0 then
begin
inc(m);
f[m]:=x;
next[last[u]]:=m;
last[u]:=m;
head[u]:=m;
end
else
begin
v:=head[u];
while v<>0 do
begin
if f[v]=x then exit;
v:=next[v];
end;
inc(m);
f[m]:=x;
next[last[u]]:=m;
last[u]:=m;
end;
end;
PROCEDURE del;inline;
var
u,v,i:longint;
begin
u:=x mod e;
if head[u]=0 then exit;
v:=head[u];
i:=0;
while v<>0 do
begin
if f[v]=x then
begin
if head[u]=v then head[u]:=next[v];
if last[u]=v then last[u]:=i;
next[i]:=next[v];
exit;
end;
i:=v;
v:=next[v];
end;
end;
PROCEDURE find;inline;
var
u,v:longint;
begin
u:= x mod e;
if head[u]=0 then
begin
writeln(fo,0);
exit;
end;
v:=head[u];
while v<>0 do
begin
if f[v]=x then
begin
writeln(fo,1);
exit;
end;
v:=next[v];
end;
writeln(fo,0);
end;
BEGIN
assign(fi,tfi);reset(fi);
assign(fo,tfo);rewrite(fo);
read(fi,n);
m:=0;
for i:= 1 to n do
begin
read(fi,task,x);
case task of
1: add;
2: del;
3: find;
end;
end;
close(fo);
close(fi);
END.