0pts求助,样例过了
查看原帖
0pts求助,样例过了
933414
User_10_noob楼主2024/10/4 20:16
#include<bits/stdc++.h>
#define rep(a,b,c) for (int i=a;i<=b;i+=c)
using namespace std;
inline void read (int &n){
	n=0;
	char c;
	do{
		c=getchar();
	}while (c<'0'||c>'9');
	while (c>='0'&&c<='9'){
		n=(n<<1)+(n<<3)+(c^48);
		c=getchar();
	}
}
const int N=1e5+5;
int a[N],b[N];
stack<int>s;
int main(){
	int q,n;
	read(q);
	while (q--){
		read(n);
		int cnt=0;
		rep(1,n,1) read(a[i]);
		rep(1,n,1) read(b[i]);
		rep(1,n,1){
			while (cnt<n&&a[cnt]!=b[i]){//碰到与poped不相等的数就压入栈,直到相等或栈满
				s.push(a[++cnt]);
			}
			if (b[i]==s.top()) s.pop();
			else {printf("No\n");goto skip;}//数取不出来
		}
		printf("Yes\n");
		skip://用goto压行
		while (!s.empty()) s.pop();//处理完一组数据后清空栈
	}
	return 0;
}
2024/10/4 20:16
加载中...