
#include<iostream>
using namespace std;
const int N=1e5+10;
int sk[N],top;
int main(){
int n;cin>>n;
while(n--){
int x;cin>>x;
while(top&&sk[top]>=x)top--;
if(!top)cout<<"-1"<<" ";
else cout<<sk[top]<<" ";
sk[++top]=x;
}
return 0;
}
原创
acwing830. 单调栈
本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。