#ifdef __GNUC__ #pragma GCC optimize ("O3") #pragma GCC target ("avx") #endif #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //assert(); #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) ///////// typedef long long LL; typedef long double LD; typedef unsigned long long ULL; #define PII pair ///////// using namespace::std; // 最大公約数 template inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);} // 最小公倍数 template inline T lcm(T a, T b){return a * b / gcd(a, b);} //////////////////////////////// class sgement{//range query int n;//要素数 int NUM_MAX; int NUM_NULL; vector dat;//4*n用意する。 public: int getNull(){return NUM_NULL;} void init(int N,int val_0,int val_null ){ NUM_MAX = val_0; NUM_NULL = val_null; dat = vector((N<<2)+2,NUM_MAX);//開区間 } /* flag:false L,true R */ int find(int t,int L,int R,int P,bool flag){ if( dat[t] != NUM_NULL ){ if( dat[t] == P ){ return flag==false?L:R; }else{ return NUM_NULL; } } int mid = (L+R)/2; int res; if( flag == false ){ res = find(t*2+0,L,mid,P,flag); if( res != NUM_NULL ){return res;} res = find(t*2+1,mid+1,R,P,flag); return res; }else{ res = find(t*2+1,mid+1,R,P,flag); if( res != NUM_NULL ){return res;} res = find(t*2+0,L,mid,P,flag); return res; } } void update(int t,int L,int R,int X,int Y,int VAL){ //親から子へ進んでいく if( L == X && R == Y){ dat[t] = VAL; }else{ int mid = (L+R)/2; if( dat[t] != NUM_NULL ){//値の伝播 dat[t*2+0] = dat[t]; dat[t*2+1] = dat[t]; dat[t] = NUM_NULL; } if( Y <= mid ){ update(t*2+0,L,mid,X,Y,VAL); }else if( X > mid ){ update(t*2+1,mid+1,R,X,Y,VAL); }else{ update(t*2+0,L,mid,X,mid,VAL); update(t*2+1,mid+1,R,mid+1,Y,VAL); } } } bool show(int t,int L,int R,bool flag){ if( dat[t] != NUM_NULL ){ if( flag == true ){printf(" ");} for(int i=L;i<=R;++i){ printf("%d",dat[t]); if( i+1 <= R){printf(" ");} } return true; }else{ int mid = (L+R)/2; bool res; res = show(t*2+0,L,mid,flag); res = show(t*2+1,mid+1,R,res); return res; } } }; inline void solve(){ int n; scanf("%d",&n); sgement seg,segB; seg.init(n,0,-1); segB.init(n,0,-1); vector s; map< int,vector > numMap; set< int > numSet; int A; for(int i=0;i::iterator itr,end; itr = numSet.begin(); end = numSet.end(); vector temp; for(;itr!=end;++itr){ now = *itr; temp = numMap[now]; sort(temp.begin(),temp.end()); size = temp.size(); segB.update(1,0,n-1,temp[0],temp[size-1],now); } segB.show(1,0,n-1,false); } signed main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); //std::cout << std::fixed;//小数を10進数表示 //cout << setprecision(16);//小数をいっぱい表示する。16? solve(); }