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;
#pragma GCC optimize("Ofast")
int n, a[310000];
int main () {
ios_base :: sync_with_stdio(false); cin.tie(0);
multiset <int> mst;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
mst.insert(a[1]);
vector <int> v = {1};
for (int i = 2; i <= n; i++) {
if (mst.find(a[i]) == mst.end()) {
mst.insert(a[i]);
v.push_back(i);
}
else {
while (v.size()) {
int j = v.back();
mst.erase(mst.find(a[j]));
v.pop_back();
if (a[j] == a[i]) break;
}
v.push_back(i);
mst.insert(a[i]);
}
}
int now = a[v . back()];
for (int i = n; i >= 1; i--) {
if (v.size() and i == v.back()) {
now = a[v.back()];
v.pop_back();
}
a[i] = now;
}
for (int i = 1; i <= n; i++) cout << a[i] << '\n';
return 0;}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |