题目链接
思路:
推导出数组b的各个元素,若不存在数组b,则输出-1.
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=2e5+7;
const int mod=1e9+7;
const int inf=0x7fffffff;
const double pi=3.1415926535;
using namespace std;
const int N=1e5+6;
map<int,int> mp;
set<int> b;
int a[N];
signed main()
{int n;cin>>n;for(int i=0;i<n;i++){cin>>a[i];mp[a[i]]++;}for(int i=0;i<=2*n;i++){if(mp[i]==0){b.insert(i);}}for(int i=0;i<n;i++){if(i&&a[i]!=a[i-1]){b.insert(a[i-1]);}cout<<*b.begin()<<" ";b.erase(*b.begin());}return 0;
}