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;
template<typename T>
bool assign_min(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<typename T>
bool assign_max(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
void solve() {
ll n;
cin >> n;
vector<pair<ll, ll>> arr;
set<ll> be;
for (ll i = 0; i < n; i++) {
ll x;
cin >> x;
if (be.find(x) != be.end()) {
ll nc = 1;
while (arr.back().first != x) {
be.erase(arr.back().first);
nc += arr.back().second;
arr.pop_back();
}
arr.back().second += nc;
continue;
}
be.insert(x);
arr.emplace_back(x, 1);
}
for (auto[x, c] : arr) {
for (ll i = 0; i < c; i++) {
cout << x << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |