WA on 1 2 3 4 5,蒟蒻求调

P4387 【深基15.习9】验证栈序列

02Ljh @ 2022-05-13 19:32:25

#include <bits/stdc++.h>
using namespace std;
int xy[114514];
bool flag[114514];
stack <int> q;
bool work(int n)
{
    while(!q.empty()) { q.pop(); }
    memset(xy,0,sizeof(xy));
    fill(flag,flag+114514,false);
    int l,pos=0;
    for(int i=0;i<n;i++)
    {
        cin>>xy[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>l;
        q.push(l);
        //cout<<pos<<endl;
        if(l==xy[pos])
        {
            while(!q.empty()&&xy[pos]==q.top())
            {
                if(!q.empty()&&xy[pos]==q.top())
                {
                    //cout<<q.top()<<" "<<o<<endl;
                    pos++;
                    q.pop();
                }
                else
                {
                    break;
                }               
            }
            //cout<<pos<<endl;
        }
    }
    if(q.empty()) return true;
    else return false;
}
int main()
{
    int t,n;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        if(work(n)) puts("Yes");
        else puts("No");
    }
    return 0;
}
/*
1
3
1 2 3
2 1 3
*/

|