全WA了?(求调)
查看原帖
全WA了?(求调)
559506
BestFriend楼主2022/11/18 13:12
#include<bits/stdc++.h>
#pragma G++ optimize(2)
using namespace std;
typedef long long ll;
const int N = 1e5+7;
inline ll read()
{
    ll x=0;
    int f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
        x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(ll x)
{
    if(x<0)
        putchar('-'),x=-x;
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
    return;
}
ll n,stk[N],s,x;
signed main(){
    n=read();
    for(ll i=0;i<n;i++){
        x=read();
        while(s/*栈不是空的*/&&stk[s]>=x/*栈顶元素>=输入的元素*/){
            s--;
        }
        if(s){
            write(stk[s]),putchar(' ');
        }
        else{
            write(0),putchar(' ');
        }
        stk[++s]=x;
    }
    return 0;
}
2022/11/18 13:12
加载中...