#abc372c. C - Count ABC Again
C - Count ABC Again
Score : points
问题陈述
你得到了一个长度为 的字符串 。你还得到了 个查询,你应该按顺序处理它们。
第 个查询如下:
- 给定一个整数 和一个字符 ,将 中的第 个字符替换为 。然后,打印字符串
ABC
作为子串在 中出现的次数。
这里, 的 子串 是通过从 的开头删除零个或多个字符,以及从 的结尾删除零个或多个字符得到的字符串。
例如,ab
是 abc
的子串,但 ac
不是 abc
的子串。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a string of length . You are also given queries, which you should process in order.
The -th query is as follows:
- Given an integer and a character , replace the -th character of with . Then, print the number of times the string
ABC
appears as a substring in .
Here, a substring of is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of .
For example, ab
is a substring of abc
, but ac
is not a substring of abc
.
Constraints
- is a string of length consisting of uppercase English letters.
- is an uppercase English letter.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the -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, becomes as follows.
- After the first query:
ABCBABC
. In this string,ABC
appears twice as a substring. - After the second query:
ABABABC
. In this string,ABC
appears once as a substring. - After the third query:
ABABCBC
. In this string,ABC
appears once as a substring. - After the fourth query:
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 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