验证栈序列WA0分

#include<bits/stdc++.h>
using namespace std;
int t,n,a[100001],b[100001],ans,yes;
stackc;
int main(){
cin>>t;
for(int i=1;i<=t;i++){
cin>>n;
for(int j=c.size();j>=1;j–){
c.pop();
}
yes=1;
ans=0;
for(int j=1;j<=n;j++){
cin>>a[j];
}
for(int j=1;j<=n;j++){
cin>>b[j];
}
for(int j=1;j<=n;j++){
if(ans<n&&c.empty()){
ans++;
c.push(a[ans]);
}
if(b[j]!=c.top()){
if(ans==n){
cout<<"No "<<endl;
yes=0;
break;
}
for(int k=ans+1;k<=n+1;k++){
if(k==n+1){
cout<<"No "<<endl;
yes=0;
break;
}
ans++;
c.push(a[ans]);
if(c.top()==b[j]){
break;
c.pop();
}
}
if(yes==0){
break;
}
}
else{
c.pop();
}
}
if(yes==1){
cout<<"Yes "<<endl;
}
}
}