烽火 2018-06-08 20:49:27
点我顶贴
收藏
删除
var
n,m,i,p,t,x,y,code:longint;
a:array[1..1000001]of byte;
s:array[1..1000001]of string;
st:string;
begin
assign(input,'toy.in'); reset(input);
assign(output,'toy.out'); rewrite(output);
readln(n,m);
for i:=1 to n do
begin
readln(st);
p:=pos(' ',st);
val(copy(st,1,p-1),a[i],code);
s[i]:=copy(st,p+1,length(st)-p);
end;
t:=1;
for i:=1 to m do
begin
readln(x,y);
if a[t]=x then t:=t-y else t:=t+y;
if t<n then t:=t+n;
if t>n then t:=t-n;
end;
writeln(s[t]);
close(input);
close(output);
end.