#P5826. 【模板】子序列自动机
【模板】子序列自动机
Background
In this problem, if is a subsequence of , then it is equivalent to the existence of a strictly increasing sequence such that , , and . Here denote the lengths of sequences , and denote the -th element of sequences .
This problem was rejected in the backup problem set of yLOI2020.
Problem Description
Given a positive integer sequence of length , there are queries. In the -th query, a sequence of length is given. You need to determine whether is a subsequence of . All elements in sequence and all are no greater than a given positive integer .
Input Format
Each test case contains exactly one dataset.
The first line contains four integers separated by spaces: . Here indicates the subtask number of the test point, and the meanings of the other variables are the same as in the Description.
The second line contains integers separated by spaces. The -th number is the -th element of sequence .
Lines to each represent a query. The input format of line is:
- At the beginning of line there is an integer , which is the length of the sequence in the -th query. After one space, there are integers separated by spaces. The -th integer on this line is the -th element of sequence .
Output Format
For each query, output one string per line. If the given sequence is a subsequence of , output Yes; otherwise output No.
0 5 5 5
1 3 2 2 4
3 1 5 2
2 3 2
3 1 2 3
3 1 2 4
5 1 3 2 2 4
No
Yes
No
Yes
Yes
Hint
Explanation for Sample 1
- For the first query, there is no in the original sequence, so the given sequence is obviously not a subsequence of the original sequence.
- For the second query, there are two valid sequences , which are and . That is, or . Here denotes the -th element of sequence . The meaning of sequence is given in the Background, and the same below.
- For the third query, there is no valid sequence .
- For the fourth query, there are two valid sequences , which are and .
- For the fifth query, there is one valid sequence , which is .
Constraints and Conventions
This problem uses bundled multi-point testing, with a total of 3 subtasks.
- Subtask 1 (20 points): , , .
- Subtask 2 (35 points): , , , .
- Subtask 3 (45 points): , , .
For all test points, it is guaranteed that , , , and .
Notes
- Please pay attention to the impact of constant factors on program efficiency.
- The input size of this problem is large, so please pay attention to input reading efficiency.
- Please note that in the first line of input, the order is to input the number of queries first, and then the maximum value of sequence elements.
Translated by ChatGPT 5