This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: wxhtzdy
* created: 12.02.2023 12:01:44
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
map<int, bool> mp;
vector<pair<int, int>> segs;
for (int i = 0; i < n; i++) {
if (mp[a[i]]) {
int s = 1;
while (segs.back().first != a[i]) {
mp[segs.back().first] = false;
s += segs.back().second;
segs.pop_back();
}
segs.back().second += s;
} else {
segs.emplace_back(a[i], 1);
mp[a[i]] = true;
}
}
for (auto& p : segs) {
while (p.second > 0) {
cout << p.first << '\n';
p.second--;
}
}
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... |