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() {
int n;
cin >> n;
vector<pair<int, int>> S;
set<int> in_stack;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (in_stack.count(x)) {
while (S.back().first != x) {
in_stack.erase(S.back().first);
S.pop_back();
}
} else {
in_stack.insert(x);
S.emplace_back(x, i);
}
}
S.emplace_back(-1, n);
for (int i = 0; i < (int)S.size() - 1; i++) {
for (int j = S[i].second; j < S[i + 1].second; j++) {
cout << S[i].first << "\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... |