QOJ.ac

QOJ

حد الوقت: 3 s حد الذاكرة: 256 MB مجموع النقاط: 100

#8107. 排列

الإحصائيات

长度为 $n$ 的排列是一个序列 $p_1, p_2, \dots, p_n$,其中 $p_i \in \{1, 2, \dots, n\}$ 且对于任意 $i \neq j$ 都有 $p_i \neq p_j$。我们称一对满足 $i < j$ 且 $p_i > p_j$ 的元素 $(p_i, p_j)$ 为一个逆序对。如果一个排列在反转整个序列后,其逆序对的数量保持不变,则称该排列为稳定的。

请找出长度为 $n$ 的所有稳定排列中,按字典序排列的第 $k$ 个排列。

输入格式

输入仅一行,包含两个整数 $n, k$ ($1 \le n \le 250\,000, 1 \le k \le 10^{18}$),分别表示排列的长度和所求稳定排列的字典序索引。

输出格式

如果存在这样的排列,第一行输出 YES,第二行输出 $n$ 个数字 $p_1, \dots, p_n$,表示所求的排列。否则输出 NO

样例

输入 1

4 3

输出 1

YES
2 4 1 3

输入 2

4 57

输出 2

NO

说明

长度为 4 的稳定排列共有 6 个: $(1, 4, 3, 2), (2, 3, 4, 1), (2, 4, 1, 3), (3, 1, 4, 2), (3, 2, 1, 4), (4, 1, 2, 3)$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.