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 int long long
signed main(){
ios::sync_with_stdio(false), cin.tie(0);
int n; cin >> n;
int a[n], id[n];
vector<int> v;
for(int i = 0; i < n; i++) cin >> a[i], v.push_back(a[i]);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for(int i = 0; i < n; i++) id[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
vector<vector<int>> pos(n);
vector<int> to(n, -1);
int cur = n, fin = 0;
for(int i = 0; i < n; i++){
while(pos[id[i]].size() && pos[id[i]].back() < fin && pos[id[i]].back() > cur) pos[id[i]].pop_back();
if(pos[id[i]].size()) to[i] = pos[id[i]].back(), cur = to[i], fin = i;
pos[id[i]].push_back(i);
}
for(int i = n - 1; i >= 0; i--){
if(to[i] == -1) continue;
for(int j = i; j >= to[i]; j--) a[j] = a[i];
i = to[i];
}
for(int i = 0; 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... |