CF1364C.Ehab and Prefix MEXs

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given an array aa of length nn, find another array, bb, of length nn such that:

  • for each ii (1≤i≤n)(1 \le i \le n) MEX({b_1, b2b_2, …\ldots, b_i})=a_i.

The MEXMEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.

If such array doesn't exist, determine this.

给定一个长度为 nn 的数组 aa,请构造另一个长度为 nn 的数组 bb,使得:

  • 对每个 ii(1≤i≤n1 \le i \le n),均有 MEX({b_1, b2b_2, …\ldots, b_i})=a_i。

一个整数集合的 MEXMEX(minimum excluded value)是指不属于该集合的最小非负整数。

若不存在满足条件的数组 bb,请判定这一点。

输入格式

The first line contains an integer nn (1≤n≤1051 \le n \le 10^5) — the length of the array aa.

The second line contains nn integers a1a_1, a2a_2, …\ldots, ana_n (0≤ai≤i0 \le a_i \le i) — the elements of the array aa. It's guaranteed that ai≤ai+1a_i \le a_{i+1} for 1≤i<n1\le i \lt n.

第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 数组 aa 的长度。

第二行包含 nn 个整数 a1a_1, a2a_2, …\ldots, ana_n(0≤ai≤i0 \le a_i \le i)—— 数组 aa 的元素。保证对所有 1≤i<n1\le i \lt n,有 ai≤ai+1a_i \le a_{i+1}。

输出格式

If there's no such array, print a single line containing −1-1.

Otherwise, print a single line containing nn integers b1b_1, b2b_2, …\ldots, bnb_n (0≤bi≤1060 \le b_i \le 10^6)

If there are multiple answers, print any.

如果不存在这样的数组,输出一行,包含 −1-1。

否则,输出一行,包含 nn 个整数 b1b_1, b2b_2, …\ldots, bnb_n(满足 0≤bi≤1060 \le b_i \le 10^6)。

如果有多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    1 2 3

    输出#1

    0 1 2
  • 输入#2

    4
    0 0 0 2

    输出#2

    1 3 4 0
  • 输入#3

    3
    1 1 3

    输出#3

    0 2 1

说明/提示

In the second test case, other answers like [1,1,1,0][1,1,1,0], for example, are valid.

在第二个测试用例中,其他答案(例如 [1,1,1,0][1,1,1,0])也是有效的。

输入解题思路,AI测评打分。不知道怎么写?

首页