Cod sursa(job #1207695)
Utilizator | Data | 13 iulie 2014 17:20:27 | |
---|---|---|---|
Problema | Stramosi | Scor | 80 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 0.48 kb |
program stramosi;
type
tabel=array [0..21,0..3000000] of longint;
var
t:tabel;
n,m,i,j,k,x,y,xx:longint;
f1,f2:text;
begin
assign (f1,'stramosi.in');
assign (f2,'stramosi.out');
reset (f1);
rewrite (f2);
readln (f1,n,m);
for i:=1 to n do
read (f1,t[0,i]);
for i:=1 to 18 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:=18 downto 0 do
if (y and (1 shl j))<>0 then x:=t[j,x];
writeln (f2,x);
end;
close (f1);
close (f2);
end.