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;
typedef long long ll;
#define all(x) begin(x), end(x)
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<pair<int, int>> stones;
unordered_map<int, int> freq;
for (int i = 0; i < n; i++) {
int to_add = 1;
if (freq[a[i]] > 0) {
while (stones.back().first != a[i]) {
to_add += stones.back().second;
freq[stones.back().first] -= stones.back().second;
stones.pop_back();
}
}
if (stones.empty() || stones.back().first != a[i]) {
stones.push_back({a[i], 0});
}
stones.back().second += to_add;
freq[a[i]] += to_add;
}
for (auto p : stones) {
for (int i = 0; i < p.second; i++) {
cout << p.first << ' ';
}
}
cout << '\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... |