当前位置: 代码迷 >> 综合 >> Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
  详细解决方案

Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs

热度:49   发布时间:2024-01-29 05:15:21.0

题目链接

思路:

推导出数组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;
}
  相关解决方案