Subsequence Queries

5

1 votes
Algorithms, Medium, Sqrt-Decomposition, Square Root Decomposition, String Manipulation
Problem

You are given N strings and Q questions. Each question contains two values X and Y. Print "Yes" if the Xth string is a subsequence of Yth string or Yth string is a subsequence of Xth string, otherwise,print "No".

subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. Read more about subsequences here.

Input format 

  • First line: Two space-separated integers N and Q
  • Next N lines: N strings
  • Next Q lines: Two space-separated integers X and Y

Output format

Print the answer to each question in a new line.

Constraints

1|Si|106

1N105

Nni=1|Si|106

1Q105

1X,YN

|Si| denotes length of ith string

Each string contains only lowercase alphabets.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

1. acd is a subsequence of abcd.

2. acd is NOT a subsequence of bcf or vice versa.

3. ad is a subsequence of abcd.

4. ad is a subsequence of acd.

Editor Image

?