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 <iostream>
#include <deque>
#include <map>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
map<int, int> cnt;
deque<pair<int, int>> stones;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
pair<int, int> top = {a, 1};
if (cnt[a] > 0) {
while (true) {
auto [color, count] = stones.back();
stones.pop_back();
top.second += count;
cnt[color] -= count;
if (color == a)
break;
}
}
stones.push_back(top);
cnt[a] += top.second;
}
for (auto [a, cnt] : stones)
for (int i = 0; i < cnt; ++i)
cout << a << '\n';
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... |