#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int a[n], odp[n];
for (int i = 0; i < n; i++)
cin >> a[i];
vector<pair<int,int>> v; multiset<int> ms;
v.push_back({0,a[0]}); ms.insert(a[0]);
for (int i = 1; i < n; i++) {
if (ms.find(a[i]) != ms.end()) {
while (v.back().second != a[i])
ms.erase(ms.find(v.back().second)), v.pop_back();
}
else
v.push_back({i,a[i]}), ms.insert(a[i]);
}
for (int i = n-1; i >= 0; i--) {
if (i < v.back().first)
v.pop_back();
odp[i] = v.back().second;
}
for (int i = 0; i < n; i++)
cout << odp[i] << endl;
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... |