Cod sursa(job #1180263)
Utilizator | Data | 30 aprilie 2014 12:41:57 | |
---|---|---|---|
Problema | Hashuri | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 2.78 kb |
Program hashuri;
const prim=900001;
type lista=^cell;
cell= record
info:longint;
pred:lista;
end;
var t,n,i,a,b,ok: longint;
lhash : array [0..900001] of lista;
bin,bout : array [0..1 shl 17 ] of char;
v,r,p:lista;
procedure add(nr : longint);
var r : lista;
begin
new(r);
r^.info:=nr;
r^.pred:=lhash[b mod prim];
lhash[b mod prim]:=r;
end;
begin
assign(input,'hashuri.in'); settextbuf(input,bin); reset(input);
assign(output,'hashuri.out'); settextbuf(output,bout); rewrite(output);
readln(t);
for i:=1 to t do begin
read(a,b);
case a of
1 : begin
ok:=0;
v:=lhash[b mod prim];
while v<>nil do begin
if v^.info=b then begin
ok:=1;
break;
end;
v:=v^.pred;
end;
if ok=0 then add(b);
end;
3 : begin
ok:=0;
v:=lhash[b mod prim];
while v<>nil do begin
if v^.info=b then begin
ok:=1;
break;
end;
v:=v^.pred;
end;
writeln(ok);
end;
2 : begin
v:=lhash[b mod prim];
r:=lhash[b mod prim];
if lhash[b mod prim]<>nil then
if lhash[b mod prim]^.info=b then
lhash[b mod prim]:=lhash[b mod prim]^.pred
else
while v<>nil do begin
if v^.info=b then begin
r^.pred:=v^.pred;
dispose(v);
break;
end;
r:=v;
v:=v^.pred;
end;
end;
end;
end;
close(input);
close(output);
end.