#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 210000;
int n, a[N];
map<int, bool> mp;
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
stack<int> st;
for (int i = 1; i <= n; i++) {
if (mp[a[i]]) {
while (a[st.top()] != a[i]) {
mp[a[st.top()]] = false;
st.pop();
}
} else {
mp[a[i]] = true;
st.push(i);
}
}
for (int i = n; i >= 1; i--) {
while (st.top() > i)
st.pop();
a[i] = a[st.top()];
}
for (int i = 1; i <= n; i++)
cout << a[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... |