Universal Cup Judging System

Universal Cup

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100
Statistics

在 2077 年,命題變得非常簡單。機器人會透過設定一些隨機操作來生成一個問題,然後解決它。命題者只需要檢查這個問題是否正確即可。

下面是一個來自 2077 年的問題:

給定一個排列 $p_1, p_2, \dots, p_n$,保證 $n$ 是偶數。你希望僅使用一種操作來對該排列進行排序:

  • FakeSort(l,r):你必須保證 $r - l + 1$ 是偶數。設 $k = r - l + 1$,那麼連續子序列 $p_l, p_{l+1}, \dots, p_r$ 中最大的 $k/2$ 個元素與最小的 $k/2$ 個元素將分別獨立地進行排序。也就是說,設 $L_1, L_2, \dots, L_{k/2}$ 為最大的 $k/2$ 個數的索引,而 $S_1, S_2, \dots, S_{k/2}$ 為最小的 $k/2$ 個數的索引。我們首先對索引為 $L_1 \sim L_{k/2}$ 的數進行排序,然後對索引為 $S_1 \sim S_{k/2}$ 的數進行排序。

這裡有一個具體的例子;假設排列為 $p = \{2, 5, 7, 1, 8, 6, 4, 3\}$。如果我們呼叫 FakeSort(2,7):

  • $k = r - l + 1 = 6$。連續子序列 $p_l, p_{l+1}, \dots, p_r$ 為 $\{5, 7, 1, 8, 6, 4\}$;我們將獨立地對該序列中最大的 $3$ 個數與最小的 $3$ 個數進行排序。
  • $p = \{2, 5, \mathbf{7}, 1, \mathbf{8}, \mathbf{6}, 4, 3\}$;最大的 $3$ 個數已加粗。排序後,它們變為 $p = \{2, 5, \mathbf{6}, 1, \mathbf{7}, \mathbf{8}, 4, 3\}$。
  • $p = \{2, \mathbf{5}, 6, \mathbf{1}, 7, 8, \mathbf{4}, 3\}$;最小的 $3$ 個數已加粗。排序後,它們變為 $p = \{2, \mathbf{1}, 6, \mathbf{4}, 7, 8, \mathbf{5}, 3\}$。

因此,$p = \{2, 5, 7, 1, 8, 6, 4, 3\}$ 在執行 FakeSort(2,7) 後變為 $\{2, 1, 6, 4, 7, 8, 5, 3\}$。

請使用不超過 $114$ 次操作對該排列進行排序,或者判斷其不可能被排序。可以證明,如果一個排列可以透過此操作進行排序,則一定存在一種使用不超過 $114$ 次操作的方法。

輸入格式

輸入包含多組測試資料。輸入的第一行包含一個整數 $T$($1 \le T \le 10^3$),表示測試資料的組數。

對於每組測試資料,第一行包含一個偶數 $n$($4 \le n \le 10^5$),表示排列的長度。

第二行包含 $n$ 個整數 $p_1, p_2, \dots, p_n$($1 \le p_i \le n$),表示你需要排序的排列。保證 $p$ 是一個排列。

保證所有測試資料中 $n$ 的總和不超過 $2 \times 10^5$。

輸出格式

對於每組測試資料,如果無法對該排列進行排序,請輸出 $-1$。

否則,輸出一個整數 $k$($0 \le k \le 114$),表示所使用的操作次數。

在接下來的 $k$ 行中,每行輸出 $l, r$($1 \le l \le r \le n$,且 $r - l + 1$ 為偶數),表示執行一次 FakeSort(l,r)。

範例

範例輸入 1

3
4
2 1 4 3
6
3 6 5 1 2 4
8
3 2 1 7 5 4 6 8

範例輸出 1

1
1 4
-1
2
4 7
1 6

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1071EditorialOpenNew Editorial for Problem #15316ZnPdCoView

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.