Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
程序员文章站
2022-10-03 17:38:56
题目链接思路:推导出数组b的各个元素,若不存在数组b,则输出-1.代码:#includeusing 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...
题目链接
思路:
推导出数组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;
}
本文地址:https://blog.csdn.net/ACkingdom/article/details/107394707
下一篇: Java 提取汉字的首字母、拼音
推荐阅读
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
-
Codeforces Round #658 (Div. 2)C1. Prefix Flip (Easy Version)(贪心)
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
-
Codeforces Round #658 (Div. 2)C1. Prefix Flip (Easy Version)(贪心)