Universal Cup Judging System

Universal Cup

Süre Sınırı: 2.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

題目描述

給定一個整數 $N$。請判斷是否存在一個由 $(1, 2, \dots, N)$ 重新排列而成、且滿足以下條件的數列 $P = (p_1, p_2, \dots, p_N)$;若存在,請構造出其中一個。

在此,滿足 $1 \le i < j < k \le N$ 的整數三元組 $(i, j, k)$ 稱為好下標三元組。

  • 滿足 $p_i < p_j < p_k$ 的好下標三元組 $(i, j, k)$ 的個數,等於滿足 $p_i > p_j > p_k$ 的好下標三元組 $(i, j, k)$ 的個數。

若不存在滿足條件的數列,請輸出 $-1$。

將給定 $T$ 組測試資料,請分別求解每一組。

輸入格式

輸入由標準輸入以如下格式給出:

T
case_1
case_2
:
case_T

每組測試資料以如下格式給出:

N

資料範圍

  • $1 \le T \le 5 \times 10^5$
  • $3 \le N \le 5 \times 10^5$
  • 所有測試資料中 $N$ 的總和至多為 $5 \times 10^5$。
  • 輸入中的所有數值均為整數。

輸出格式

對於每組測試資料,若不存在滿足條件的數列,請輸出 $-1$;否則請在同一行以空白分隔輸出代表滿足條件的數列 $P$ 的 $N$ 個整數。若存在多個滿足條件的數列,輸出任意一個皆可。

範例

範例輸入1

2
3
4

範例輸出1

1 3 2
2 4 1 3

範例說明

範例 1 說明

當 $N = 3$ 時,驗證 $(1, 3, 2)$ 滿足條件。好下標三元組僅有 $(1, 2, 3)$。在 $(1, 3, 2)$ 中,滿足前者的好下標三元組有 $0$ 個,滿足後者的好下標三元組也有 $0$ 個。兩者個數相等,因此此數列滿足條件。

當 $N = 4$ 時,驗證 $(2, 4, 1, 3)$ 滿足條件。好下標三元組有以下四個:

$$(1, 2, 3), \ (1, 2, 4), \ (1, 3, 4), \ (2, 3, 4)$$

無論是前者或後者,皆無任何好下標三元組滿足,故個數皆為 $0$ 個。兩者個數相等,因此此數列滿足條件。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2545EditorialOpen题解KobicGendView
#1495EditorialOpen题解jianglyView
#1347EditorialOpen题解MilmonView

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.