Cod sursa(job #1418160)

Utilizator ButnaruButnaru George Butnaru Data 12 aprilie 2015 09:25:17
Problema Stramosi Scor 80
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.58 kb
program stramosi;
type vector1=array[0..17,0..250001] of longint;
     buf=array[0..1 shl 17] of char;
var t:vector1; ff1,ff2:buf;
    n,m,i,j,x,y:longint;
    f1,f2:text;
begin
assign (f1,'stramosi.in');
assign (f2,'stramosi.out');
reset (f1);
rewrite (f2);
settextbuf(f1,ff1);
settextbuf(f2,ff2);
readln (f1,n,m);
for i:=1 to n do read (f1,t[0,i]);
for i:=1 to 17 do
for j:=1 to n do
t[i,j]:=t[i-1,t[i-1,j]];
for i:=1 to m do begin
readln (f1,x,y);
for j:=17 downto 0 do
if (y and (1 shl j))<>0 then x:=t[j,x];
writeln (f2,x);
end;
close (f1);
close (f2);
end.