QOJ.ac

QOJ

時間限制: 6 s 記憶體限制: 256 MB 總分: 100

#5567. 平衡排列

统计

给定一个大小为 $n$ 的排列 $p$,如果一个(连续)子数组的第一个或最后一个元素是该子数组中的最大值,则称该子数组为“不稳定”的。如果一个排列在所有大小为 $n$ 的排列中拥有的“不稳定”子数组数量最少,则称该排列为“平衡”的。

给定整数 $n, l$ 和 $k$,请输出第 $l$ 个字典序最小的“平衡”排列以及第 $k$ 个字典序最大的“平衡”排列。如果不存在这样的排列,则输出 $-1$。

输入格式

输入仅一行,包含三个整数 $n, l$ 和 $k$ ($1 \le n \le 10^5, 1 \le l, k \le 10^{18}$),分别表示所需的排列长度,以及需要提供的字典序最小和字典序最大的排列的序号。

输出格式

输出两行。第一行包含第 $l$ 个字典序最小的“平衡”排列 $p$。 第二行包含第 $k$ 个字典序最大的“平衡”排列 $q$。

$p$ 和 $q$ 必须满足对于所有 $1 \le i \le n$,都有 $1 \le p_i, q_i \le n$。 如果 $p$ 或 $q$ 不存在(即不存在第 $l$ 个或第 $k$ 个“平衡”排列),则输出 $-1$。

样例

样例输入 1

3 1 2

样例输出 1

1 3 2
1 3 2

样例输入 2

4 9 13

样例输出 2

3 1 4 2
-1

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.