Inversion Insight

시간 제한0.5초메모리 제한2048 MB

요약
1부터 N까지의 모든 순열을 반전 수 오름차순으로, 같으면 사전순으로 정렬했을 때 K번째 순열을 구해 출력한다.
난이도

어려움10점 중 9점

유형
조합론, 동적 계획법, 그리디, 수학
정답자
아직 제출이 없습니다

문제

In MathemIsland, the wildlife is very diverse. There are roots, trees, leaves, pigeons – everything you’d find in a math book. And everywhere you look, there is a permutation.

ICPC University has devised a systematic way to catalog these permutations. Specifically, because inversions are of utmost importance in studying wildlife genetics, ICPC University has decided to sort all N!N! permutations of the integers from 11 to NN: first by the number of inversions and, in the case of a tie, by lexicographic order. This approach uniquely identifies each permutation by an integer from 11 to N!N!, indicating its position in the sorted list of all N!N! permutations.

Thus, the identity permutation (1,2,…,N)(1, 2, \dots , N), which is the only permutation with zero inversions, is assigned the identifier 11, while the reverse identity permutation (N,N−1,…,1)(N, N - 1, \dots , 1), which is the only one with the maximum number of inversions, is assigned the identifier N!N!.

As part of the team implementing the ICPC University database, your task is to retrieve a specific permutation based on its identifier. Write a program that, given two integers NN and KK, outputs the permutation of the integers from 11 to NN corresponding to identifier KK.

Remember that the number of inversions in a permutation is the number of pairs of elements that are out of their natural order. That is, for a permutation ππ with NN elements, its number of inversions inv(π)\text{inv}(π) is defined as

inv(π)=∣(i,j):1≤i<j≤N∧π(i)>π(j)∣\text{inv}(π) = |\\{(i, j) : 1 ≤ i < j ≤ N ∧ π(i) > π(j)\\}|

입력

The input consists of a single line that contains two integers NN (1≤N≤2⋅1051 ≤ N ≤ 2 \cdot 10^5 ) and KK (1≤K≤min⁡(N!,4⋅1018)1 ≤ K ≤ \min(N!, 4 \cdot 10^{18})).

출력

Output a single line with NN integers, describing the KK-th permutation of the integers from 11 to NN, considering permutations sorted according to the university’s criteria.

예제3

  1. 예제 1

    입력
    4 10
    
    예상 출력
    1 4 3 2
    
  2. 예제 2

    입력
    5 120
    
    예상 출력
    5 4 3 2 1
    
  3. 예제 3

    입력
    16 12345678901234
    
    예상 출력
    2 13 8 10 3 15 16 5 11 12 1 9 7 6 14 4