#P16797. [蓝桥杯 2026 国 B] 密码提取

    ID: 19138 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>数学前缀和2026蓝桥杯国赛

[蓝桥杯 2026 国 B] 密码提取

Problem Description

Xiao Lan found a digital password wall in some ruins. The password wall can be seen as a string SS of length NN, and the string contains only digits from 00 to 99.

Xiao Lan can take any non-empty contiguous substring of SS and treat this substring as a decimal integer. Leading zeros are allowed, and any number of leading zeros does not affect the final value. If the substring consists entirely of digit 00, then no matter how long the substring is, its value is 00. For example, the values of 0505 and 005005 are both 55, and the values of 00 and 0000 are both 00.

If two substrings have different start or end positions, then even if their values are the same, they are considered two different extraction plans.

Now Xiao Lan has MM attempts. In the ii-th attempt, a security threshold interval [li,ri][l_i, r_i] is given. For each attempt, please compute how many extraction plans make the extracted decimal value fall within [li,ri][l_i, r_i].

Input Format

The first line contains two positive integers N,MN, M, representing the length of the digit string and the number of queries.

The second line contains a digit string SS of length NN.

The next MM lines each contain two integers li,ril_i, r_i, representing the security threshold interval of one query.

Output Format

Output MM lines. The ii-th line outputs one integer, representing the number of valid extraction plans for the ii-th query.

5 3
00510
0 5
1 10
50 510
8
5
6

Hint

Sample Explanation

The string is 0051000510. If we count all non-empty contiguous substrings by their values, we get:

  • Value 00: there are 33 extraction plans for substring 00, and 11 extraction plan for substring 0000, for a total of 44 plans.
  • Value 11: there is 11 extraction plan for substring 11.
  • Value 55: the substrings 55, 0505, and 005005 each have 11 extraction plan, for a total of 33 plans.
  • Value 1010: there is 11 extraction plan for substring 1010.
  • Value 5151: the substrings 5151, 051051, and 00510051 each have 11 extraction plan, for a total of 33 plans.
  • Value 510510: the substrings 510510, 05100510, and 0051000510 each have 11 extraction plan, for a total of 33 plans.

Therefore, the answer for interval [0,5][0, 5] is 4+1+3=84+1+3=8. The answer for interval [1,10][1, 10] is 1+3+1=51+3+1=5. The answer for interval [50,510][50, 510] is 3+3=63+3=6.

Constraints

For 30%30\% of the testdata, 1≤N,M≤10001 \le N, M \le 1000.

For 80%80\% of the testdata, 1≤N,M≤50001 \le N, M \le 5000.

For all testdata, 1≤N,M≤1061 \le N, M \le 10^6, 0≤li≤ri≤1000000 \le l_i \le r_i \le 100000.

Translated by ChatGPT 5