AcWing 830. 单调栈

时间:2020-07-29 15:07:47   收藏:0   阅读:84

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;
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!