有dalao帮我改改吗?改了好长时间都没过······
#include<bits/stdc++.h>
using namespace std;
int q,n;
int a[1000005],b[1000005];
int st[1000005];
int c[1000];
int main(){
cin>>q;
for(int i=1;i<=q;i++){
cin>>n;
int j=1,top=0;
for(int j=1;j<=n;j++){
cin>>a[j];
}
for(int j=1;j<=n;j++){
cin>>b[j];
}
for(int i=1;i<=n;i++){
st[++top]=a[i];
while(1){
if(st[top]!=b[j]) break;
top--;
j++;
if(top==0) break;
}
}
if(top==0) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}