John Watson performs an operation called a right circular rotation on an array of integers,
[a(0),a(1).a(2)...a(n-2),a(n-1)]. After performing one right circular rotation operation, the array is transformed from
Watson performs this operation
k times. To test Sherlock’s ability to identify the current element at a particular position in the rotated array, Watson asks
q queries, where each query consists of a single integer,
m, for which you must print the element at index in the rotated array (i.e., the value of
The first line contains space-separated integers,
The second line contains space-separated integers, where each integer
i describes array element
0 <= i <= n).
Each of the
q subsequent lines contains a single integer denoting
0 <= i <= 10^5
0 <= a(i) <= 10^5
0 <= k <= 10^5
0 <= q <= 500
0 <= m <= N-1
For each query, print the value of the element at index
m of the rotated array on a new line.
3 2 3
1 2 3
After the first rotation, the array becomes
After the second (and final) rotation, the array becomes
Let’s refer to the array’s final state as array
b. For each query, we just have to print the value of
b(m) on a new line:
m=0 , so we print
2 on a new line.
m=1 , so we print
3 on a new line.
m=2 , so we print
1 on a new line.