#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int N = 200005;
struct com{
bool operator()(const pair<ll,ll>&a,const pair<ll,ll>&b)const{
if(a.second==b.second)return a.first<b.first;
else return a.second<b.second;
}
};
set<pair<ll,ll>,com>st;
map<int,int>in;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;cin>>n;
ll x;cin>>x;
st.insert({x,1});
in[x]=1;
for(int i=2;i<=n;i++){
ll x;cin>>x;
auto pos=st.find(make_pair(x,in[x]));
if(pos==st.end()){
st.insert({x,i});
in[x]=i;
// cout<<"f";
}
else{
while(!st.empty()&&(st.rbegin()->second)>(pos->second))st.erase(prev(st.end()));
}
// cout<<i<<endl;
// for(auto [x,y]:st){
// cout<<x<<" "<<y<<endl;
// }
// cout<<endl<<endl;
}
st.insert({-1,n+1});
int i=1;
for(auto it=st.begin();it!=prev(st.end());++it){
while(i<next(it)->second){cout<<it->first<<" ";i++;}
}
}
/*
6
1
2
1
2
3
2
*/
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |