#K65167. Process Queries on a String
Process Queries on a String
Process Queries on a String
You are given an initial string s
of length \(n\) and a sequence of \(q\) queries. There are two types of queries:
- Type 1:
1 i c
— Replace the character at position \(i\) in the string with the character \(c\). - Type 2:
2 l r
— Count the number of distinct characters in the substring from position \(l\) to \(r\) (inclusive) and print the result.
For each query of type 2, output the answer on a new line. Note that the positions are 1-indexed.
inputFormat
The input is read from standard input (stdin) and has the following format:
The first line contains two integers (n) and (q) — the length of the string and the number of queries.
The second line contains the string s
.
The next (q) lines each contain a query in one of the two formats:
1 i c
— Update the character at position \(i\) to \(c\).2 l r
— Query the number of distinct characters between positions \(l\) and \(r\) (inclusive).
outputFormat
For each query of type 2, output a single integer on a new line representing the number of distinct characters in the specified substring.## sample
11 5
abracadabra
2 1 3
1 4 z
2 1 3
2 1 4
1 10 y
3
3
4
</p>