Cod sursa(job #1178579)

Utilizator Mihai_ChihaiMihai Chihai Mihai_Chihai Data 26 aprilie 2014 21:55:55
Problema Hashuri Scor 30
Compilator fpc Status done
Runda Arhiva educationala Marime 1.75 kb
  program hashuri;
    const p=666013;
   type lista=^celula;
        celula=record
           info:int64;
           pred:lista;
           end;
   var a:array[0..p] of lista;
      n,op,x:int64;

      i:longint;
      r,q:lista;
      u:boolean;

   begin
   assign(input,'hashuri.in');
   assign(output,'hashuri.out');
   reset(input);
   rewrite(output);
   readln(n);
   for i:=1 to n do begin
       readln(op,x);
       if op=1 then
          begin
            u:=false;
            r:=a[x mod p];
            while r<>nil do begin
              if r^.info=x  then u:=true;
              r:=r^.pred;
              end;
            if not u then
            begin
            new(r);
            r^.info:=x;
            r^.pred:=a[x mod p];
            a[x mod p]:=r;
            end;
          end;
       if op=2 then
          begin
          r:=a[x mod p];
          if( r<>nil) then
               begin
                 if  (r^.info=x) then
                   a[x mod p]:=a[x mod p]^.pred
                 else
                 begin
                   while (R^.pred<>nil) do
                       begin
                       if (R^.pred^.info=x) then q:=r;
                       r:=r^.pred;
                       end;
                 if q<>nil then
                  q^.pred:=q^.pred^.pred;
                 end;
               end;
          end;
       if op=3 then
          begin
          u:=false;
          r:=a[x mod p];
          while r<>nil do begin
                if r^.info=x then
                   u:=true;
                r:=r^.pred;
                end;
          if u then
             writeln(1)else
             writeln(0);
          end;
      end;
   close(output);
   end.