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>
#define int long long
#define X first
#define Y second
using namespace std;
signed main(){
int n;
cin >> n;
vector< int > v(n + 1);
map<int, int> cnt;
multiset< pair<int, int> > s;
for(int i = 1; i <= n; ++i){
cin >> v[i];
int id = i;
while(cnt[v[i]]){
auto it = prev(s.end());
--cnt[v[it->Y]];
id = it->X;
s.erase(it);
}
++cnt[v[i]];
s.insert({id, v[i]});
}
int now = n;
while(!s.empty()){
auto it = prev(s.end());
for(; now >= it->X; --now){
v[now] = it->Y;
}
s.erase(it);
}
for(int i = 1; i <= n; ++i) cout << v[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... |