0分求助
查看原帖
0分求助
940472
Sirenaya楼主2024/1/25 10:29
 #include<iostream>
#include<stack>
using namespace std;
#define Maxsize 100005

int q, n, head = 1, i, j;
int Test[Maxsize], Ver[Maxsize];
int main()
{
	cin >> q;
	for (i = 0; i < q; i++)
	{
		stack<int> s;
		cin >> n;
		for (j = 1; j <= n; j++)
		{
			cin >> Test[j];
		}
		for (j = 1; j <= n; j++)
		{
			cin >> Ver[j];
		}
		for (j = 1; j <= n; j++)
		{
			s.push(Test[j]);
			while (Ver[head] == s.top())
			{
				s.pop();
				head++;
				if (s.empty())
					break;
			}
		}
		if (s.empty())
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}
2024/1/25 10:29
加载中...