- C24zhouyanchen's blog
6
- @ 2025-2-28 21:36:09
#include <iostream>
#include <stack>
using namespace std;
const int N = 100005;
int n,a[N],b[N];
stack <int> nPr;
int main(){
int t;
cin >> t;
while (t--){
cin >> n;
for (int i = 1;i <= n;i++){
cin >> a[i];
}
for (int i = 1;i <= n;i++){
cin >> b[i];
}
int tmp = 1;
for (int i = 1;i <= n;i++){
nPr.push(a[i]);
while (nPr.size() && tmp <= n && nPr.top() == b[tmp]){
// cout << nPr.top() << '\n';
nPr.pop();
tmp++;
}
}
if (nPr.size())
cout << "NO";
else
cout << "YES";
cout << '\n';
}
return 0;
}