Codeforces Round 1008 (Div. 2)
B
Vicious Labyrinth
Codeforces
1100
原题
← AC →
翻译中…
翻译中…

There are $n$ cells in a labyrinth, and cell $i$ ($1 \leq i \leq n$) is $n - i$ kilometers away from the exit. In particular, cell $n$ is the exit. Note also that each cell is connected to the exit but is not accessible from any other cell in any way.

翻译中…

In each cell, there is initially exactly one person stuck in it. You want to help everyone get as close to the exit as possible by installing a teleporter in each cell $i$ ($1 \leq i \leq n$), which translocates the person in that cell to another cell $a_i$.

翻译中…

The labyrinth owner caught you in the act. Amused, she let you continue, but under some conditions:

翻译中…
  • Everyone must use the teleporter exactly $k$ times.
  • No teleporter in any cell can lead to the same cell it is in. Formally, $i \neq a_i$ for all $1 \leq i \leq n$.
翻译中…

You must find a teleporter configuration that minimizes the sum of distances of all individuals from the exit after using the teleporter exactly $k$ times while still satisfying the restrictions of the labyrinth owner.

翻译中…

If there are many possible configurations, you can output any of them.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first and only line of each test case contains two integers $n$ and $k$ ($2 \leq n \leq 2 \cdot 10^5$, $1 \leq k \leq 10^9$) — the number of cells in the labyrinth and the value $k$.

翻译中…

It is guaranteed that the total sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output $n$ integers — the destinations of the teleporters $a_1, a_2, \ldots, a_n$ in order, satisfying the given conditions ($1 \leq a_i \leq n$, $a_i \neq i$).

翻译中…

Note

翻译中…

In the first test case, the position of each person is as follows.

翻译中…
  • Before teleporting: $[1, 2]$.
  • First teleportation: $[2, 1]$.
翻译中…

The distance sum is $(2-2) + (2-1) = 1$, which is the minimum possible.

翻译中…

In the second test case, the position of each person is as follows.

翻译中…
  • Before teleporting: $[1, 2, 3]$.
  • First teleportation: $[2, 3, 2]$.
  • Second teleportation: $[3, 2, 3]$.
翻译中…

The distance sum is $(3-3) + (3-2) + (3-3) = 1$, which is the minimum possible.

翻译中…

样例

Input #1
2
2 1
3 2
Output #1
2 1
2 3 2
InputCopy OutputCopy
题目信息
题号
2078B
时间限制
1.5 s
内存限制
256 MB
标签
构造
图论
贪心
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。