CF1098F.Ж-function
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The length of the longest common prefix of two strings s=s1s2…sn and t=t1t2…tm is defined as the maximum k≤min(n,m) such that s1s2…sk equals t1t2…tk . Let's denote the longest common prefix of two strings s and t as lcp(s,t) .
Z-function of a string s1s2…sn is a sequence of integers z1,z2,…,zn , where zi=lcp(s1s2…sn, sisi+1…sn) . Ж-function of a string s is defined as z1+z2+…+zn .
You're given a string s=s1s2…sn and q queries. Each query is described by two integers li and ri , where 1≤li≤ri≤n . The answer for the query is defined as Ж-function of the string slisli+1…sri .
输入格式
The first line contains the string s , consisting of lowercase English letters ( 1≤∣s∣≤200000 ). The second line contains one integer q — the number of queries ( 1≤q≤200000 ). Each of the following q lines contains two integers li and ri , describing the query ( 1≤li≤ri≤∣s∣ ).
输出格式
For every query output one integer: the value of Ж-function of the corresponding substring.
输入输出样例
输入#1
abbd 4 2 3 1 3 3 3 1 4
输出#1
3 3 1 4
输入#2
bbaaa 5 2 4 1 5 1 5 3 3 1 2
输出#2
3 6 6 1 3
说明/提示
In the first sample case there are four queries:
- the first query corresponds to the substring bb, and its Ж-function equals 2+1=3 ;
- the second query corresponds to the substring abb, and its Ж-function equals 3+0+0=3 ;
- the third query corresponds to the substring b, and its Ж-function equals 1 .
- the fourth query corresponds to the substring abdd, and its Ж-function equals 4+0+0+0=4 .