Pagini recente » Cod sursa (job #370863) | Cod sursa (job #1794336) | Cod sursa (job #1690849) | Cod sursa (job #1997872) | Cod sursa (job #342471)
Cod sursa(job #342471)
Program Hashuri;
const nb = 666013;
lf = 4000;
type list = ^cell;
cell = record no:0..lf; ne:list; end;
var f,g:text; hash:array[0..nb-1 ]of list;
i,j,k,n:longint; p:list;
procedure add (x:longint);
var y:longint; z:0..lf;
begin
y:=x mod nb;
z:=x div nb;
if hash[y]=nil then begin
new (hash[y]);
hash[y]^.no:=z;
end else begin
p:=hash[y];
while (p^.ne<>nil) and (p^.no<>z) do p:=p^.ne;
if p^.no<>z then begin
new (p^.ne);
p^.ne^.no:=z;
end;
end;
end;
procedure del (x:longint);
var y:longint; z:0..lf;
begin
y:=x mod nb;
z:=x div nb;
if hash[y]<>nil then if hash[y]^.no=z then hash[y]:=hash[y]^.ne else begin
p:=hash[y];
while (p^.ne<>nil) and (p^.ne^.no<>z) do p:=p^.ne;
if p^.ne<>nil then p^.ne:=p^.ne^.ne;
end;
end;
procedure check (x:longint);
var y:longint; z:0..lf;
begin
y:=x mod nb;
z:=x div nb;
if hash[y]<>nil then
if hash[y]^.no=z then writeln (g,1) else begin
p:=hash[y];
while (p^.ne<>nil) and (p^.ne^.no<>z) do p:=p^.ne;
if p^.ne<>nil then writeln (g,1) else writeln (g,0);
end
else writeln (g,0);
end;
begin
assign (f,'hashuri.in'); reset (f);
assign (g,'hashuri.out'); rewrite (g);
readln (f,n);
for i:=1 to n do begin
readln (f,j,k);
case j of
1: add (k);
2: del (k);
3: check (k);
end;
end;
close (f); close (g);
end.