Gene bank - MarisaOJ: Marisa Online Judge

Gene bank

Time limit: 2000 ms
Memory limit: 512 MB
A gene can be represented as a string consisting of four characters A, U, G, and C. A gene bank contains n genes. Given q queries, each query consists of two strings P and Q, and the task is to count how many strings in the gene bank have P as a prefix and Q as a suffix. ### Input - The first line contains two integers n and q. - The next n lines, each contains a string Si, representing a gene in the gene bank. - The next q lines, each contains two strings Pi and Qi, representing a query. ### Output - For each query, print an integer representing the number of strings that have Pi as a prefix and Qi as a suffix. ### Constraints - 1≤n,q,|Si|,|Pi|,|Qi|≤105. - ∑|Si|,∑|Pi|,∑|Qi|≤2×106. ### Example Input: 23AUGCAGCGCAUCAC Output: 012 ### Subtasks - Subtask 1 (10% of the points): 1≤n,q,|Si|,|Pi|,|Qi|≤100. - Subtask 2 (25% of the points): n,q≤5000. - Subtask 3 (25% of the points): ∑|Si|,∑|Pi|,∑|Qi|≤105. - Subtask 4 (40% of the points): No additional constraints.