229074068ZHL @ 2022-12-28 12:20:56
#include <iostream>
using namespace std;
const int N = 1e6 + 5;
int p[N], l;
void push(int k)
{
p[++l] = k;
}
void pop()
{
l--;
}
int top()
{
return p[l];
}
bool empty()
{
if (l == 0)
return true;
else
return false;
}
int main()
{
int q;
cin >> q;
while (q--)
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
push(x);
}
for (int i = 0; i < n; i++)
{
int y;
cin >> y;
if (top() == y && !empty())
{
pop();
}
}
if (empty())
cout << "Yes" << endl;
else
cout << "No" << endl;
l = 0;
}
return 0;
}
by ISTP @ 2022-12-28 12:45:48
@229074068ZHL 每次要把栈清空