Pagini recente » Diferente pentru autumn-warmup-2007/solutii/runda-3 intre reviziile 26 si 27 | Diferente pentru concursuri intre reviziile 81 si 80 | basavyr | Cod sursa (job #3150282) | Cod sursa (job #201833)
Cod sursa(job #201833)
program stramosi_010;
var a:array[0..250001,0..18] of longint;
n,m:longint;
i,j,r,l,u,v,w:longint;
BEGIN
assign(input,'stramosi.in'); reset(input);
assign(output,'stramosi.out'); rewrite(output);
readln(n,m); r:=trunc(ln(n)/ln(2));
for i:=1 to n do read(a[i,0]);
for j:=1 to r do
for i:=1 to n do a[i,j]:=a[a[i,j-1],j-1];
for l:=1 to m do begin
readln(u,v);
for w:=0 to r do begin
if (v and (1 shl w))>0 then u:=a[u,w];
end;
writeln(u);
end;
close(output); close(input);
END.