我不知道自己哪里有错,求助!

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

ML_Ravenclaw @ 2022-07-11 17:05:23

Segmentation Fault了

#include <bits/stdc++.h>
using namespace std;
int t;
int main()
{
    cin>>t;
    while(t--)
    {
        stack<long long>c;
        long long n,a[100010]={0},b;
        cin>>n;
        for(int i = 1;i<=n;i++)
        {
            cin>>a[i];
        }
        int k=0;
        bool f = 1;
        for(int i = 1;i<=n;i++)
        {
            cin>>b;
            if(c.top()==b)c.pop();
            else
            {
                while(c.top()!=b&&k<=n)c.push(a[++k]);
                if(c.top()!=b)
                {
                    cout<<"No\n";
                    f=0;
                    break;
                }
                else c.pop();
            }
        }
        if(f==1)cout<<"Yes\n";
    }
    return 0;
}

|