Subsequence Queries
Practice
5 (1 votes)
Algorithms
Medium
Sqrt Decomposition
Square root decomposition
String manipulation
Problem
18% Success 680 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given \(N\) strings and \(Q\) questions. Each question contains two values \(X\) and \(Y\). Print "Yes" if the \(X^{th}\) string is a subsequence of \(Y^{th}\) string or Yth string is a subsequence of Xth string, otherwise,print "No".
A 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 \le |S_i| \le 10^6\)
\(1 \le N \le 10^5\)
\(N \le\sum_{i=1}^{n}|S_i|\le 10^6 \)
\(1 \le Q \le 10^5\)
\(1 \le X,Y \le N\)
\(|Si|\) denotes length of ith string
Each string contains only lowercase alphabets.
Submissions
Please login to view your submissions
Similar Problems
Points:50
7 votes
Tags:
AlgorithmsMediumSquare Root DecompositionTrees
Points:50
2 votes
Tags:
AlgorithmsMediumSquare Root Decomposition
Points:50
10 votes
Tags:
AlgorithmsData StructuresMediumSqrt-Decomposition
Editorial