题意:通过数组a构建数组b;其中ai是MEX(b1~bi);
思路:假如两个数字不同那么第i号元素一定是i-1号元素;
假如相同的话;只需要从小到大一直添加即可;
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <vector>
using namespace std;
const int N = 200010;
typedef long long ll;
int a[N];
int vis[N];
inline int read() {
int date = 0, w = 1; char c = 0;
while (c < '0' || c > '9') {if (c == '-')w = -1; c = getchar();}
while (c >= '0' && c <= '9') {date = date * 10 + c - '0'; c = getchar();}
return date * w;
}
inline void out(int x) {
if (x < 0) {putchar('-'); x = -x;}
if (x > 9) out(x / 10);
putchar(x % 10 + '0');
}
#define x first
#define y second
int main() {
int n = read();
vector<int> v;
vector<int>b;
for (int i = 1; i <= n; i++) a[i] = read(), vis[a[i]]++;
for (int i = n; i >= 0; i--) if (!vis[i]) v.push_back(i);
a[0] = a[1];
for (int i = 1; i <= n; i++) {
if (a[i] != a[i - 1]) b.push_back(a[i - 1]);
else b.push_back(v.back()), v.pop_back();
}
for (auto i : b) out(i), cout << " ";
return 0;
}