CF245H.Queries for Number of Palindromes
普及+/提高
通过率:0%
时间限制:5.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You've got a string s = _s_1_s_2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers l__i, r__i (1 ≤ l__i ≤ r__i ≤ |s|). The answer to the query is the number of substrings of string s[l__i... r__i], which are palindromes.
String s[l... r] = s__l__s__l + 1... s__r (1 ≤ l ≤ r ≤ |s|) is a substring of string s = _s_1_s_2... s|s|.
String t is called a palindrome, if it reads the same from left to right and from right to left. Formally, if t = _t_1_t_2... t|t| = t|t|t|t| - 1... _t_1.
你有一个长度为 ∣s∣ 的字符串 s=s1s2…s∣s∣,由小写英文字母组成。此外还有 q 个查询,每个查询由两个整数 li,ri 描述(满足 1≤li≤ri≤∣s∣)。查询的答案是字符串 s[li…ri] 中回文子串的个数。
字符串 s[l…r]=slsl+1…sr(其中 1≤l≤r≤∣s∣)是字符串 s=s1s2…s∣s∣ 的一个子串。
若字符串 t 从左到右读与从右到左读完全相同,则称 t 为回文串。形式化地,若 t=t1t2…t∣t∣=t∣t∣t∣t∣−1…t1。
输入格式
The first line contains string s (1 ≤ |s| ≤ 5000). The second line contains a single integer q (1 ≤ q ≤ 106) — the number of queries. Next q lines contain the queries. The i-th of these lines contains two space-separated integers l__i, r__i (1 ≤ l__i ≤ r__i ≤ |s|) — the description of the i-th query.
It is guaranteed that the given string consists only of lowercase English letters.
第一行包含字符串 s(1 ≤ ∣s∣ ≤ 5000)。第二行包含一个整数 q(1 ≤ q ≤ 106)—— 查询的个数。接下来 q 行为查询内容。其中第 i 行包含两个以空格分隔的整数 li、ri(1 ≤ li ≤ ri ≤ ∣s∣),表示第 i 个查询。
保证给定字符串仅由小写英文字母组成。
输出格式
Print q integers — the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.
输出 q 个整数——即各查询的答案。按输入中查询给出的顺序输出答案。用空格分隔所输出的数字。
输入输出样例
输入#1
caaaba 5 1 1 1 4 2 3 4 6 4 5
输出#1
1 7 3 4 2
说明/提示
Consider the fourth query in the first test case. String s[4... 6] = «aba». Its palindrome substrings are: «a», «b», «a», «aba».
考虑第一个测试用例中的第四个查询。字符串 s[4...6]=«aba»。它的回文子串有:«a»、«b»、«a»、«aba»。
输入解题思路,AI测评打分。不知道怎么写?