QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 512 MB 총점: 100

#16527. 排列之和

통계

畀定一個 $1\sim n$ 嘅排列 $p$。

你要構造一個長度係 $n$ 嘅序列 $a$,滿足:

  • 序列 $a$ 入面每個元素都係唔大過 $n$ 嘅正整數;
  • 唔存在有序整數二元組 $(l,r)$,滿足 $1 \le l \le r \le n$ 而且 $\sum\limits_{i=l}^r a_i=\sum\limits_{i=l}^r p_i$;

或者報告冇解。

當中,$1\sim n$ 嘅排列係指所有唔大過 $n$ 嘅正整數都啱啱出現一次嘅序列。

輸入格式

呢題有多組測試數據。

第一行輸入一個整數 $T$,表示測試數據嘅組數。

之後依次輸入每組測試數據。對於每組測試數據:

  • 第一行輸入一個整數 $n$。
  • 第二行輸入 $n$ 個整數,表示畀定嘅排列 $p$。

輸出格式

對於每組數據,輸出一行:

  • 如果存在滿足條件嘅序列 $a$,就輸出用空格分隔嘅 $n$ 個整數,表示你構造嘅序列 $a$;
  • 如果唔存在滿足條件嘅序列 $a$,就輸出 $-1$。

任何滿足要求嘅輸出都會獲接納。

樣例

輸入格式 1

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

輸出格式 1

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

說明

對於第 $1$ 組數據,$\{1,3,3\}$ 同 $\{1,1,3\}$ 都係滿足條件嘅序列 $a$。

對於第 $2$ 組數據,可以證明唔存在滿足條件嘅序列 $a$。

對於第 $3$ 組數據,除咗 $\{5,3,2,1,1 \}$,$\{3,4,5,3,2 \}$、$\{1,4,5,3,4 \}$、$\{5,3,3,4,5\}$ 等都係滿足條件嘅序列 $a$。

數據範圍

設 $\sum n$ 表示單個測試點入面 $n$ 嘅總和。

對於所有數據,$1 \le T \le 5000$,$2 \le n \le 10^6$,$\sum n \le 10^6$,保證 $p$ 係 $1\sim n$ 嘅排列。

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.