#P13242. 「2.48sOI R1」你的名字
「2.48sOI R1」你的名字
Background

Problem Description
Since you cannot swap bodies, you need to solve a problem.
Let be the number of occurrences of string in string . Let denote the substring of string consisting of the -th to the -th characters.
Given a sequence of strings , a sequence of positive integers , and a string , there are queries. Each query has four parameters . Compute:
$$\sum\limits_{i=l_1}^{r_1}\left(\operatorname{occ}(s_i,t[l_2,r_2])\times\min\limits_{j=l_1}^{i}a_j\right)$$For the subtask with , you need to support online queries.
Input Format
There are lines in total.
-
The first line contains six positive integers . Here indicates the Subtask ID of the test point. In particular, for the sample, . The meanings of the other values are as described in the statement.
-
Lines to : strings .
-
Line : a string .
-
Line : positive integers .
-
Lines to : each line contains four positive integers , describing a query.
For the -th query, let the answer to the -th query be (if , then ). Then are computed as:
- .
- .
- .
- .
If , swap . Do the same for .
When , you need to change all to ; when , you need to change all to (if the initial , this operation is performed after swapping ).
Output Format
There are lines. The -th line gives the result of the -th query in the formal statement.
0 6 6 0 -1 -1
aaaaabababaabab
baaabaabababaabba
aabababbaabaabab
abaababababaabaaaba
baabababababaaababa
bababaababababaabab
baababababaaaaababbbaaababaabababaabb
114 51 41 91 98 10
1 6 16 18
2 5 11 12
3 4 1 2
1 5 4 6
3 5 3 4
1 5 7 12
955
614
492
895
820
247
0 6 6 1 -1 -1
aaaaabababaabab
baaabaabababaabba
aabababbaabaabab
abaababababaabaaaba
baabababababaaababa
bababaababababaabab
baababababaaaaababbbaaababaabababaabb
114 51 41 91 98 10
1 6 16 18
2 5 11 12
3 4 1 2
1 5 4 6
3 5 3 4
1 5 7 12
955
900
287
1344
820
41
0 6 6 1 1 -1
aaaaabababaabab
baaabaabababaabba
aabababbaabaabab
abaababababaabaaaba
baabababababaaababa
bababaababababaabab
baababababaaaaababbbaaababaabababaabb
114 51 41 91 98 10
1 6 16 18
2 5 11 12
3 4 1 2
1 5 4 6
3 5 3 4
1 5 7 12
955
1662
1358
824
1184
165
0 6 6 1 -1 6
aaaaabababaabab
baaabaabababaabba
aabababbaabaabab
abaababababaabaaaba
baabababababaaababa
bababaababababaabab
baababababaaaaababbbaaababaabababaabb
114 51 41 91 98 10
1 6 16 18
2 5 11 12
3 4 1 2
1 5 4 6
3 5 3 4
1 5 7 12
955
900
430
348
41
0
Hint
Sample Explanation #1
Take the last query as an example: . The needed values are:
- $\text{occ}(s_1,t[7,12])=\text{occ}(s_2,t[7,12])=\text{occ}(s_4,t[7,12])=\text{occ}(s_5,t[7,12])=1$.
- .
So the answer is $114\times 1+51\times 1+41\times 0 + 41\times 1 + 41\times 1 = 247$.
Constraints
This problem uses bundled testdata.
Let .
| Special Properties | Score | Subtask Dependencies | |||||
|---|---|---|---|---|---|---|---|
Special Property : both and are a.
Special Property : .
Special Property : .
For of the data: , , , , , and or .
Translated by ChatGPT 5