QOJ.ac

QOJ

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

#11547. 不是那么长的上升子序列

الإحصائيات

令 $N, K$ 为满足 $K \le N$ 的正整数。Busy Beaver 有一个 $1, \dots, N$ 的排列 $a_1, \dots, a_N$。若 $a_1, \dots, a_N$ 的一个长度为 $K$ 的子序列 $b_1, \dots, b_K$ 的最长上升子序列长度不超过 $\frac{K+1}{2}$,则称该子序列是“有趣的”。

请判断 Busy Beaver 的排列中是否存在长度为 $K$ 的有趣子序列,如果存在,请给出一个有趣的子序列示例。

输入格式

每个测试包含多个测试用例。输入的第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试用例的数量。接下来是各测试用例的描述。

每个测试用例的第一行包含两个空格分隔的整数 $N, K$ ($1 \le K \le N \le 2 \cdot 10^5$)。

每个测试用例的第二行包含 $N$ 个整数 $a_1, a_2, \dots, a_N$ ($1 \le a_i \le N$,$a_i$ 两两不同) —— 即 Busy Beaver 的排列。

保证所有测试用例的 $N$ 之和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,如果存在有趣的子序列,输出 “YES”(不含引号),否则输出 “NO”(不含引号)。你可以以任意大小写形式输出 “YES” 和 “NO”(例如,“yES”、“yes” 和 “Yes” 均会被识别为肯定回答)。

如果回答为 “YES”,则打印第二行,包含 $K$ 个空格分隔的整数 $i_1, \dots, i_K$ ($1 \le i_1 < \dots < i_K \le N$),表示排列中满足 $a_{i_1}, \dots, a_{i_K}$ 为有趣子序列的下标。如果存在多个可能的解,打印其中任意一个即可。

子任务

如果 YES/NO 回答正确,但提供的 $i_1, \dots, i_K$ 值不正确,你将获得每个子任务 50% 的分数。对于每个测试用例,你仍然必须输出长度为 $K$ 的子序列下标 $i_1 < \dots < i_K$,才能获得 YES/NO 回答的部分分。例如,你可以输出 $(i_1, \dots, i_K) = (1, \dots, K)$,但不能输出 $(i_1, \dots, i_K) = (1, \dots, 1)$。

本题共有三个子任务:

  • (10 分):$K \le 4$。
  • (20 分):排列中满足 $a_i > a_{i+1}$ 的下标 $i$ ($1 \le i < N$) 最多只有一个。
  • (70 分):无额外限制。

样例

样例输入 1

10
4 2
4 2 1 3
7 3
3 1 4 5 7 2 6
8 8
4 5 6 7 8 1 2 3
6 4
5 2 4 3 1 6
9 8
1 3 2 4 6 5 7 9 8
9 7
1 3 2 4 6 5 7 9 8
9 5
1 6 8 9 2 5 3 4 7
3 2
3 2 1
3 2
1 2 3
1 1
1

样例输出 1

YES
2 3
YES
5 6 7
NO
YES
1 2 4 5
NO
YES
2 3 5 6 7 8 9
YES
3 4 6 7 8
YES
2 3
NO
YES
1

说明

在第一个测试用例中,子序列 $[a_2, a_3] = [2, 1]$ 有两个最长上升子序列 $[2]$ 和 $[1]$,它们的长度均不超过 $\frac{2+1}{2} = \frac{3}{2}$。因此它是一个有趣的子序列。

在第二个测试用例中,子序列 $[a_5, a_6, a_7] = [7, 2, 6]$ 有一个唯一的最长上升子序列 $[2, 6]$,其长度不超过 $\frac{3+1}{2} = 2$。因此它是一个有趣的子序列。

在第三个测试用例中,长度为 8 的唯一子序列是整个序列 $[a_1, \dots, a_8] = [4, 5, 6, 7, 8, 1, 2, 3]$。该序列的最长上升子序列是 $[4, 5, 6, 7, 8]$。由于其长度大于 $\frac{8+1}{2} = \frac{9}{2}$,因此不存在有趣的子序列。

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.