QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Difficulty: [show]

#14979. Shiratama

Statistics

身為 Shiratama 的忠實粉絲,Kamome 正嘗試創作一些 Shiratama 風格的畫作。

……好吧,出題者太懶了不想寫故事,所以我們直接進入正題。

Kamome 的畫作可以抽象為一個 $1 \sim 2n$ 的排列 $p_1, p_2, \dots, p_{2n}$。你需要透過執行不超過 $2n$ 次操作 1 與不超過 $2n^2$ 次操作 2 來將 $p$ 排序。

  • 操作 1:對於每個 $i = 1, 3, \dots, 2n - 1$,同時交換 $p_i$ 與 $p_{i+1}$。
  • 操作 2:Kamome 選擇一個偶數 $i$($1 \le i \le 2n$)並交換 $p_i$ 與 $p_{i+1}$。注意我們視為 $p_{2n+1} = p_1$。

然而,有時使用上述操作是無法將這個排列排好序的;若是如此,請回報此情況。

輸入格式

每個測試包含多組測試資料。第一行包含一個整數 $t$($1 \le t \le 10^5$),表示測試資料的組數。接下來是各組測試資料的描述。

每組測試資料的第一行包含一個整數 $n$($1 \le n \le 100$,$\sum n^2 \le 10^6$),表示排列的長度參數。

第二行包含 $2n$ 個整數 $p_1, p_2, \dots, p_{2n}$($1 \le p_i \le 2n$,對於 $1 \le i < j \le 2n$ 有 $p_i \ne p_j$),表示該排列。

輸出格式

對於每組測試資料,若無法將排列排序,請輸出一個單字 NO。

否則,你的輸出應包含三行。第一行包含一個單字 YES,第二行包含一個整數 $k$($0 \le k \le 2n^2 + 2n$),第三行包含 $k$ 個整數 $a_1, a_2, \dots, a_k$($a_i \in \{1\} \cup \{2, 4, \dots, 2n\}$),表示你執行的操作。若 $a_i = 1$ 則代表你執行一次操作 1,否則代表你執行一次操作 2 並選擇 $x = a_i$。

注意你不能使用超過 $2n$ 次操作 1 與 $2n^2$ 次操作 2。

若有多組可能的答案,你可以輸出其中任意一組。

範例

輸入

3
2
1 3 4 2
2
2 4 1 3
3
1 2 4 3 5 6

輸出

NO
YES
2
2 1
YES
7
2 4 1 6 1 2 4

說明

對於第 2 組測試資料,排列的變化過程如下:

$$[2, \underline{4, 1}, 3] \to [\underline{2, 1}, \underline{4, 3}] \to [1, 2, 3, 4]$$

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.