Pagini recente » Cod sursa (job #2804650) | Cod sursa (job #1054397) | Cod sursa (job #2571756) | Cod sursa (job #153142) | Cod sursa (job #1420549)
program hashuri;
const modd=666013;
type
lista=^date;
date=record
m:longint;
next:lista;
end;
vector1=array[0..modd+1] of lista;
buf=array[0..1000001] of char;
var hash:vector1; ff1,ff2:buf;
n,i,tip,x:longint;
f1,f2:text;
function inhash(x,y:longint):boolean;
var a:lista;
begin
a:=hash[y];
while a<>nil do begin
if a^.m=x then exit(true);
a:=a^.next;
end;
exit(false);
end;
procedure add_hash(x:longint);
var xx:longint; a:lista;
begin
if x>=modd then xx:=x mod modd else xx:=x;
if not inhash(x,xx) then begin
new(a); a^.m:=x; a^.next:=hash[xx]; hash[xx]:=a;
end;
end;
procedure delete_hash(x:longint);
var xx:longint; a:lista;
begin
if x>=modd then xx:=x mod modd else xx:=x;
a:=hash[xx];
if a<>nil then begin
if a^.m=x then hash[xx]:=hash[xx]^.next else begin
while (a^.next<>nil) and (a^.next^.m<>x) do a:=a^.next;
a^.next:=a^.next^.next;
end; end;
end;
begin
assign (f1,'hashuri.in');
assign (f2,'hashuri.out');
reset (f1);
rewrite (f2);
settextbuf(f1,ff1);
settextbuf(f2,ff2);
readln (f1,n);
for i:=1 to n do begin
readln (f1,tip,x);
if tip=1 then add_hash(x) else
if tip=2 then delete_hash(x) else
if inhash(x,x mod modd) then writeln (f2,1) else writeln (f2,0);
end;
close (f1);
close (f2);
end.