QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 512 MB 总分: 100

#9321. 排列与置换(最小化版本)

统计

对于给定的 $x$,如果一个大小为 $n$ 的排列满足对于每个 $1 \le i < n$ 都有 $p_i + p_{i+1} \le x$,则称该排列为“好的”。请找到任意一个具有最少循环数量的“好的”排列。

大小为 $n$ 的排列是 $1$ 到 $n$ 的 $n$ 个不同整数的序列。

排列 $p$ 的一个循环是一个下标序列 $i_1, i_2, \dots, i_k$,满足 $p_{i_1} = i_2, p_{i_2} = i_3, \dots, p_{i_k} = i_1$。通过循环移位得到的序列被视为同一个循环。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 2 \cdot 10^5$),表示测试用例的数量。接下来是各测试用例。

每个测试用例占一行,包含两个整数 $n$ ($2 \le n \le 2 \cdot 10^5$) 和 $x$ ($n+1 \le x \le 2 \cdot n - 1$)。这些约束条件保证至少存在一个“好的”排列。

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

输出格式

对于每个测试用例,输出两行。第一行包含长度为 $n$ 的“好的”排列中最少的循环数量。第二行包含 $n$ 个整数,即该排列本身。如果存在多个这样的排列,输出其中任意一个即可。

样例

样例输入 1

2
2 3
6 10

样例输出 1

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