This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct node{
int s, e, m, val, lz;
node *l, *r;
node(int _s, int _e){
s = _s, e = _e, m = (s + e) >> 1;
if(s != e)l = new node(s, m), r = new node(m+1, e);
val = lz= 0 ;
}
void prop(){
if(lz){
val = lz;
if(s != e)l->lz = lz, r->lz = lz;
lz = 0;
}
}
void upd(int a, int b, int c){
prop();
if(a == s && b == e)lz = c;
else{
if(b <= m)l->upd(a, b, c);
else if(a > m)r->upd(a, b, c);
else l->upd(a, m, c), r->upd(m+1, b, c);
l->prop(), r->prop();
}
}
int qry(int x){
prop();
if(s == e)return val;
if(x <= m)return l->qry(x);
else return r->qry(x);
}
}*root;
void solve(){
int n; cin >> n;
map <int, vector <int> > mp;
root = new node(1, n);
for(int i = 1; i <= n; i++){
int x; cin >> x;
root->upd(i, i, x);
while(!mp[x].empty() && root->qry(mp[x].back()) != x)mp[x].pop_back();
if(!mp[x].empty()){
root->upd(mp[x].back(), i, x);
}
mp[x].push_back(i);
}
for(int i = 1; i <= n; i++)cout << root->qry(i) << ' ';
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message (stderr)
Main.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
63 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |