#P2227. [HNOI2001] 洗牌机
[HNOI2001] 洗牌机
Description
Kaikai and Fanfan have cards (numbered in order) and a shuffling machine. Assume is odd. The shuffling machine performs the following operation: for every position (), if the card at position is , and the card at position is , then after running the machine, the card at position will be .
Kaikai first writes down a random permutation of : . He then arranges the deck as follows: put card at position (for ), and put card at position . After this arrangement, the deck order is . Then he runs the shuffling machine times to obtain the order . Now Kaikai tells Fanfan the final order and the number of shuffles, and asks Fanfan to determine the initial order .
Input Format
The first line contains integers and .
The second line contains the final order of the cards .
Output Format
Output one line: the initial order .
5 2
4 1 5 3 2
2 5 4 1 3
Hint
Constraints
For of the testdata, it is guaranteed that .
The testdata guarantees that, starting from , let the number on the -th card be , then assign and continue this process; eventually, all cards will be visited.
Translated by ChatGPT 5
京公网安备 11011102002149号