Common Substring Queries
Time limit4sMemory limit1024 MB
Given N strings with total length up to 200,000, answer Q queries, each asking how many distinct substrings strings S_i and S_j share.
- Level
Hard8 of 10
- Topics
- String matching, Tree, Sorting
- Solved
- No attempts yet
Problem
Given strings made only of lowercase English letters, write a program that processes the following query.
- : Find the number of distinct common substrings of and .
A substring of a string is a non-empty contiguous part of that string. A common substring of two strings and is a string that is a substring of both and .
Input
The first line contains the number of strings (). The next lines each contain one string made of lowercase letters, one per line. The total length of does not exceed .
The next line contains the number of queries (). The next lines each contain two integers and ().
Output
Print the answer to each of the queries on its own line, in order.