单调栈.acwing.830

code:

#include<bits/stdc++.h>
using namespace std;
int a[100010],top;
int main()
{
    int n;
    cin>>n;
    a[0]=-1;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        while(top&&a[top]>=x)top--;
        printf("%d ",a[top]);
        a[++top]=x;
    }
    return 0;
}

 

posted @ 2020-12-25 16:13  纸上的彩虹  阅读(59)  评论(0)    收藏  举报