QOJ.ac

QOJ

Límite de tiempo: 5.0 s Límite de memoria: 256 MB Puntuación total: 100 Hackeable ✓

#12830. 排列

Estadísticas

Byteasar 急需两个整数序列用于他的研究:一个递增序列和一个递减序列。然而,他手头仅有一个范围在 $[1, n]$ 内的排列 $(p_1, p_2, \dots, p_n)$。你能帮他将这个排列划分为这样的两个序列吗?

形式化地,我们需要寻找两个子序列 $p_{r_1}, p_{r_2}, \dots, p_{r_R}$ 和 $p_{m_1}, p_{m_2}, \dots, p_{m_M}$ ($R, M \ge 0$),使得:

  • $1 \le r_1 < \dots < r_R \le n$ 且 $p_{r_1} < \dots < p_{r_R}$,
  • $1 \le m_1 < \dots < m_M \le n$ 且 $p_{m_1} > \dots > p_{m_M}$,
  • 对于所有 $i, j$ ($1 \le i \le R, 1 \le j \le M$),满足 $r_i \neq m_j$,
  • $R + M = n$。

输入格式

输入的第一行包含一个整数 $t$ ($1 \le t \le 50$),表示输入文件中的测试用例数量。接下来的行描述了各个测试用例。

每个测试用例包含两行。第一行包含一个整数 $n$ ($1 \le n \le 100\,000$),表示排列 $(p_i)$ 的长度。下一行包含 $n$ 个整数 $p_1, \dots, p_n$ ($1 \le p_i \le n$ 且对于所有 $i \neq j$ 有 $p_i \neq p_j$),即排列本身。

输出格式

对于每个测试用例(按输入顺序),如果该排列可以划分为符合条件的子序列,则输出 YES,否则输出 NO。如果划分可行,你还需要输出另外两行来描述一个示例解。请遵循以下格式:

$R \ p_{r_1} \ p_{r_2} \ \dots \ p_{r_R}$ $M \ p_{m_1} \ p_{m_2} \ \dots \ p_{m_M}$

如果存在多种解,你可以输出其中任意一个。

样例

样例输入 1

3
5
5 1 4 2 3
5
1 2 3 5 4
1
1

样例输出 1

YES
2 1 2
3 5 4 3
YES
3 1 2 3
2 5 4
YES
0
1 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.