QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#6108. Uporządkowanie permutacji

Statistics

Dana jest tablica $a$ o długości $N$. Każdy element $a$ jest równy $-1$ lub jest liczbą całkowitą z przedziału od $1$ do $N$. Każda liczba z przedziału od $1$ do $N$ występuje w $a$ co najwyżej raz. Ponadto żadne dwa sąsiednie elementy $a$ nie różnią się dokładnie o $1$.

Należy znaleźć leksykograficznie najmniejszą permutację $p$ zbioru $\{1, 2, \dots, N\}$ spełniającą następujące warunki:

  • jeśli $a_i \neq -1$, to $a_i = p_i$ dla $1 \leq i \leq N$;
  • $|p_i - p_{i+1}| \neq 1$ dla $1 \leq i \leq N - 1$.

Wejście

W pierwszej linii znajduje się jedna liczba całkowita $N$. W drugiej linii znajduje się $N$ liczb całkowitych oddzielonych spacjami: elementy tablicy $a$.

  • $1 \leq N \leq 200\,000$
  • $1 \leq a_i \leq N$ lub $a_i = -1$ dla $1 \leq i \leq N$
  • $a_i \neq a_j$ lub $a_i = -1$ dla $1 \leq i < j \leq N$
  • $|a_i - a_{i+1}| \neq 1$ dla $1 \leq i \leq N - 1$

Wyjście

Jeśli nie istnieje permutacja $p$ spełniająca warunki, wypisz jedną liczbę całkowitą $-1$. W przeciwnym razie wypisz leksykograficznie najmniejszą permutację $p$.

Przykład

Wejście 1

10
3 -1 10 -1 8 -1 -1 -1 -1 -1

Wyjście 1

3 1 10 2 8 4 6 9 5 7

Wejście 2

2
-1 -1

Wyjście 2

-1

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.