308990: CF1609B. William the Vigilant
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
William the Vigilant
题意翻译
给你一个长为 $n$ 的字符串,只包含 `abc` 三种字符。$q$ 次操作,每次把一个位置的字符改成给定字符,询问当前串至少修改几次满足不包含子串 `abc`。修改指把一个位置的字符修改成 `a`、`b`、`c` 三种字符之一。 $1\le n,q\le 10^5$。题目描述
![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1609B/bc27b81066321842bda936f44a55e1a8e3d4f0d8.png)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 $ s $ of length $ n $ only consisting of characters "a", "b" and "c". There are $ q $ queries of format ( $ pos, c $ ), meaning replacing the element of string $ s $ at position $ pos $ with character $ c $ . 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 $ x $ is a substring of a string $ y $ if $ x $ can be obtained from $ y $ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.输入输出格式
输入格式
The first line contains two integers $ n $ and $ q $ $ (1 \le n, q \le 10^5) $ , the length of the string and the number of queries, respectively. The second line contains the string $ s $ , consisting of characters "a", "b" and "c". Each of the next $ q $ lines contains an integer $ i $ and character $ c $ $ (1 \le i \le n) $ , index and the value of the new item in the string, respectively. It is guaranteed that character's $ c $ value is "a", "b" or "c".
输出格式
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.
输入输出样例
输入样例 #1
9 10
abcabcabc
1 a
1 b
2 c
3 a
4 b
5 c
8 a
9 b
1 c
4 a
输出样例 #1
3
2
2
2
1
2
1
1
1
0