report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Subsequence queries - MarisaOJ: Marisa Online Judge

Subsequence queries

Time limit: 4000 ms
Memory limit: 256 MB
Given $n$ strings $S_1, S_2, ..., S_n$. There are $q$ queries, each consisting of two integers $x, y$. Check whether $S_x$ is a substring (not necessarily contiguous) of $S_y$ or if $S_y$ is a substring (not necessarily contiguous) of $S_x$. ### Input - The first line contains two integers $n, q$. - The next $n$ lines, where the $i$-th line represents the string $S_i$. - The next $q$ lines, each containing two integers $x, y$. ### Output - For each query, print `YES` if $S_x$ is a substring of $S_y$ or if $S_y$ is a substring of $S_x$, otherwise print `NO`. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le \sum |S_i| \le 10^6$ - $1 \le x, y \le n$. - All strings consist only of lowercase letters. ### Example Input: ``` 3 3 aab db dacb 2 1 2 3 1 3 ``` Output: ``` NO YES NO ```
Square root decomposition
Frequency
Tree query
Inversions query
Nearest vertex
Dominating color
String occurences 3
Inversions query 2
Pair
Sparse update
Tree
Range query
String concatenation
Subarray distance
Chameleon
Knapsack
Bit counting
Subsequence queries
Sub-subsequence
Delete numbers
Mode
Marisa is happy
Inversions query 3
Upperbound
23 path
Yet another square root decomposition problem
Marisa plays poker
Wonderful world
Topic
String
Rating 2100
Solution (0) Solution