#include<bits/stdc++.h>
using namespace std;
stack<int> p;
int a[100010];
int b[100010];
int main()
{
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
while(!p.empty()) p.pop();
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
cin>>b[i];
}
int cut=1;
for(int i=1;i<=n;i++)
{
p.push(a[i]);
while(!p.empty()&&p.top()==b[cut])
{
p.pop();
cut++;
}
}
if(!p.empty())
{
cout<<"No"<<endl;
}else
{
cout<<"Yes"<<endl;
}
}
return 0;
}
STL-栈
最新推荐文章于 2024-07-18 10:21:10 发布