一开始想到的是set上可去数字二分,写挂了,看了tag 提示是并查集 然后就好写了还是太菜了,一开始觉得特别像那个set维护mex..
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
#define int long long
const int N = 2e6+10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
int n;
int a[N];
int p[N];
int find(int x){
if(x!=p[x])p[x] = find(p[x]);
return p[x];
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=2e6;i++)p[i] = i;
for(int i=1;i<=n;i++){
int x = a[i];
cout<<find(x)<<" ";
int anc = find(x);
p[find(x)] = find(anc+1);
}
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _;
//cin>>_;
_ = 1;
while(_--)solve();
return 0;
}