Drugs @ 2022-01-18 21:47:23
#include<iostream>
#include<stack>
using namespace std;
stack <int> a;
int q;
int u[100001];
int n;
int p[100001];
int s[100002];
int i, j, k, b;
int main()
{
cin>>q;
for(i=0;i<q;++i)
{
cin>>n;
for(j=0;j<n;++j)
{
cin>>u[j];
}
for(j=0;j<n;++j)
{
cin>>p[j];
}
k=0;
for(j=0;j<n;++j)
{
a.push(u[j]);
while(a.top()==p[k])
{
a.pop();
k++;
if(a.empty())
break;
}
}
if(a.empty())
{
s[i]=1;
b++;
}
else
{
s[i]=0;
b++;
}
}
for(i=0;i<b;++i)
{
if(s[i]==1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
by Drugs @ 2022-01-18 22:01:12
A了,没有清空栈。