Pagini recente » Cod sursa (job #3194290) | Cod sursa (job #1525662) | Cod sursa (job #953254) | Cod sursa (job #2971997) | Cod sursa (job #1179711)
var s:array[0..25,0..2500000] of longint;
n,m,x,y,i,j:longint;
bufin,bufout:array[1..1 shl 17] of char;
begin
assign(input,'stramosi.in');
reset(input);
assign(output,'stramosi.out');
rewrite(output);
settextbuf(input,bufin);
settextbuf(output,bufout);
readln(n,m);
for i:=1 to n do read(s[0,i]);
for i:=1 to 20 do
for j:=1 to n do
s[i][j]:=s[i-1][s[i-1,j]];
while m>0 do begin
readln(x,y);
for j:=20 downto 0 do
if (y and (1 shl j))<>0 then
x:=s[j,x];
writeln(x);
dec(m);
end;
close(output);
end.