求助QZ
查看原帖
求助QZ
377876
lbc20070331楼主2023/8/13 20:39
#include<bits/stdc++.h>
using namespace std;
int t;
int n;
int main()
{
	cin>>t;
	while(t--)
	{
		stack<int> in,out;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			int x;
			cin>>x;
			in.push(x);
		}
		for(int i=1;i<=n;i++)
		{
			int x;
			cin>>x;
			out.push(x);
			while(true)
			{
				if(in.top()==out.top()) out.pop(),in.pop();
				if(in.size()==0 || out.size()==0 || in.top()!=out.top()) break;
			}
		}
		if(out.size()!=0 || in.size()!=0) cout<<"No"<<"\n";
		else cout<<"Yes"<<"\n";
	}
	return 0;
}
2023/8/13 20:39
加载中...