#include #include #include #include using namespace std; int main(){ int n;cin>>n; map> A; for(int i = 0; n > i; i++){ int t;cin>>t; if(!A[t].first){ A[t].first = i+1; } A[t].second = i+1; } vector ret[n+1],ans(n); for(auto x: A){ ret[x.second.first-1].push_back(x.first); ret[x.second.second].push_back(-x.first); } priority_queue C; priority_queue eraser; for(int i = 0; n > i; i++){ for(int j = 0; ret[i].size() > j; j++){ if(ret[i][j]>0){ C.push(ret[i][j]); }else if(ret[i][j] < 0){ eraser.push(-1*ret[i][j]); } } while(C.size() && eraser.size() && C.top() == eraser.top()){ C.pop(); eraser.pop(); } ans[i] = C.top(); } for(int i = 0; n > i; i++){ cout << ans[i]; if(i+1 != n)cout << " "; } cout << endl; }