QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 512 MB Puntuación total: 100

#8561. 还原排列

Estadísticas

给定一个正整数 $n$ 以及两个均包含 $n$ 个整数的数组 $a$ 和 $b$。

你需要找到一个长度为 $n$ 的排列 $p$,使得对于每个 $i \in \{1, 2, \dots, n\}$,以下两个条件均满足:

  • 以位置 $i$ 结尾的最长上升子序列的长度等于 $a_i$。
  • 从位置 $i$ 开始的最长下降子序列的长度等于 $b_i$。

输入格式

第一行包含一个正整数 $n$ ($1 \le n \le 2 \cdot 10^5$),表示排列的长度。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$,其中 $a_i$ ($1 \le a_i \le n$) 表示以位置 $i$ 结尾的最长上升子序列的长度。

第三行包含 $n$ 个整数 $b_1, b_2, \dots, b_n$,其中 $b_i$ ($1 \le b_i \le n$) 表示从位置 $i$ 开始的最长下降子序列的长度。

输出格式

输出一行,包含 $n$ 个由空格分隔的整数 $p_1, p_2, \dots, p_n$,即所求的排列。

题目保证解存在。如果存在多个解,你可以输出其中任意一个。

样例

样例输入 1

5
1 1 1 2 3
3 2 1 1 1

样例输出 1

3 2 1 4 5

样例输入 2

6
1 1 2 2 3 3
2 1 2 1 2 1

样例输出 2

2 1 4 3 6 5

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.