Cod sursa(job #410051)

Utilizator hungntnktpHungntnktp hungntnktp Data 4 martie 2010 07:32:29
Problema Hashuri Scor 30
Compilator fpc Status done
Runda Arhiva educationala Marime 1.42 kb
{DINH QUANG DAT TIN 07-10}
{HASHURI}
CONST
 TFI='hashuri.in';
 TFO='hashuri.out';
 MAX=1000001;
 e=300103;
TYPE
 arr1int=array[0..MAX] of longint;
VAR
 fi,fo:text;
 i,m,n,x,task:longint;
 next,f:array[0..MAX] of longint;
 head:array[0..e] of longint;

PROCEDURE       add;
var
 u,v:longint;
begin
 u:=x mod e;
 if head[u]=0 then
  begin
   inc(m);
   f[m]:=u;
   head[u]:=m;
  end
 else
  begin
   v:=head[u];
   while v<>0 do
    begin
     if f[v]=x then exit;
     if next[v]=0 then break;
     v:=next[v];
    end;
   inc(m);
   f[m]:=x;
   next[v]:=m;
  end;
end;

PROCEDURE       del;
var
 u,v,i:longint;
begin
 u:=x mod e;
 if head[u]=0 then exit;
 v:=head[u];
 i:=0;
 while v<>0 do
  begin
   if f[v]=x then
    begin
     if head[u]=v then head[u]:=next[v];
     next[i]:=next[v];
     exit;
    end;
   i:=v;
   v:=next[v];
  end;
end;

PROCEDURE       find;
var
 u,v:longint;
begin
 u:= x mod e;
 if head[u]=0 then
  begin
   writeln(fo,0);
   exit;
  end;
 v:=head[u];
 while v<>0 do
  begin
   if f[v]=x then
    begin
     writeln(fo,1);
     exit;
    end;
   v:=next[v];
  end;
 writeln(fo,0);
end;

BEGIN
 assign(fi,tfi);reset(fi);
 assign(fo,tfo);rewrite(fo);
  read(fi,n);
  m:=0;
  for i:= 1 to n do
   begin
    read(fi,task,x);
    case task of
     1: add;
     2: del;
     3: find;
    end;
   end;
 close(fo);
 close(fi);
END.