#C4239. String Query Processor

    ID: 47755 Type: Default 1000ms 256MiB

String Query Processor

String Query Processor

You are given a string S that consists only of lowercase English letters. You are also given Q queries to perform on the string. There are two types of queries:

  1. COUNT a b c: Count the number of occurrences of character ( c ) in the substring of S from index ( a ) to index ( b ) (inclusive). The string is 0-indexed.
  2. UPDATE a b: Update the character at index ( a ) of S to character ( b ).

For each COUNT query, output the result on a new line.

Input Constraints:

  • 1 \( \leq \) |S| \( \leq 10^5 \)
  • 1 \( \leq \) Q \( \leq 10^5 \)
  • For UPDATE queries, 0 \( \leq \) a \( < \) |S|
  • For COUNT queries, 0 \( \leq \) a \( \leq \) b \( < \) |S|

The input is read from standard input and the output is written to standard output.

Example:

Input:
abcdeabcd
4
COUNT 0 4 a
UPDATE 2 x
COUNT 0 4 a
COUNT 3 7 b

Output:
1
1
1

inputFormat

The first line contains the string S. The second line contains an integer Q, representing the number of queries. The following Q lines each contain a query in one of the following formats:

  • COUNT a b c
  • UPDATE a b

outputFormat

For each COUNT query, output an integer on a new line representing the count of character c in the specified substring.## sample

abcdeabcd
4
COUNT 0 4 a
UPDATE 2 x
COUNT 0 4 a
COUNT 3 7 b
1

1 1

</p>