QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#17424. 增减

Estadísticas

给你两个长度为 $N$ 的序列 $A$ 和 $B$。

对于所有 $i$ ($1 \le i \le N$),确定是否存在一个 $(1, 2, \dots, N)$ 的排列 $C$,满足其长度为 $i$ 的前缀的最长上升子序列(LIS)长度为 $A_i$,且长度为 $i$ 的前缀的最长下降子序列(LDS)长度为 $B_i$。

如果存在这样的排列,请构造一个。

输入格式

输入格式如下:

$$N$$ $$A_1\ A_2\ \dots\ A_N$$ $$B_1\ B_2\ \dots\ B_N$$

数据范围

  • $1 \le N \le 5 \times 10^5$
  • $1 \le A_i \le N$ ($1 \le i \le N$)
  • $1 \le B_i \le N$ ($1 \le i \le N$)
  • 所有输入值均为整数

输出格式

如果不存在这样的排列,输出 $-1$。否则,输出 $N$ 个空格分隔的整数,表示排列 $C$ 的元素。如果存在多个满足条件的排列,输出其中任意一个即可。

样例

输入样例 1

3
1 1 2
1 2 2

输出样例 1

2 1 3

输入样例 2

4
1 1 2 2
1 2 2 3

输出样例 2

3 2 4 1

输入样例 3

4
1 2 2 3
1 2 2 2

输出样例 3

-1

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1488EditorialOpen题解jiangly2026-04-09 18:07:06View

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.