QOJ.ac

QOJ

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

#5529. 最烦人的构造题

统计

如果一个整数数组 $a_1, a_2, \dots, a_m$ 的逆序对数量为奇数,则称其为奇数组,否则称为偶数组。 回想一下,逆序对是指满足 $1 \le i < j \le m$ 且 $a_i > a_j$ 的数对 $(i, j)$。例如,在数组 $[2, 4, 1, 3]$ 中,有 3 个逆序对:$(1, 3), (2, 3), (2, 4)$(因为 $a_1 > a_3, a_2 > a_3, a_2 > a_4$),因此它是奇数组。

给定 $n, k$,确定是否存在一个 $1$ 到 $n$ 的排列,使得它恰好有 $k$ 个奇子数组。 如果数组 $b$ 可以通过从数组 $c$ 的开头删除若干个(可能为零或全部)元素,并从末尾删除若干个(可能为零或全部)元素得到,则称 $b$ 是 $c$ 的子数组。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 10^4$),表示测试用例的数量。接下来是各测试用例的描述。 每个测试用例仅一行,包含两个整数 $n, k$ ($1 \le n \le 1000, 0 \le k \le \frac{n(n-1)}{2}$)。 保证所有测试用例的 $n^2$ 之和不超过 $4 \cdot 10^6$。

输出格式

对于每个测试用例,如果不存在这样的排列,输出 NO。 否则,输出 YES。在下一行输出 $n$ 个整数 $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$,所有 $p_i$ 互不相同),即该排列的元素。

样例

输入 1

4
1 0
3 3
4 1
6 15

输出 1

YES
1
YES
3 2 1
YES
1 3 4 2
NO

说明

在第一个测试用例中,排列为 (1);其所有子数组均为偶数组。 在第二个测试用例中,排列为 (3, 2, 1)。它有 3 个奇子数组:[3, 2] 和 [2, 1] 各有 1 个逆序对,[3, 2, 1] 有 3 个逆序对。 在第三个测试用例中,排列为 (1, 3, 4, 2)。它恰好有 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.