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 \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)$이 조건을 만족함을 확인해 봅시다. 좋은 인덱스 쌍은 다음과 같이 4개가 있습니다:

$$(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.