CF2209E.A Trivial String Problem
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Define f(t) as the maximum number of parts t can be split into such that each part is a non-empty prefix of t. In other words, f(t) is the maximum positive integer k that satisfies the following condition:
- There exist k strings p1,p2,…,pk, which are prefixes of t, such that t=p1+p2+…+pk. Here + denotes the string concatenation.
You are given a string s of length n, consisting of only lowercase English letters. Let s[x..y] represent the substring∗ of s from the x-th to the y-th character (inclusive). You need to answer q queries. The i-th query provides two integers li and ri, and you need to find
\\sum\_{j=l\_i}^{r\_i} f(s\[l\_i..j\]).∗A string a is a substring of a string b if a can be obtained from b by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
定义 f(t) 为字符串 t 可被划分成的最多部分数,使得每一部分均为 t 的非空前缀。换言之,f(t) 是满足以下条件的最大正整数 k:
- 存在 k 个字符串 p1,p2,…,pk,它们均为 t 的前缀,且满足 t=p1+p2+…+pk。其中 + 表示字符串连接运算。
给定一个长度为 n 的字符串 s,其仅由小写英文字母组成。记 s[x..y] 表示 s 中从第 x 个字符到第 y 个字符(含端点)的子串∗。你需要回答 q 个查询。第 i 个查询给出两个整数 li 和 ri,你需要计算
j=li∑rif(s[li..j]).
∗ 若字符串 a 可通过从字符串 b 的开头删除若干(可能为零或全部)字符、并从结尾删除若干(可能为零或全部)字符而得到,则称 a 是 b 的子串。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤103). The description of the test cases follows.
The first line of each test case contains two integers n and q (1≤n≤106, 1≤q≤100).
The second line contains the string s of length n, consisting of only lowercase English letters.
The i-th of the next q lines contains two integers li and ri (1≤li≤ri≤n), representing the i-th query.
It is guaranteed that the sum of n over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤103)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 q(1≤n≤106,1≤q≤100)。
第二行包含一个长度为 n 的字符串 s,仅由小写英文字母组成。
接下来的 q 行中,第 i 行包含两个整数 li 和 ri(1≤li≤ri≤n),表示第 i 个查询。
保证所有测试用例的 n 之和不超过 106。
输出格式
For each query, output an integer representing the value of the expression.
对于每个查询,输出一个整数,表示该表达式的值。
输入输出样例
输入#1
6 1 1 a 1 1 5 2 aaaaa 1 5 2 4 6 2 abcdef 1 6 3 5 6 3 abaaba 1 6 1 3 2 6 7 3 abcabca 1 7 2 7 4 7 8 3 aababaac 1 8 2 8 3 7
输出#1
1 15 6 6 3 14 4 7 12 9 5 13 14 7
说明/提示
In the first test case, f(a)=1.
In the second test case, f(a)+f(aa)+f(aaa)+f(aaaa)+f(aaaaa)=1+2+3+4+5=15 and f(a)+f(aa)+f(aaa)=1+2+3=6.
In the third test case, f(a)+f(ab)+f(abc)+f(abcd)+f(abcde)+f(abcdef)=1+1+1+1+1+1=6 and f(c)+f(cd)+f(cde)=1+1+1=3.
在第一个测试用例中,f(a)=1。
在第二个测试用例中,f(a)+f(aa)+f(aaa)+f(aaaa)+f(aaaaa)=1+2+3+4+5=15,且 f(a)+f(aa)+f(aaa)=1+2+3=6。
在第三个测试用例中,f(a)+f(ab)+f(abc)+f(abcd)+f(abcde)+f(abcdef)=1+1+1+1+1+1=6,且 f(c)+f(cd)+f(cde)=1+1+1=3。
输入解题思路,AI测评打分。不知道怎么写?