C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1000001;
int a[N];
int judge(int x)
{
if(a[x]!=x)
a[x] = judge(a[x]);
return a[x];
}
int main()
{
int n,x;
cin >> n;
for(int i=1;i<=N;i++)
a[i] = i;
for(int i=1;i<=n;i++)
{
cin >> x;
x = judge(x);
cout << x << " ";
a[x] = x + 1;
}
return 0;
}