题目:https://www.luogu.com.cn/problem/P4387
#include<iostream>
#include<cstdio>
#include<stack>
#define MAXN 100005
using namespace std;
int stkA[MAXN];
int stkB[MAXN];
int read(){
int x = 0,f = 1;
char c = getchar();
while (c<'0'||c>'9') {
if (c=='-') {
f = -1;
}
c = getchar();
}
while (c>='0'&&c<='9') {
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
int main(){
int n = read();
while(n--){
int num = read();
stack<int> s;
int A = 1,B = 1;
for (int i = 1; i<=num; i++) {
stkA[i] = read();
}
for (int i = 1; i<=num; i++) {
stkB[i] = read();
}
while(A<=num){
s.push(stkA[A]);
while(stkB[B]==s.top()) {
s.pop();
B++;
if (s.empty()) {
break;
}
}
A++;
}
printf("%s\n",s.empty()?"Yes":"No");
}
return 0;
}
/*
1
5
1 5 2 3 4
2 4 3 5 1
*/
网友评论