luogu#P4770. [NOI2018] 你的名字

    ID: 3765 远端评测题 5000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2018线段树NOI后缀自动机 SAMO2优化后缀数组 SA

[NOI2018] 你的名字

Background

The very capable Little A was chosen as the problem setter for ION2018, and now he needs to solve the problem of naming the tasks.

Problem Description

Little A was chosen as the problem setter for ION2018. He carefully prepared a very high-quality problem, and has already finished all the work except naming the problem.

Since ION has been held for many years, there are also rules for naming problems. The ION problem-setting manual states: every year, the problem committee specifies a lowercase-letter string, which we call that year's naming string. The name of each problem must be a non-empty contiguous substring of that year's naming string, and it must not be the same as the name of any problem in the previous year.

For some special reasons, Little A does not know the names of each problem in ION2017, but through some special means he obtained the ION2017 naming string. Now Little A has QQ queries: each time, given the ION2017 naming string and the ION2018 naming string, find how many possible problem names are guaranteed to satisfy the committee's rules, that is, the name is a non-empty contiguous substring of the ION2018 naming string and is guaranteed not to be the same as the name of any problem in ION2017.

For some special reasons, in all queries, the given ION2017 naming strings are contiguous substrings of some string. See the input format for details.

Input Format

The first line contains a string SS. In the queries below, the given ION2017 naming string is always a contiguous substring of SS. The second line contains a positive integer QQ, indicating the number of queries. The next QQ lines each contain a string TT and two positive integers l,rl, r, meaning: if the ION2017 naming string is SlrS_{l\ldots r} and the ION2018 naming string is TT, then how many naming choices are guaranteed to satisfy the rules.

Output Format

Output QQ lines. The ii-th line contains a non-negative integer, representing the answer to the ii-th query.

scbamgepe
3
smape 2 7
sbape 3 8
sgepe 1 9
12
10
4

Hint

More Samples

Please download more samples from the additional files.

Sample 2

See name2.in and name2.ans in the additional files.

Constraints

::cute-table{tuack}

Test Point S\vert S\vert \leq QQ\leq T\sum \vert T\vert \leq Query Restrictions Other Restrictions
11 200200 4000040000 For all queries, l=1,r=Sl = 1, r=\vert S\vert T200T\leq 200
22 10001000 ^ ^ ^ ^
33 ^
44 5×1055 \times 10^5 None
55 ^ ^
66 5×1055 \times 10^5 11
77 ^
88 10510^5 2×1052 \times 10^5
99 ^ ^ ^ Random strings
1010 2×1052 \times 10^5 4×1054 \times 10^5 None
1111 ^ ^ Random strings
1212 3×1053 \times 10^5 6×1056 \times 10^5 None
1313 ^ ^ Random strings
1414 4×1054 \times 10^5 8×1058 \times 10^5 None
1515 ^ ^ Random strings
1616 5×1055 \times 10^5 10610^6 None
1717 ^ ^ Random strings
1818 2×1052 \times 10^5 None
1919 3×1053 \times 10^5 ^
2020 4×1054 \times 10^5
2121 5×1055 \times 10^5
2222 ^
2323
2424
2525

For all data, it is guaranteed that 1lrS1\leq l \leq r \leq |S|, 1T5×1051\leq |T|\leq 5 \times 10^5.

Thanks to @Wen_kr for providing a set of hack testdata.

Translated by ChatGPT 5