#SRD0000151. Duff đang tức giận (Duff is Mad)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Duff đang tức giận (Duff is Mad)
Duff is Mad
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Duff has friends. Friend has a nonempty lowercase-English name . Names need not be unique.
For each of queries , compute the sum of occurrences of the names as contiguous substrings of the text :
Here is the number of starting positions at which exactly matches a contiguous substring of . Overlapping occurrences count separately; equal names at different indices also contribute separately.
All queries are independent; strings do not change.
Input
- First line: integers .
- Next lines: the nonempty strings , consisting of lowercase letters
a–z. - Next lines: , specifying the inclusive range of name indices and the target text index.
Output
Print lines. Line gives the sum of the occurrence counts for query .
Subtasks
- Subtask 1 (20 points): ; ; ; all nonempty and lowercase
a–z; ; . - Subtask 2 (30 points): ; ; ; all nonempty and lowercase
a–z; ; . - Subtask 3 (50 points): ; ; ; all nonempty and lowercase
a–z; ; .
Examples
Example 1
Input
5 5
a
ab
abab
ababab
b
1 5 4
3 5 4
1 5 2
1 5 3
1 4 1
Output
12
6
3
7
1
Explanation
The text ababab contains a three times, ab three times, abab twice, ababab once and b three times: total . Restricting to indices yields . The text ab contains a, ab, b once each: . The text abab yields counts , total . The last query asks for names indexed in text a, giving .