Cod sursa(job #601195)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 5 iulie 2011 11:37:16
Problema Stramosi Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.83 kb
program stramosi;
 var a:array [1..250000] of longint;
   i,q,n,m,p:longint;
   fi,fo:text;
begin
 assign(fi,'stramosi.in');
  reset(fi);
 assign(fo,'stramosi.out');
  rewrite(fo);
 readln(fi,n,m);
 for i:=1 to n do
  read(fi,a[i]);
 readln(fi);
 for i:=1 to m do begin
  readln(fi,q,p);
  {if (q-p+1>0) and (a[q]<>0) then
               writeln(fo,a[q-p+1])
  else writeln(fo,'0');}
  if p=1 then writeln(fo,a[q])
   else begin
  while p>1 do
  if q>1 then
   if a[q-1]<>a[q] then begin
                        dec(p);
                        dec(q);
                        end
   else dec(q)
    else if (q=1) and (p>1) then begin
                                  writeln(fo,'0');
                                  p:=1;
                                  end;
   writeln(fo,a[q]);
  end;
  end;
close(fo);
end.