#include <iostream>
using namespace std;
const int N=10010;
int stk[N],tt;
int n,x;
int main()
{
cin>>n;
while(n--)
{
cin>>x;
while(tt&&stk[tt]>=x) tt--;
if(tt) cout<<stk[tt]<<" ";
else cout<<"-1"<<" ";
stk[++tt]=x;
}
return 0;
}
原文:https://www.cnblogs.com/xiao--yang/p/15345228.html