#P4387. 【深基15.习9】验证栈序列

【深基15.习9】验证栈序列

Problem Description

Given two sequences pushed and poped, whose values range from 11 to nn (n100000)(n \le 100000). The push sequence is known to be pushed. If the pop sequence could be poped, output Yes; otherwise output No. Note that the given sequences are guaranteed to be a permutation (i.e., there are no repeated numbers).

To prevent hacking, each test point contains multiple testdata sets, no more than 55 sets.

Input Format

The first line contains an integer qq, the number of queries.

Next come qq queries. For each query:

The first line contains an integer nn, the length of the sequence.

The second line contains nn integers, the push sequence.

The third line contains nn integers, the pop sequence.

Output Format

For each query, output the answer.

2
5
1 2 3 4 5
5 4 3 2 1
4
1 2 3 4
2 4 1 3
Yes
No

Hint

Translated by ChatGPT 5