Tjaweiof @ 2023-05-17 13:12:38
代码如下
#include <bits/stdc++.h>
using namespace std;
int main(){
int Q;
scanf("%d", &Q);
while (Q--){
int n;
cin >> n;
int pushed[n+5], poped[n+5], h = 0;
stack<int> q;
for (int i = 0; i < n; i++){
scanf("%d", &pushed[i]);
}
for (int i = 0; i < n; i++){
scanf("%d", &poped[i]);
}
for (int i = 0; i < n; i++){
q.push(pushed[i]);
while (1){
if (q.top() == poped[h]){
h++;
q.pop();
} else {
break;
}
}
}
if (q.empty()){
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}