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;
unordered_map <int, int> mp;
stack <pair<int, pair<int, int>>> s;
for (int i=0; i<n; i++) {
int a;
cin >> a;
if (mp[a] == 0) {
if (s.size() && s.top().first == a) {
pair <int, pair<int, int>> p = s.top();
s.pop();
p.second.second++;
s.push(p);
} else {
mp[a] = i+1;
s.push({a, {i, i}});
}
} else {
while (s.size()) {
if ((s.top()).second.first <= mp[a]-1 && (s.top().second.second) >= mp[a]-1) {
pair <int, pair<int, int>> p = s.top();
s.pop();
p.second.second = i;
s.push(p);
break;
} else {
if (mp[(s.top()).first]-1 == (s.top()).second.first) mp[(s.top()).first]=0;
s.pop();
}
}
}
}
vector <pair<int, pair<int, int>>> v;
while (s.size()) {
v.push_back(s.top());
s.pop();
}
reverse(v.begin(), v.end());
for (auto it : v) {
for (int i=it.second.first; i<=it.second.second; i++) {
cout << it.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... |