luogu#P5112. FZOUTSY

FZOUTSY

Problem Description

Original Meaning

cdm1020 is a shut-in. His favorite thing in daily life is chatting (and copying) in group chats.

He took the chat logs from a group he recently chatted in, and used some mysterious compression algorithm to compress these chat logs into a string of length nn. Because he is a chuunibyou-style fan, this string contains only 77 kinds of characters: f,z,o,u,t,s,y\mathtt{f,z,o,u,t,s,y}. Because of his obsession with suffix data structures, he is only interested in the suffixes of this string. He defines the index of a suffix to be ii if and only if the interval of the string it represents is [i,n][i,n].

cdm1020 defines a pair of suffixes (i,j)(i,j) to be “kk-level copying” if and only if the length of the longest common prefix of suffix ii and suffix jj is at least kk. In other words, a pair of kk-level copying suffixes is also k1,k2,k3,,1,0k-1,k-2,k-3,\cdots,1,0-level copying.

Now he wants to ask: among the suffixes with indices in (l,r)(l,r), how many pairs of suffixes are kk-level copying.

One-Sentence Meaning

Given a string of length nn over the alphabet f,z,o,u,t,s,y\mathtt{f,z,o,u,t,s,y} and a query parameter kk, for multiple queries (l,r)(l,r), find among the suffixes with indices in (l,r)(l,r) how many pairs of suffixes have LCP (longest common prefix) length at least kk.

A suffix has index ii if and only if it represents the characters in the interval (i,n)(i,n).

Input Format

The first line contains three positive integers n,m,kn,m,k, representing the string length nn, the number of queries mm, and the query parameter kk.

The second line contains a string of length nn, which is the string you need to process.

The next mm lines each contain two positive integers l,rl,r, representing the query interval l,rl,r.

Output Format

Output mm lines, each containing a positive integer, representing the number of suffix pairs in the query interval whose LCP length is at least kk.

20 15 3
oouuoouuoouuoouuoouu
10 16
2 15
4 13
6 7
4 12
12 14
12 13
7 19
1 5
6 13
1 15
9 15
11 15
1 19
15 18
3
18
8
0
6
0
0
12
1
4
21
3
1
32
0

Hint

Constraints and Notes

For all testdata, 1lrn3×1061\leq l\leq r\leq n \leq 3×10^6, 1kn3×1061\leq k \leq n \leq 3×10^6, 1m1051\leq m \leq 10^5, 1n2m10151 \leq n^2m \leq 10^{15}.

It is guaranteed that the input string contains only the 77 lowercase letters f,z,o,u,t,s,y\mathtt{f,z,o,u,t,s,y}.

Translated by ChatGPT 5