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;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
set<pair<pair<int, int>, int>> segms;
map<int, vector<pair<int, int>>> vals;
for (int i = 0; i < n; ++i) {
if (vals[a[i]].empty()) {
segms.insert({{i, i + 1}, a[i]});
vals[a[i]].push_back({i, i + 1});
} else {
int start = vals[a[i]].back().first;
while (!segms.empty() && segms.rbegin()->first.first >= start) {
vals[segms.rbegin()->second].pop_back();
segms.erase(*segms.rbegin());
}
segms.insert({{start, i + 1}, a[i]});
vals[a[i]].push_back({start, i + 1});
}
}
for (auto [lr, val] : segms) {
for (int i = lr.first; i < lr.second; ++i) {
cout << val << '\n';
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
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... |