galiyuebing @ 2021-08-13 14:49:04
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <stack>
using namespace std;
stack<int> a;
int n,q,j,k;
int b,in[100002],out[100002];
int main()
{
cin>>q;
for(int i=1;i<=q;i++)
{
cin>>n;
for(j=1;j<=n;j++)
{
cin>>in[j]; //输入
}
for(j=1;j<=n;j++)
{
cin>>out[j]; //输入
}
for(j=1,k=1;j<=n;j++)
{
a.push(in[j]); //读入栈
while(true)
{
if((a.top())==out[k])
{
k++;
a.pop();
}
else
break;
if(a.empty())
{
cout<<"Yes"<<endl;
break;
}
}
}
if(!a.empty())
{
cout<<"No"<<endl;
}
}
return 0;
}