Codeforces Round 1082 (Div. 2)
D
Recollect Numbers
Codeforces
未评级
原题
← C2E →
翻译中…

There are $2n$ cards with numbers $1,1,2,2,\ldots,n,n$ written on them. In other words, for all $j=1,2,\ldots,n$, there are exactly $2$ cards with the number $j$. Each card only has one number written on its front.

翻译中…

You will play a card flipping game. Initially, all $2n$ cards are placed on their back (the side without numbers). In each turn, you flip exactly two cards. If the two cards have the same number, you discard the two cards. Otherwise, you flip them back to their original position. You win when all $2n$ cards are discarded. Note that you do not have to flip the two cards simultaneously, so you can decide on your choice of the second card after seeing the number on the first one.

翻译中…

Consider the following "greedy" algorithm to play the game. Initially, the $2n$ cards are placed in a row arbitrarily. Then your strategy on each turn is as follows:

翻译中…
  • If there are two cards that you have flipped previously and have the same number, flip those two cards.
  • Otherwise, flip the first card$^\text{*}$ that you have never flipped so far as the first one. Let's say this card has the number $x$.
  • Afterwards, if there is another card that you have flipped previously and has the number $x$, flip that card.
    • Otherwise, flip the first card$^{\text{∗}}$ that you have never flipped so far (including in this turn) as the second one.
翻译中…

It can be shown that the algorithm's strategy is uniquely determined on every turn.

翻译中…

You must solve the following problem regarding the algorithm stated above.

翻译中…
  • Given $n$ and $k$, please find an orientation of the $2n$ cards for which the algorithm above takes exactly $k$ turns to win the game.
翻译中…

Additionally, if such an orientation does not exist, please report so.

翻译中…

$^{\text{∗}}$Here, "the first card" of some condition refers to the earliest card in the row satisfying that condition.

翻译中…

Input

翻译中…

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

翻译中…

The only line of each test case contains two integers $n$ and $k$ ($1 \le n \le 300\,000$, $1 \le k \le 1\,000\,000$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $300\,000$.

翻译中…

Output

翻译中…

If there is an orientation of cards that satisfies the conditions, output "YES" on a new line.

翻译中…

Then, output $2n$ integers $a_1,a_2,\ldots,a_{2n-1},a_{2n}$ on the next line. Here, $a_i$ is the number written on the $i$-th card.

翻译中…

Do note that the sequence $a$ must satisfy the following conditions:

翻译中…
  • For each $1 \le i \le 2n$, $1 \le a_i \le n$;
  • For each $1 \le j \le n$, $j$ appears in $a$ exactly twice;
  • When the cards are placed in this order, the algorithm stated above takes exactly $k$ turns to win the game.
翻译中…

If there are multiple solutions, print any of them.

翻译中…

If there is no orientation of cards that satisfies the conditions, output "NO" on a separate line.

翻译中…

You can output the answer in any case. For example, the strings "yEs", "yes", and "Yes" will also be recognized as positive responses.

翻译中…

Note

翻译中…

For the first test case, the choices on each turn are as follows:

翻译中…
  1. $[\color{red}{2},\color{red}{1},2,1]$: The two cards have different numbers, so they are flipped back into position.
  2. $[\color{red}{2},\color{blue}{1},\color{red}{2},1]$: The two cards have the same number, so they get discarded.
  3. $[\color{red}{1},\color{red}{1}]$: The two cards have the same number, so they get discarded.
翻译中…

Here, the red numbers indicate the cards flipped on the current turn, and the blue numbers indicate cards that you have flipped previously.

翻译中…

For the fourth test case, the choices on each turn are as follows:

翻译中…
  1. $[\color{red}{1},\color{red}{2},3,1,2,3]$: The two cards have different numbers, so they are flipped back into position.
  2. $[\color{blue}{1},\color{blue}{2},\color{red}{3},\color{red}{1},2,3]$: The two cards have different numbers, so they are flipped back into position.
  3. $[\color{red}{1},\color{blue}{2},\color{blue}{3},\color{red}{1},2,3]$: The two cards have the same number, so they get discarded.
  4. $[\color{red}{2},\color{blue}{3},\color{red}{2},3]$: The two cards have the same number, so they get discarded.
  5. $[\color{red}{3},\color{red}{3}]$: The two cards have the same number, so they get discarded.
翻译中…

The algorithm took exactly $k=5$ turns to win the game.

翻译中…

样例

Input #1
6
2 3
3 4
3 2
3 5
6 10
6 67
Output #1
YES
2 1 2 1
YES
1 3 2 2 1 3
NO
YES
1 2 3 1 2 3
YES
2 1 3 4 5 4 1 2 6 5 6 3
NO
InputCopy OutputCopy
题目信息
题号
2202D
时间限制
2 s
内存限制
256 MB

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