40分蒟蒻求助!
查看原帖
40分蒟蒻求助!
846041
__xxy_free_ioi__楼主2023/5/26 20:43
#include <bits/stdc++.h>
using namespace std;
stack<int> s;
int q,n;
int a[100001],b[100001]; 
int main() {
	cin>>q;
	while(q--) {
		cin>>n;
		while(!s.empty()) s.pop(); 
		for(int i=1;i<=n;i++) cin>>a[i];
		for(int i=1;i<=n;i++) cin>>b[i];
		int j=1;
		for(int i=1;i<=2*n;i++) {
			if(s.empty()) s.push(a[i]);
			if(s.top()==b[j]) s.pop(),j++;
			else if(i<=n) s.push(a[i]);
		}
		if(s.empty()) printf("Yes\n");
		else printf("No\n");
	}
    return 0;
}

2023/5/26 20:43
加载中...