题目描述
Problem Description
Given a permutation \( P = (P_0, P_1, \cdots, P_{N-1}) \) of \( (0, 1, \cdots, N-1) \).
For integers \( a, b \) (where \( 0 \leq a, b \leq N-1 \)), we define the permutation \( f(a,b) \) as follows:
- Let \( f(a,b) = (q_0, q_1, \cdots, q_{N-1}) \), and define \( q_{(i+a \mod N)} = (P_i + b \mod N) \) for \( 0 \leq i \leq N-1 \).
Calculating \( f(a,b) \) for all \( a, b \) yields \( N^2 \) permutations. We consider sorting these permutations lexicographically. After sorting, find the permutation that is at the \( K \)-th position from the beginning.
What is lexicographical order for sequences? A sequence \( S = (S_1, S_2, \ldots, S_{|S|}) \) is lexicographically smaller than a sequence \( T = (T_1, T_2, \ldots, T_{|T|}) \) if either of the following conditions holds:
- \( |S| < |T| \) and \( (S_1, S_2, \ldots, S_{|S|}) = (T_1, T_2, \ldots, T_{|S|}) \).
- There exists an integer \( 1 \leq i \leq \min\{|S|, |T|\} \) such that both of the following are true:
- \( (S_1, S_2, \ldots, S_{i-1}) = (T_1, T_2, \ldots, T_{i-1}) \)
- \( S_i \) is smaller than \( T_i \) (as a number).
Input Format
The input is given from the standard input in the following format:
\( N \) \( K \) \( P_0 \) \( P_1 \) \( \cdots \) \( P_{N-1} \)
Output Format
Output the resulting permutation, with elements separated by spaces.
Sample Input and Output
Sample Input #1
2 2
0 1
Sample Output #1
0 1
Sample Input #2
4 6
0 2 1 3
Sample Output #2
1 2 0 3
Sample Input #3
10 79
6 5 9 8 7 1 3 2 0 4
Sample Output #3
7 9 8 2 1 0 4 6 5 3
Notes/Hints
Constraints
- \( 1 \leq N \leq 2 \times 10^5 \)
- \( 1 \leq K \leq N^2 \)
- \( (P_0, P_1, \cdots, P_{N-1}) \) is a permutation of \( (0, 1, \cdots, N-1) \).
- All values given in the input are integers.
Sample Explanation 1
The possible \( f(a,b) \) are as follows:
- \( f(0,0) = (0,1) \)
- \( f(0,1) = (1,0) \)
- \( f(1,0) = (1,0) \)
- \( f(1,1) = (0,1) \)
Sorting these permutations lexicographically results in \( (0,1), (0,1), (1,0), (1,0) \). Therefore, the permutation at the 2nd position, \( (0,1) \), is the answer.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分