#P2227. [HNOI2001] 洗牌机

    ID: 1201 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2001各省省选湖南图的建立,建图最大流

[HNOI2001] 洗牌机

Description

Kaikai and Fanfan have nn cards (numbered 1,2,,n1,2,\ldots,n in order) and a shuffling machine. Assume nn is odd. The shuffling machine performs the following operation: for every position ii (1in1\le i\le n), if the card at position ii is jj, and the card at position jj is kk, then after running the machine, the card at position ii will be kk.

Kaikai first writes down a random permutation of 1,2,,n1,2,\ldots,n: a1,a2,,ana_1,a_2,\ldots,a_n. He then arranges the deck as follows: put card ai+1a_{i+1} at position aia_i (for 1in11\le i\le n-1), and put card a1a_1 at position ana_n. After this arrangement, the deck order is x1,x2,,xnx_1,x_2,\ldots,x_n. Then he runs the shuffling machine ss times to obtain the order p1,p2,,pnp_1,p_2,\ldots,p_n. Now Kaikai tells Fanfan the final order and the number of shuffles, and asks Fanfan to determine the initial order x1,x2,,xnx_1,x_2,\ldots,x_n.

Input Format

The first line contains integers nn and ss.

The second line contains the final order of the cards p1,p2,,pnp_1,p_2,\ldots,p_n.

Output Format

Output one line: the initial order x1,x2,,xnx_1,x_2,\ldots,x_n.

5 2          
4 1 5 3 2

2 5 4 1 3

Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that 1n,s1031\le n,s\le 10^3.

The testdata guarantees that, starting from i=1i=1, let the number on the ii-th card be jj, then assign i=ji=j and continue this process; eventually, all cards will be visited.

Translated by ChatGPT 5