#P5826. Subsequence Query
Subsequence Query
Subsequence Query
Given a sequence of positive integers a of length \(n\) and a positive integer \(m\), you are also given \(q\) queries. In the \(i\)-th query, a sequence \(b_i\) of length \(L_i\) is provided. Your task is to determine whether \(b_i\) is a subsequence of \(a\). A sequence \(b\) is a subsequence of \(a\) if it can be obtained by deleting some (possibly zero) elements from \(a\) without changing the order of the remaining elements. All elements in \(a\) and every \(b_i\) are positive integers not exceeding \(m\).
inputFormat
The input consists of multiple lines:
- The first line contains two integers \(n\) and \(q\) denoting the length of sequence \(a\) and the number of queries, respectively.
- The second line contains \(n\) space-separated positive integers, which represent the sequence \(a\).
- The third line contains a single positive integer \(m\), the upper bound for the values in the sequences.
- Then, for each query, there is one line that starts with an integer \(L_i\) (the length of sequence \(b_i\)) followed by \(L_i\) space-separated positive integers representing the sequence \(b_i\).
outputFormat
For each query, output a single line containing Yes
if \(b_i\) is a subsequence of \(a\), or No
otherwise.
sample
5 3
1 3 2 4 5
5
3 1 2 5
2 3 4
3 1 4 2
Yes
Yes
No
</p>