#K69642. Count Distinct Characters in Substrings Queries
Count Distinct Characters in Substrings Queries
Count Distinct Characters in Substrings Queries
You are given a string s and a list of queries. Each query can be one of two types:
- Query type 1: "1 l r" - For this query, consider the substring s[l...r] (inclusive) and determine the number of distinct characters in that substring.
- Query type 2: "2 k c" - For this query, update the character at index k of s to c.
You should process the queries in order and for every query of type 1, output the corresponding result. In other words, if there are m queries of type 1, your output should consist of m numbers, each on its own line.
Input Format: The input is given from standard input in the following format.
Let N be the length of string s and Q be the number of queries. The first line contains the string s. The second line contains an integer Q, the number of queries. Each of the following Q lines contains a query in one of the two forms described above.
Example:
abacaba 5 1 0 6 2 2 d 1 0 6 2 6 e 1 0 6
The output for the above example should be:
3 4 5
Notation: If a formula is needed, use LaTeX format. For instance, the substring from index \(l\) to \(r\) can be denoted as \(s[l \ldots r]\).
inputFormat
The input is read from standard input (stdin) and has the following structure:
- The first line contains a string s consisting of lowercase letters.
- The second line contains an integer Q, representing the number of queries.
- Each of the following Q lines contains a query in one of the following formats:
- 1 l r: A query to count the distinct characters in the substring \(s[l \ldots r]\).
- 2 k c: A query to update the character at index k of s to the character c.
Indices are 0-indexed.
outputFormat
For every query of type '1', output the number of distinct characters in the specified substring on a new line to standard output (stdout).
## sampleabacaba
5
1 0 6
2 2 d
1 0 6
2 6 e
1 0 6
3
4
5
</p>