#abc372c. C - Count ABC Again

C - Count ABC Again

Score : 350350 points

问题陈述

你得到了一个长度为 NN 的字符串 SS。你还得到了 QQ 个查询,你应该按顺序处理它们。

ii 个查询如下:

  • 给定一个整数 XiX_i 和一个字符 CiC_i,将 SS 中的第 XiX_i 个字符替换为 CiC_i。然后,打印字符串 ABC 作为子串在 SS 中出现的次数。

这里,SS子串 是通过从 SS 的开头删除零个或多个字符,以及从 SS 的结尾删除零个或多个字符得到的字符串。 例如,ababc 的子串,但 ac 不是 abc 的子串。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given a string SS of length NN. You are also given QQ queries, which you should process in order.

The ii-th query is as follows:

  • Given an integer XiX_i and a character CiC_i, replace the XiX_i-th character of SS with CiC_i. Then, print the number of times the string ABC appears as a substring in SS.

Here, a substring of SS is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of SS.
For example, ab is a substring of abc, but ac is not a substring of abc.

Constraints

  • 3N2×1053 \le N \le 2 \times 10^5
  • 1Q2×1051 \le Q \le 2 \times 10^5
  • SS is a string of length NN consisting of uppercase English letters.
  • 1XiN1 \le X_i \le N
  • CiC_i is an uppercase English letter.

Input

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

NN QQ

SS

X1X_1 C1C_1

X2X_2 C2C_2

\vdots

XQX_Q CQC_Q

Output

Print QQ lines. The ii-th line (1iQ)(1 \le i \le Q) should contain the answer to the ii-th query.

Sample Input 1

7 4
ABCDABC
4 B
3 A
5 C
4 G

Sample Output 1

2
1
1
0

After processing each query, SS becomes as follows.

  • After the first query: S=S= ABCBABC. In this string, ABC appears twice as a substring.
  • After the second query: S=S= ABABABC. In this string, ABC appears once as a substring.
  • After the third query: S=S= ABABCBC. In this string, ABC appears once as a substring.
  • After the fourth query: S=S= ABAGCBC. In this string, ABC appears zero times as a substring.

Sample Input 2

3 3
ABC
1 A
2 B
3 C

Sample Output 2

1
1
1

There are cases where SS does not change through processing a query.

Sample Input 3

15 10
BBCCBCACCBACACA
9 C
11 B
5 B
11 B
4 A
8 C
8 B
5 B
7 B
14 B

Sample Output 3

0
0
0
0
1
1
2
2
1
1