This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #cheat_when_I_was_young
// #cheatkhitacontre #khionhatoicheat
// #thaycuckythatvong
#include "bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
signed main() {
IOS;
int n;
stack<pair<int,int>> s;
map<int,int> cnt;
cin >> n;
while (n--) {
int x;
cin >> x;
++cnt[x];
if (cnt[x] == 1) {
s.push({x, 1});
continue;
}
int tmp = 1;
while (s.top().first != x) {
int a = s.top().first, b = s.top().second;
s.pop();
cnt[a] -= b;
cnt[x] += b;
tmp += b;
}
s.top().second += tmp;
}
vector<int> ans;
while (!s.empty()) {
int a = s.top().first, b = s.top().second;
s.pop();
for (int i = 0; i < b; ++i) ans.push_back(a);
}
reverse(ans.begin(), ans.end());
for (int &i: ans) cout << i << "\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... |