#include <bits/stdc++.h>
using namespace std;
signed main(){
int n; cin >> n;
vector <int> a(n);
for ( auto &u: a ) cin >> u;
stack <array<int,3>> stk;
stk.push({-1, 0, -1});
map <int,int> cnt;
for ( int i = 0; i < n; i++ ){
if ( cnt[a[i]] ){
while ( stk.top()[0] != a[i] ){
auto [v, l, r] = stk.top(); stk.pop();
cnt[v] -= 1;
}
stk.top()[2] = i;
} else{
stk.push({a[i], i, i});
cnt[a[i]] = 1;
}
}
vector <int> val(n);
while ( !stk.empty() ){
auto [v, l, r] = stk.top(); stk.pop();
for ( int i = l; i <= r; i++ ) val[i] = v;
}
for ( auto &x: val ) cout << x << '\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... |