#include <bits/stdc++.h>
// Author: Kazuki_Will_Win_VOI_8703
#define fi first
#define se second
#define pii pair<int, int>
#define int long long
#define all(a) a.begin(), a.end()
using namespace std;
const int mn = 2e5 + 5, inf = 1e18;
int n, q, a[mn], w[mn], ans[mn];
map<int, int> on;
void solve(){
cin >> n;
stack <int> st;
for(int i = 1; i <= n; i++){
cin >> a[i];
if(!on[a[i]]){
on[a[i]] = i;
w[i] = 1;
st.push(i);
}
else{
while(st.size() && st.top() > on[a[i]]){
if(w[st.top()]){
w[st.top()] = 0;
on[a[st.top()]] = 0;
}
st.pop();
}
}
}
for(int i = n; i >= 1; i--){
if(st.top() > i) st.pop();
ans[i] = a[st.top()];
}
for(int i = 1; i <= n; i++) cout << ans[i] << "\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
while(t--) 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... |