#SRD0000133. Truy vấn dãy con của xâu (Subsequence queries)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Truy vấn dãy con của xâu (Subsequence queries)
Subsequence queries
Source: MarisaOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given strings . String is a subsequence of string if some characters of , at strictly increasing positions, form . The selected positions need not be contiguous. For example, abc is a subsequence of axbyc, while acb is not.
For each of independent queries containing indices , determine whether at least one of these statements is true:
- is a subsequence of .
- is a subsequence of .
Equal strings always satisfy the requirement. Character order must be preserved, although characters may be skipped.
Input
- The first line contains integers , the number of strings and queries.
- The next lines contain the strings; line contains .
- Each of the following lines contains indices of the strings in query .
Output
Print one line per query in the original order. Print YES if either string is a subsequence of the other, otherwise print NO.
Subtasks
- Subtask 1 (10 points): ; ; each is nonempty and contains only lowercase English letters; in every query.
- Subtask 2 (20 points): ; ; each is nonempty and contains only lowercase English letters; in every query.
- Subtask 3 (30 points): ; ; each is nonempty and contains only lowercase English letters; in every query.
- Subtask 4 (40 points): ; ; each is nonempty and contains only lowercase English letters; in every query.
Examples
Example 1
Input
3 3
aab
db
dacb
2 1
2 3
1 3
Output
NO
YES
NO
Explanation
For , db contains d, which is absent from aab; the reverse direction is impossible as well. For , select positions and of dacb to obtain db, so the answer is YES. For , aab requires two a characters before b, but dacb has only one a; the opposite direction also fails because dacb is longer.
Example 2
Input
4 4
ab
aba
bbb
babbb
1 2
1 3
3 4
2 4
Output
YES
NO
YES
NO
Explanation
ab is a subsequence of aba. Neither ab nor bbb is a subsequence of the other. bbb is a subsequence of babbb by selecting three b characters. aba is not a subsequence of babbb because there is only one a; the reverse direction also fails by length, so the fourth answer is NO.