UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211507#1689. 合法的出栈序列zhoushouchenCompile Error//C++992b2024-08-12 11:21:462024-08-12 11:21:49

answer

#include<iostream>
#include<cstdio>
#include<cmath>
#include<stack>

inline int read()
{
    int r,s=0,c;
    for(;!isdigit(c=getchar());s=c);
    for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);
    return s^45?r:-r;
}

const int N=1000010;

int main()
{
    int n=read(),m=read();
    while(m--)
    {
        std::stack<int> st{};
        int pos=0;
        bool flag=0;
        for(int i=1;i<=n;++i)
        {
            int f=read();
            if(flag)
                continue;
            if(f>pos)
            {
                while(pos<f)
                    st.push(++pos);
                st.pop();
            }
            else
            {
                if(st.empty()||st.top()!=f)
                {
                    puts("NO");
                    flag=1;
                }
                else
                    st.pop();
            }
        }
        if(!flag)
            puts("YES");
    }



    return 0;
}

详细

answer.code: In function 'int main()':
answer.code:21:25: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
         std::stack<int> st{};\x0d
                         ^
answer.code:21:28: error: in C++98 'st' must be initialized by constructor, not by '{...}'
         std::stack<int> st{};\x0d
                            ^