Subsequence queries - MarisaOJ: Marisa Online Judge

Subsequence queries

Time limit: 4000 ms
Memory limit: 256 MB
Given n strings S1,S2,...,Sn. There are q queries, each consisting of two integers x,y. Check whether Sx is a substring (not necessarily contiguous) of Sy or if Sy is a substring (not necessarily contiguous) of Sx. ### Input - The first line contains two integers n,q. - The next n lines, where the i-th line represents the string Si. - The next q lines, each containing two integers x,y. ### Output - For each query, print YES if Sx is a substring of Sy or if Sy is a substring of Sx, otherwise print NO. ### Constraints - 1≤n,q≤105. - 1≤∑|Si|≤106 - 1≤x,y≤n. - All strings consist only of lowercase letters. ### Example Input: 33aabdbdacb212313 Output: NOYESNO