#P10716. 【MX-X1-T4】「KDOI-05」简单的字符串问题

    ID: 11981 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>字符串倍增树上启发式合并O2优化KMP 算法梦熊比赛

【MX-X1-T4】「KDOI-05」简单的字符串问题

Background

Original problem link: https://oier.team/problems/X1D.

Problem Description

You are given a string SS. There are qq queries. Each query gives (i,k)(i, k). For each query, find how many non-empty strings AA exist such that there are (possibly empty) strings B1,B2,…,Bk−1B_1, B_2, \dots, B_{k-1} satisfying:

S[1,i]=AB1AB2A…ABk−1AS[1,i]=AB_1AB_2A\dots AB_{k-1}A

Here, S[1,i]S[1,i] denotes the prefix of SS with length ii.

Input Format

The first line contains a positive integer nn, denoting the length of SS.

The next line contains a string of length nn consisting only of lowercase letters, denoting SS.

The next line contains a positive integer qq.

The next qq lines each contain two positive integers, denoting a query i,ki, k.

Output Format

Output qq lines. Each line contains a non-negative integer, denoting the answer.

10
aabaacaaaa
5
5 3
5 2
6 1
10 4
10 5
1
2
1
2
1
10
bababababa
10
6 1
6 2
6 3
6 4
6 5
10 2
10 3
9 4
5 5
4 2
1
1
1
0
0
2
1
1
0
1

Hint

Sample Explanation #1

For the first query (5,3)(5, 3), we can take A=aA=\texttt{a}, B1=εB_1=\varepsilon, B2=baB_2=\texttt{ba}, where ε\varepsilon denotes the empty string. It can be proven that there is exactly one valid AA.

Constraints

This problem uses bundled testdata.

Subtask ID Score n,q≤n,q\leq Special Property
11 55 500500 None
22 1010 50005000
33 2×1052\times10^5 Characters in SS are generated randomly from a,b\tt a,b
44 2020 All queries have the same kk
55 5×1045\times10^4 None
66 3535 2×1052\times10^5

For 100%100\% of the testdata: 1≤k≤i≤n≤2×1051\leq k\leq i\leq n\leq 2\times 10^5, 1≤q≤2×1051\leq q\leq 2\times 10^5, ss consists only of lowercase letters.

Translated by ChatGPT 5