题目链接-------------------------------------------------
题解:
先对原数列按照从小到大的位置进行排序,并且记录下原来的位置,然后确保新的数列中对应位置上的数为原数列当前数字和未使用过的1-n这些数中最小数字的最大值
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include <algorithm>
using namespace std;
int n, i, now, a[310000], tx[310000], ans[310000];
bool cmp(int x, int y)
{
return a[x] < a[y];
}
int main()
{
scanf("%d", &n);
for (i = 1; i <=n; i++)
{
scanf("%d", &a[i]);
tx[i] = i;
}
sort(tx + 1, tx + n + 1, cmp);
for (i = 1; i <= n; i++)
{
now = max(now + 1, a[tx[i]]);
ans[tx[i]] = now;
}
for (i = 1; i <= n; i++)
{
printf("%d ", ans[i]);
}
printf("\n");
return 0;
}