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;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<int> a(n), c;
for (int i = 0; i < n; i++) cin >> a[i];
c = a;
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
for (int i = 0; i < n; i++)
a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
vector<int> has(c.size());
vector<array<int, 3>> segs;
for (int i = 0; i < n; i++) {
if (!has[a[i]])
segs.push_back({i, i, a[i]});
else {
while (segs.back()[2] != a[i]) {
has[segs.back()[2]] = 0;
segs.pop_back();
}
segs.back()[1] = i;
}
has[a[i]] = 1;
}
for (auto [l, r, p] : segs)
for (int i = l; i <= r; i++) a[i] = c[p];
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... |