Count ABC Again

AtCoder
IDabc372_c
Time2000ms
Memory256MB
Difficulty
You are given a string $S$ of length $N$. You are also given $Q$ queries, which you should process in order. The $i$\-th query is as follows: * Given an integer $X_i$ and a character $C_i$, replace the $X_i$\-th character of $S$ with $C_i$. Then, print the number of times the string `ABC` appears as a substring in $S$. Here, a **substring** of $S$ is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of $S$. For example, `ab` is a substring of `abc`, but `ac` is not a substring of `abc`. ## Constraints * $3 \le N \le 2 \times 10^5$ * $1 \le Q \le 2 \times 10^5$ * $S$ is a string of length $N$ consisting of uppercase English letters. * $1 \le X_i \le N$ * $C_i$ is an uppercase English letter. ## Input The input is given from Standard Input in the following format: $N$ $Q$ $S$ $X_1$ $C_1$ $X_2$ $C_2$ $\vdots$ $X_Q$ $C_Q$ [samples]
Samples
Input #1
7 4
ABCDABC
4 B
3 A
5 C
4 G
Output #1
2
1
1
0

After processing each query, $S$ becomes as follows.

*   After the first query: $S=$ `ABCBABC`. In this string, `ABC` appears twice as a substring.
*   After the second query: $S=$ `ABABABC`. In this string, `ABC` appears once as a substring.
*   After the third query: $S=$ `ABABCBC`. In this string, `ABC` appears once as a substring.
*   After the fourth query: $S=$ `ABAGCBC`. In this string, `ABC` appears zero times as a substring.
Input #2
3 3
ABC
1 A
2 B
3 C
Output #2
1
1
1

There are cases where $S$ does not change through processing a query.
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
Output #3
0
0
0
0
1
1
2
2
1
1
API Response (JSON)
{
  "problem": {
    "name": "Count ABC Again",
    "description": {
      "content": "You are given a string $S$ of length $N$. You are also given $Q$ queries, which you should process in order. The $i$\\-th query is as follows: *   Given an integer $X_i$ and a character $C_i$, replace",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc372_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a string $S$ of length $N$. You are also given $Q$ queries, which you should process in order.\nThe $i$\\-th query is as follows:\n\n*   Given an integer $X_i$ and a character $C_i$, replace...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments