#P4387. 【深基15.习9】验证栈序列
【深基15.习9】验证栈序列
Problem Description
Given two sequences pushed and poped, whose values range from to . 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 sets.
Input Format
The first line contains an integer , the number of queries.
Next come queries. For each query:
The first line contains an integer , the length of the sequence.
The second line contains integers, the push sequence.
The third line contains 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