<span>AcWing 830. 单调栈</span>

AcWing 830. 单调栈


#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n;
int stk[N],tt;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        while(tt&&stk[tt]>=x) tt--;
        if(tt) cout<<stk[tt]<<' ';
        else cout<<-1<<' ';
        stk[++tt]=x;
    }
    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务