2023秋-A-2 Two Ways In, One Way Out
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
题目描述
Consider a special queue which is a linear structure that allows insertions at both ends, yet deletions at one end. Your job is to check, for a given insertion sequence, if a deletion sequence is possible. For example, if we insert 1, 2, 3, 4, and 5 in order, then it is possible to obtain 1, 3, 2, 5, and 4 as an output, but impossible to obtain 5, 1, 3, 2, and 4.
输入格式
Each input file contains one test case.
For each case, the first line gives 2 positive integers and (), which are the number of insertions and the number of queries, respectively. Then distinct numbers (each no larger than ) are given in the next line, as the insertion sequence.
Finally lines follow, each contains inserted numbers as the deletion sequence to be checked.
All the numbers in a line are separated by spaces.
输出格式
For each deletion sequence, print in a line yes
if it is indeed possible to be obtained, or no
otherwise.
样例
5 4
10 2 3 4 5
10 3 2 5 4
5 10 3 2 4
2 3 10 4 5
3 5 10 4 2
yes
no
yes
no
限制
Java (javac) 时间限制 550 ms 内存限制 512 MB
其他编译器 时间限制 400 ms 内存限制 64 MB