Universal Cup Judging System

Universal Cup

시간 제한: 1.0 s 메모리 제한: 1024 MB 총점: 100
통계

喺 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.