传统题 1000ms 256MiB

Consecutive

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Statement

You are given a string S=S1S2SNS = S_1S_2\ldots S_N of length NN consisting of lowercase English letters.

Additionally, you are given QQ queries about the string SS. For i=1,2,,Qi = 1, 2, \ldots, Q, the ii-th query is represented by two integers li,ril_i, r_i and asks the following.

In the substring SliSli+1SriS_{l_i}S_{l_i+1}\ldots S_{r_i} of SS, which ranges from the lil_i-th to the rir_i-th character, how many places are there where the same lowercase English letter occurs twice in a row? In other words, how many integers pp satisfy lipri1l_i \leq p \leq r_i-1 and Sp=Sp+1S_p = S_{p+1}?

Print the answer for each of the QQ queries

Constraints

  • NN and QQ are integers.
  • 1N,Q3×1051 \leq N, Q \leq 3 \times 10^5
  • SS is a string of length NN consisting of lowercase English letters.
  • lil_i and rir_i are integers.
  • 1liriN1 \leq l_i \leq r_i \leq N

Input

The input is given from Standard Input in the following format:

NN QQ

SS

l1l_1 r1r_1

l2l_2 r2r_2

......

lQl_Q rQr_Q

Output

Print QQ lines. For i=1,2,,Qi = 1, 2, \ldots, Q, the ii-th line should contain the answer to the ii-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, S3S4S9=S_3S_4\ldots S_9 = ssissip has two places where the same lowercase English letter occurs twice in a row: S3S4=S_3S_4 = ss and S6S7=S_6S_7 = ss.
  • For the second query, S4S5S10=S_4S_5\ldots S_{10} = sissipp has two places where the same lowercase English letter occurs twice in a row: S6S7=S_6S_7 = ss and S9S10=S_9S_{10} = pp.
  • For the third query, S4S5S6=S_4S_5S_6 = sis has zero places where the same lowercase English letter occurs twice in a row.
  • For the fourth query, S7=S_7 = s has zero places where the same lowercase English letter occurs twice in a row.

2024暑期集训第六周小测

未参加
状态
已结束
规则
ACM/ICPC
题目
6
开始于
2024-8-7 19:00
结束于
2024-8-7 21:00
持续时间
2 小时
主持人
参赛人数
27