#include using namespace std; #define ll long long #define FOR(i,n,m) for(int i=(n);i<(m);i++) #define REP(i,n) FOR(i,0,n) #define REPR(i,n) for(int i=(n);i>=0;i--) #define all(vec) vec.begin(),vec.end() using vi=vector; using vvi=vector; using vl=vector; using vvl=vector; using P=pair; using PP=pair; using Pl=pair; using PPl=pair; using vs=vector; #define fi first #define se second #define pb push_back templatebool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;} const ll MOD=1000000007LL; const int INF=1<<30; const ll LINF=1LL<<60; template struct LazySegTree{ //0-indexed 閉区間 using F=function; using G=function; using H=function; using P=function; int size; vector data; vector lazy; const F f; //要素同士の演算 const G g; //要素と作用素のマージ const H h; //作用素同士のマージ const P p; //作用素を下に降ろす const Monoid M1; //単位元 const OperatorMonoid OM0; //作用素の単位元 LazySegTree(int n,const F f,const G g,const H h,const P p,const Monoid &M1,const OperatorMonoid OM0) :f(f),g(g),h(h),p(p),M1(M1),OM0(OM0){ size=1; while(size=0;k--){ data[k]=f(data[2*k+1],data[2*k+2]); } } void propagate(int k,int len){ //長さlenのkから下へ伝播 if(lazy[k]!=OM0){ if(k=r){ //内部 lazy[k]=h(lazy[k],x); propagate(k,r-l+1); return data[k]; }else{ return data[k]=f(update(a,b,x,2*k+1,l,(l+r)/2), update(a,b,x,2*k+2,(l+r)/2+1,r)); } } Monoid update(int a,int b,const OperatorMonoid &x){ //[a,b]をxに変更 return update(a,b,x,0,0,size-1); } Monoid query(int a,int b,int k,int l,int r){ propagate(k,r-l+1); if(r=r){ return data[k]; }else{ return f(query(a,b,2*k+1,l,(l+r)/2), query(a,b,2*k+2,(l+r)/2+1,r)); } } Monoid query(int a,int b){ return query(a,b,0,0,size-1); } Monoid operator[](const int &k){ return query(k,k); } void debug(){ for(int i=0;i>n; map ma; REP(i,n){ int t; cin>>t; if(ma.find(t)==ma.end()){ ma[t]=P(i,i); }else{ ma[t]=P(min(ma[t].fi,i),max(ma[t].se,i)); } } auto f=[](int a,int b){ return max(a,b); }; auto g=[](int a,int b){ return b; }; auto p=[](int a,int b){ return a; }; LazySegTree tr(n,f,g,g,p,0,0); for(auto itr:ma){ tr.update(itr.se.fi,itr.se.se,itr.fi); } REP(i,n){ if(i)cout<<" ";cout<