题目描述
输入输出样例
示例
输入
5
2 1 1 3 4
输出
2 1 3 4 5
运行限制
最大运行时间:1s
最大运行内存: 256M
参考代码
import java.util.Scanner;
public class Main {
static int[] f = new int[1000010];
static int[]arr= new int[100010];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
for (int i = 1; i <= 1000003; i++) {
f[i] = i;
}
for (int i = 0; i < n; i++) {
arr[i]=find(sc.nextInt());
f[arr[i]]=find(arr[i]+1);
}
for (int i = 0; i < n; i++) {
System.out.print(arr[i]+" ");
}
sc.close();
}
static int find( int x) {
if (f[x]!=x) {
f[x]=find(f[x]);
}
return f[x];
}
}