#abc295f. F - substr = S

F - substr = S

Score : 500500 points

问题描述

你将得到一个由数字组成的字符串 SS,以及对于 TT 个测试用例的正整数 LLRR。请解决以下问题。

对于正整数 xx,我们定义函数 f(x)f(x)xx 的十进制表示(不含前导零)中等于 SS 的连续子串的数量。

例如,如果 S=S= 22,则有 f(122)=1f(122) = 1f(123)=0f(123) = 0f(226)=1f(226) = 1,以及 f(222)=2f(222) = 2

k=LRf(k)\displaystyle \sum_{k=L}^{R} f(k)

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a string SS consisting of digits and positive integers LL and RR for each of TT test cases. Solve the following problem.

For a positive integer xx, let us define f(x)f(x) as the number of contiguous substrings of the decimal representation of xx (without leading zeros) that equal SS.

For instance, if S=S= 22, we have f(122)=1f(122) = 1, f(123)=0f(123) = 0, f(226)=1f(226) = 1, and f(222)=2f(222) = 2.

Find k=LRf(k)\displaystyle \sum_{k=L}^{R} f(k).

Constraints

  • 1T10001 \le T \le 1000
  • SS is a string consisting of digits whose length is between 11 and 1616, inclusive.
  • LL and RR are integers satisfying 1LR<10161 \le L \le R < 10^{16}.

Input

The input is given from Standard Input in the following format, where casei\rm{case}_i denotes the ii-th test case:

TT

case1\rm{case}_{1}

case2\rm{case}_{2}

\vdots

caseT\rm{case}_{\it{T}}

Each test case is in the following format:

SS LL RR

Output

Print TT lines in total.
The ii-th line should contain an integer representing the answer to the ii-th test case.

Sample Input 1

6
22 23 234
0295 295 295
0 1 9999999999999999
2718 998244353 9982443530000000
869120 1234567890123456 2345678901234567
2023032520230325 1 9999999999999999

Sample Output 1

12
0
14888888888888889
12982260572545
10987664021
1

This input contains six test cases.

  • In the first test case, S=S= 22, L=23L=23, R=234R=234.
    • f(122)=f(220)=f(221)=f(223)=f(224)==f(229)=1f(122)=f(220)=f(221)=f(223)=f(224)=\dots=f(229)=1.
    • f(222)=2f(222)=2.
    • Thus, the answer is 1212.
  • In the second test case, S=S= 0295, L=295L=295, R=295R=295.
    • Note that f(295)=0f(295)=0.

update @ 2024/3/10 12:16:41