欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1609B.William the Vigilant
William the Vigilant

Before becoming a successful trader William got a university degree. During his education an interesting situation happened, after which William started to listen to homework assignments much more attentively. What follows is the correct formal description of the homework assignment:
You are given a string of length only consisting of characters "a", "b" and "c". There are queries of format (), meaning replacing the element of string at position with character . After each query you must output the minimal number of characters in the string, which have to be replaced, so that the string doesn't contain string "abc" as a substring. A valid replacement of a character is replacing it with "a", "b" or "c".
A string is a substring of a string if can be obtained from by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
Input
The first line contains two integers and , the length of the string and the number of queries, respectively.
The second line contains the string , consisting of characters "a", "b" and "c".
Each of the next lines contains an integer and character , index and the value of the new item in the string, respectively. It is guaranteed that character's value is "a", "b" or "c".
Output
For each query output the minimal number of characters that would have to be replaced so that the string doesn't contain "abc" as a substring.
Note
Let's consider the state of the string after each query:
- "
abcabcabc". In this case replacements can be performed to get, for instance, string "bbcaccabb". This string does not contain "abc" as a substring. - "
bbcabcabc". In this case replacements can be performed to get, for instance, string "bbcbbcbbc". This string does not contain "abc" as a substring. - "
bccabcabc". In this case replacements can be performed to get, for instance, string "bccbbcbbc". This string does not contain "abc" as a substring. - "
bcaabcabc". In this case replacements can be performed to get, for instance, string "bcabbcbbc". This string does not contain "abc" as a substring. - "
bcabbcabc". In this case replacements can be performed to get, for instance, string "bcabbcabb". This string does not contain "abc" as a substring. - "
bcabccabc". In this case replacements can be performed to get, for instance, string "bcabbcabb". This string does not contain "abc" as a substring. - "
bcabccaac". In this case replacements can be performed to get, for instance, string "bcabbcaac". This string does not contain "abc" as a substring. - "
bcabccaab". In this case replacements can be performed to get, for instance, string "bcabbcaab". This string does not contain "abc" as a substring. - "
ccabccaab". In this case replacements can be performed to get, for instance, string "ccabbcaab". This string does not contain "abc" as a substring. - "
ccaaccaab". In this case the string does not contain "abc" as a substring and no replacements are needed.
Samples
9 10
abcabcabc
1 a
1 b
2 c
3 a
4 b
5 c
8 a
9 b
1 c
4 a
3
2
2
2
1
2
1
1
1
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |