P383 One Way In, Two Ways Out
One Way In, Two Ways Out
题目描述
Consider a special queue which is a linear structure that allows insertions at one end, yet deletions at both ends. Your job is to check, for a given insertion sequence, if a deletion sequence is possible. For example, if we insert and in order, then it is possible to obtain and as an output, but impossible to obtain and .
输入格式
Each input file contains one test case. For each case, the first line gives positive integers and (), which are the number of insertions and the number of queries, respectively. Then distinct numbers are given in the next line, as the insertion sequence. Finally lines follow, each contains inserted numbers as the deletion sequence to be checked.



