Cod sursa(job #280065)

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


             end;
       end
          else
           if a=2 then
                begin
                  p:=v[b mod ct];
                  while (p<>nil)and(p^.i<>b) do p:=p^.a;
                   if p^.i=b then
                     begin
                       if p=v[b mod ct] then v[b mod ct]:=p^.a
                           else p^.p^.a:=p^.a;
                     end;
                end
                  else
                     begin
                       if exista then writeln('1')
                          else writeln('0');

                     end;
  end;
close(input);
close(output);
end.