您的位置:首页 > 其它

拓展:单调栈

2020-02-02 19:45 155 查看

传送门:单调栈

板子:

#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;
}
  • 点赞
  • 收藏
  • 分享
  • 文章举报
〆℡小短腿走快点ゝ 发布了30 篇原创文章 · 获赞 1 · 访问量 1413 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: