传送门:单调栈
板子:
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
const int N=100010;
stack<int> st;
int main()
{
ios::sync_with_stdio(false);
int n,x;
cin>>n;
while(n--)
{
cin>>x;
while(st.size()&&st.top()>=x)
st.pop();
if(st.empty())
cout<<-1<<" ";
else
cout<<st.top()<<" ";
st.push(x);
}
return 0;
}