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;
#define ll long long
#define endl '\n'
#define dbg(x) cout << (#x) << " = " << x << endl
const ll maxn = 2e5 + 69;
ll a[maxn],b[maxn],n;
map<ll,ll> cnt,pre;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1;i<=n;i++){
cin >> a[i];
b[i] = a[i];
if(cnt[a[i]] == 0) cnt[a[i]] = i;
if(cnt[a[i]]) pre[a[i]] = i;
}
ll pt = 1;
while(pt <= n){
if(pre[a[pt]]){
ll temp = pt;
while(pt != pre[a[temp]]){
b[pt] = a[temp];
pt++;
}
b[pt] = a[temp];
pt++;
}else pt++;
}
for(int i = 1;i<=n;i++) cout << b[i] << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |