#P3509. Frog Leaping Training
Frog Leaping Training
Frog Leaping Training
A frog is training by leaping on rocks located along a straight Byteotian brook. There are \( n \) rocks located at positions \( p_1, p_2, \dots, p_n \) (with \( p_1 < p_2 < \cdots < p_n \)). The frog is initially on one of these rocks. When the frog is on the rock at position \( p_i \), it makes a leap according to the following rule:
It leaps to the rock \( p_j \) that satisfies \[ |\{ p_a : |p_a - p_i| k, \] where \( k \) is a given nonnegative integer. In other words, if you list the distances \( \{|p_a - p_i| : a\neq i\} \) in non-decreasing order, then the frog always jumps to the rock corresponding to the \( (k+1)\)th smallest distance. If there are multiple rocks with the same distance, the frog chooses the one nearest to the spring (i.e. with the smallest \( p \) value).
The process is repeated for \( m \) leaps. Given the layout of the rocks, determine on which rock the frog will be after \( m \) leaps for several starting positions.
inputFormat
The input begins with a line containing three integers \( n \), \( k \), and \( m \) where \( n \) is the number of rocks, \( k \) is the parameter as described above, and \( m \) is the number of leaps.
The second line contains \( n \) integers \( p_1, p_2, \dots, p_n \) in strictly increasing order.
The third line contains a single integer \( q \), the number of queries.
Then \( q \) lines follow; each contains a single integer representing the starting rock's index (1-indexed).
outputFormat
For each query, output a single line with one integer – the 1-indexed position of the rock where the frog is located after \( m \) leaps.
sample
3 0 1
1 2 3
3
1
2
3
2
1
2
</p>