Cod sursa(job #280116)

Utilizator cheery_g1rlHaller Emanuela cheery_g1rl Data 13 martie 2009 10:59:30
Problema Hashuri Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 1.28 kb
type lista=^element;
     element=record
         i:longint;
         a:lista;
            end;
var v:array[1..666013] of lista;
    i,ct,n,a,b:longint;
    p:lista;
function exista:boolean;
   var w:lista;
   begin
     w:=v[b mod ct];
     while w<>nil do
        begin
          if w^.i=b then exista:=true;
          w:=w^.a;
        end;
     exista:=false;
   end;
begin
assign(input,'hashuri.in'); reset(input);
assign(output,'hashuri.out'); rewrite(output);
ct:=666013;readln(n);
while (n>=1) do
  begin
    readln(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;
                end
                  else
                     begin
                       if exista then writeln('1')
                                 else writeln('0');
                     end;
    dec(n);
  end;
close(input);
close(output);
end.