QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#16102. Bring It To Back

统计

Jack 正在和他的猫 Salmon 玩一个游戏。书架上放着编号从 1 到 $N$ 的漫画书,按某种顺序从左到右排列。所有书的大小都相同。

Jack 和 Salmon 将重复以下动作序列恰好 $M$ 次($M$ 可以为零):

  1. Jack 选择一本不是最右侧的书,将其推倒。
  2. 他随后通过将该位置右侧的所有书向左移动来填补空隙,使书架的最右端留出空位。
  3. 最后,Salmon 捡起那本推倒的书,并将其放入最右侧的空位中。

你的任务是确定初始排列,使得在执行恰好 $M$ 次上述动作后,存在一种 Jack 的选择序列,能够使书架上的书按从左到右的顺序排列为 $1, 2, \dots, N$。在所有满足条件的初始排列中,你需要找出字典序最大的那一个。

两个不同的 $N$ 本书的排列 $A$ 和 $B$ 进行字典序比较的方法如下:如果在从左往右第一个不同的位置 $i$ 上,$A_i > B_i$,则称 $A$ 的字典序大于 $B$。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试用例的数量。 每个测试用例包含一行,包含两个整数 $N$ 和 $M$ ($1 \le N \le 10^5, 1 \le M \le 10^9$),分别表示书架上的漫画书数量和执行的动作次数。 保证所有测试用例的 $N$ 之和不超过 $10^5$。

输出格式

对于每个测试用例,输出 $N$ 个整数,表示在 Jack 最优选择下,经过恰好 $M$ 次动作后能使书排列为 $1, 2, \dots, N$ 的字典序最大的初始排列。

样例

输入 1

2
3 1
5 2

输出 1

3 1 2
5 4 1 2 3

说明

在第一个测试用例中,Jack 可以推倒 3 号书,Salmon 将其插入到最右侧位置,结果为: 1 2 3。 另一种可能的初始排列是 1 3 2,但输出的排列字典序更大。 初始排列 1 2 3 是不可能的:推倒 1 号书得到 2 3 1,推倒 2 号书得到 1 3 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.