#P10176. 「OICon-02」Native Faith
「OICon-02」Native Faith
Problem Description
In this problem, string indices start from .
Define the result of adding two strings as the new string formed by concatenating the two strings end to end.
Let $f(a,b,c)=\sum\limits_{i=1}^{|a|}\sum\limits_{j=i}^{|a|}\sum\limits_{k=1}^{|b|}\sum\limits_{l=k}^{|b|}[a_{i,i+1,\cdots,j}+b_{k,k+1,\cdots,l} = c]$ ( are all strings).
That is, how many ways are there to choose a non-empty substring from each of and such that the sum (concatenation) of the two substrings equals .
Given strings .
There are queries. Each query gives three positive integers . Compute $\sum\limits_{i=l}^r\sum\limits_{j=l}^rf(s_i,s_j,s_k)$.
Input Format
The first line contains two integers .
The next lines each contain a non-empty string consisting only of lowercase letters, representing .
The next lines each contain three positive integers , representing one query.
Output Format
For each query, output one integer per line representing the answer.
3 3
a
aa
aaa
1 2 3
2 3 3
1 3 3
6
30
36
10 10
aabb
aba
abbba
abaccaab
abbba
ababababab
aaaaa
bbbbbb
aaba
abbba
1 10 10
1 4 5
3 6 4
2 8 1
1 5 4
2 10 7
2 9 2
4 5 5
5 5 6
8 9 10
241
31
51
105
40
136
460
17
0
0
5 5
a
ba
aba
ababa
abab
1 3 3
1 2 3
2 3 3
4 4 5
3 4 4
12
2
9
11
28
Hint
Sample Explanation
For sample , some values of the function are given.
- , , , , , , , , .
Constraints
This problem uses bundled testdata.
Let .
::cute-table | | Special Property | | | :-----------: | :-----------: | :-----------: | | | | | | | The in each query are all different | | | | | | | | The strings only contain the lowercase letter | | | | None | |
For of the data: , , , and the strings contain only lowercase letters.
Translated by ChatGPT 5