单调栈

时间:2022-05-27 22:39:24   收藏:0   阅读:25

#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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!