Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

問題文

整数 $N$ が与えられます。以下の条件を満たす、$(1, 2, \dots, N)$ を並び替えて得られる数列 $P = (p_1, p_2, \dots, p_N)$ が存在するか判定し、存在するならば実際に 1 つ構成してください。

ここで、整数の 3 つ組 $(i, j, k)$ であって $1 \le i < j < k \le N$ を満たすものを良い添字の組と呼ぶことにします。

  • $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 行に出力してください。条件を満たす数列が複数存在する場合は、どれを出力してもかまいません。

入力例

入力例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)$$

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