#abc328c. C - Consecutive
C - Consecutive
Score : points
问题描述
你将得到一个长度为 的由小写英文字母组成的字符串 。
另外,你还将收到关于字符串 的 个查询。对于 ,第 个查询由两个整数 表示,并询问以下内容:
在从第 个字符到第 个字符的子串 中,有多少位置连续出现了相同的英文小写字母?换句话说,有多少整数 满足条件 且 ?
请分别输出这 个查询的答案。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a string of length consisting of lowercase English letters.
Additionally, you are given queries about the string . For , the -th query is represented by two integers and asks the following.
In the substring of , which ranges from the -th to the -th character, how many places are there where the same lowercase English letter occurs twice in a row? In other words, how many integers satisfy and ?
Print the answer for each of the queries.
Constraints
- and are integers.
- is a string of length consisting of lowercase English letters.
- and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. For , the -th line should contain the answer to the -th query.
Sample Input 1
11 4
mississippi
3 9
4 10
4 6
7 7
Sample Output 1
2
2
0
0
The answers to the four queries are as follows.
- For the first query,
ssissip
has two places where the same lowercase English letter occurs twice in a row:ss
andss
. - For the second query,
sissipp
has two places where the same lowercase English letter occurs twice in a row:ss
andpp
. - For the third query,
sis
has zero places where the same lowercase English letter occurs twice in a row. - For the fourth query,
s
has zero places where the same lowercase English letter occurs twice in a row.
Sample Input 2
5 1
aaaaa
1 5
Sample Output 2
4
aaaaa
has four places where the same lowercase English letter occurs twice in a row: aa
, aa
, aa
, and aa
.
update @ 2024/3/10 01:52:39