This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
map <int, int> mp, mp2;
int a[N], b[N];
int n;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
//cout << n << " MF\n";
for (int i = 1; i <= n; i++){
cin >> a[i];
mp[a[i]]++;
mp2[a[i]] = max(mp2[a[i]], i);
}
for (int i = 1; i <= n; i++){
//cout << i << ' ' << n << " MF\n";
if (mp[a[i]] > 1 && i != mp2[a[i]]){
for (int j = i+1; j <= n; j++){
if (a[j] == a[i]){
i = j;
break;
}
mp[a[i]]++;
mp[a[j]]--;
a[j] = a[i];
}
i--;
}
}
//cout << n << " MF\n";
for (int i = 1; i <= n; i++){
cout << a[i] << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |