QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100

#11699. 草图

Statistics

给定一个由整数 $a_1, \dots, a_n$ 组成的序列,考虑其所有长度为 $k$ 的非降子序列。在所有这些子序列中,取最后一个元素最小的那一个。我们将该元素的值记为 $s_k$。

序列 $s(a) = s_1, \dots, s_l$ 是序列 $a$ 的一个“草图”(sketch),其中 $l$ 是 $a$ 的最长非降子序列的长度。

构建序列的草图是一个标准任务,类似于寻找最长非降子序列的长度。在这里,我们考虑一个相反的问题:给定一个包含部分缺失项的草图,寻找任何能产生该草图的序列。

形式化地说,给定一个序列 $t_1, \dots, t_k$,其中每个元素要么是一个正整数,要么是 $-1$。你需要找到一个序列 $a_1, \dots, a_n$,使得每个元素都是 $1$ 到 $m$ 之间的整数(包含 $1$ 和 $m$),并满足以下性质:该序列的草图长度应等于 $k$,且对于 $1$ 到 $k$ 之间的每个索引 $i$,如果 $t_i \neq -1$,则必须满足 $s_i = t_i$。

输入格式

第一行包含三个整数 $k, n, m$ ($1 \le k \le 300\,000, 1 \le n \le 300\,000, 1 \le m \le 10^9$),分别表示草图的长度、目标序列的长度以及元素值的上限。

第二行包含 $k$ 个数 $t_1, \dots, t_k$ ($1 \le t_i \le m$ 或 $t_i = -1$),即草图本身。

输出格式

如果存在满足该草图的序列,输出目标序列的元素。如果存在多个答案,你可以输出其中任意一个。

如果不存在有效的序列,输出单个整数 $-1$。

样例

样例输入 1

3 4 10
3 7 7

样例输出 1

3 7 8 7

样例输入 2

3 5 10
3 -1 7

样例输出 2

3 6 5 4 7

样例输入 3

4 2 10
1 2 3 4

样例输出 3

-1

说明

样例 2 中答案序列的草图为:$3, 4, 7$。

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.