#P9660. [ICPC2021 Macao R] Pass the Ball!
[ICPC2021 Macao R] Pass the Ball!
题目描述
There are children playing with balls. Both children and balls are numbered from to .
Before the game, integers are given. In each round of the game, child will pass the ball he possesses to child . It is guaranteed that no child will pass his ball to himself, which means . Moreover, we also know that after each round, each child will hold exactly one ball.
Let be the ball possessed by child . At the beginning of the game, child () will be carrying ball , which means initially. You're asked to process queries. For each query you're given an integer and you need to compute the value of after rounds.
输入格式
There is only one test case for each test file.
The first line of the input contains two integers () and (), indicating the number of children and the number of queries.
The second line contains integers () indicating how the children pass the balls around.
For the following lines, the -th line contains one integer () indicating a query asking for the result after rounds.
输出格式
For each query output one line containing one integer indicating the answer.
4 4
2 4 1 3
1
2
3
4
25
20
25
30
提示
The sample test case is explained below.
$$\begin{array}{|c|c|c|c|c|c|} \hline \textbf{Round} & \textbf{b1} & \textbf{b2} & \textbf{b3} & \textbf{b4} & \textbf{Answer} \\\hline 1 & 3 & 1 & 4 & 2 & 25 \\\hline 2 & 4 & 3 & 2 & 1 & 20 \\\hline 3 & 2 & 4 & 1 & 3 & 25 \\\hline 4 & 1 & 2 & 3 & 4 & 30 \\\hline \end{array} $$