Cod sursa(job #512503)

Utilizator chestiaproblema de trimis chestia Data 13 decembrie 2010 22:38:38
Problema Hashuri Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 1.29 kb
type lista=^element;
element=record
i:longint;
a:lista;
end;
var v:array[1..666013] of lista;
ct,n,a,b,i:longint;
p:lista;
f,g:text;


function exista:boolean;
var w:lista;
begin
w:=v[b mod ct];
exista:=false;
while w<> nil do begin
   if w^.i=b then exista:=true;
   w:=w^.a;
   end;
end;





begin
assign(f,'hashing.in');reset(f);
assign(g,'hashing.out');rewrite(g);
ct:=666013;
readln(f,n);
for i:=1 to n do begin
    readln(f,a,b);
    if a=1 then begin
       if not exista then begin
          new(p);
          p^.i:=b;
          p^.a:=v[b mod ct];
          v[b mod ct]:=p;
        end;
    end
        else
        if a=2 then begin
           p:=v[b mod ct];
           while p<> nil do begin
                 if p^.i=b then p^.i:=0;
                 p:=p^.a;
                 end;
           {if p^.i=b then v[b mod ct]:=v[b mod ct]^.a else
                                while p^.a <> nil do begin
                                    if p^.a^.i=b then p^.a:=p^.a^.a;
                                    p:=p^.a;
                                 end;     }
               end
               else
               begin
                 if exista then writeln(g,1) else writeln(g,0);
                 end;
end;
close(f);
close(g);
end.