This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define ld long double
#define pb push_back
using namespace std;
using ll=long long;
const int MN = 2e5+5;
const int mod = 1e9+7;
const int inf = 1e18;
int n,a[MN];
map<int,int> cnt;
inline void solve() {
cin>>n;
for (int i=1; i<=n; i++) {
cin>>a[i];
}
for (int i=1; i<=n; i++) {
cnt[a[i]]++;
if(cnt[a[i]]>1) {
// cout<<i<<" ";
for (int j=i-1; j>=1; j--) {
// cout<<j<<" ";
if(a[j]==a[i]) break;
cnt[a[j]]--;
cnt[a[i]]++;
a[j]=a[i];
}
// cout<<endl;
}
}
for (int i=1; i<=n; i++) {
cout<<a[i]<<"\n";
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
// cin>>t;
while(t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |