CF1364C.Ehab and Prefix MEXs
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an array a of length n, find another array, b, of length n such that:
- for each i (1≤i≤n) MEX({b_1, b2, …, b_i})=a_i.
The MEX 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.
给定一个长度为 n 的数组 a,请构造另一个长度为 n 的数组 b,使得:
- 对每个 i(1≤i≤n),均有 MEX({b_1, b2, …, b_i})=a_i。
一个整数集合的 MEX(minimum excluded value)是指不属于该集合的最小非负整数。
若不存在满足条件的数组 b,请判定这一点。
输入格式
The first line contains an integer n (1≤n≤105) — the length of the array a.
The second line contains n integers a1, a2, …, an (0≤ai≤i) — the elements of the array a. It's guaranteed that ai≤ai+1 for 1≤i<n.
第一行包含一个整数 n(1≤n≤105)—— 数组 a 的长度。
第二行包含 n 个整数 a1, a2, …, an(0≤ai≤i)—— 数组 a 的元素。保证对所有 1≤i<n,有 ai≤ai+1。
输出格式
If there's no such array, print a single line containing −1.
Otherwise, print a single line containing n integers b1, b2, …, bn (0≤bi≤106)
If there are multiple answers, print any.
如果不存在这样的数组,输出一行,包含 −1。
否则,输出一行,包含 n 个整数 b1, b2, …, bn(满足 0≤bi≤106)。
如果有多个答案,输出任意一个即可。
输入输出样例
输入#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], for example, are valid.
在第二个测试用例中,其他答案(例如 [1,1,1,0])也是有效的。
输入解题思路,AI测评打分。不知道怎么写?