URbit @ 2022-09-18 10:52:03
#include <iostream>
#include <stack>
using std::cin;
using std::cout;
using std::endl;
using std::stack;
class Solution
{
public:
int pushed[100100];
int vis[100100];
void isStack();
};
void Solution::isStack()
{
int n;
int flag = 0;
vis[0] = -1;
cin >> n;
for (int i = 1; i <= n; i++)
vis[i] = 0;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
pushed[x] = i;
}
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (flag == 0)
{
int loc = pushed[x];
for (int j = loc; vis[j] != -1 && vis[j] != 1; j--)
{
vis[j] = 1;
}
vis[loc] = -1;
while (vis[loc] != 0)
{
if (vis[loc + 1] == 1)
{
flag = 1;
break;
}
loc++;
}
}
}
if (flag == 1)
cout << "No\n";
else
cout << "Yes\n";
}
Solution s;
int main()
{
int q;
cin >> q;
for (int i = 0; i < q; i++)
s.isStack();
return 0;
}