#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
set<int> colors;
vector<pair<int, int>> starts;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (colors.find(x) != colors.end()) {
while (starts.back().first != x) {
colors.erase(starts.back().first);
starts.pop_back();
}
} else {
colors.insert(x);
starts.push_back({x, i});
}
}
vector<int> ans(n, -1);
for (auto [col, pos]: starts) {
ans[pos] = col;
}
for (int i = 0; i < n; ++i) {
if (ans[i] == -1) ans[i] = ans[i - 1];
cout << ans[i] << '\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... |