Lost Permutation
문제
You once had a permutation of size . And now it's gone. All you have left is an old device you made while studying group theory. To try and recover you can input a permutation of size into this device. This device will then display a permutation . Find using at most two interactions with the device.
A permutation of size is a sequence of distinct integers from to . The composition of two permutations and is a permutation such that . That is, if we consider a permutation as an action on elements, moving element at position to , then is the action that applies , then applies , so that element at position first moves to , then moves to . Note that some definitions of composition use the reverse order.
The inverse permutation is a permutation such that . The composition of a permutation and its inverse is equal to an identity permutation: for all from to . For example, if and , then , and .
힌트
There are two test cases in the first test. In the first test case, is the only permutation that satisfies and . In the second test case, based on the interaction, can be equal to either , , or . The solution got lucky and guessed the correct one: .
예제
예제 1
2 4 1 2 4 3 2 4 3 1 3 3 1 2 2 3 1
? 3 2 1 4 ? 2 4 3 1 ! 4 1 3 2 ? 2 3 1 ? 3 1 2 ! 3 2 1