80分求助
查看原帖
80分求助
223620
Willan_Lian楼主2023/7/21 15:06

代码如下:

#include<bits/stdc++.h>
using namespace std;
stack <int > st;
int q,n;
int a[100010],b[100010];
int main(){
	scanf("%d",&q);
	while(q--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		for(int i=1;i<=n;i++)
			scanf("%d",&b[i]);
			
		int j=1;
		for(int i=1;i<=n;i++){
			st.push(a[i]);
			while (!st.empty() && st.top()==b[j])
				st.pop(),j++;
		}
		if(j==n+1) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}
2023/7/21 15:06
加载中...