#C2120. Perform Queries on a String
Perform Queries on a String
Perform Queries on a String
You are given a string of length \(n\) consisting of lowercase English letters and \(q\) queries to perform on it. There are two types of queries:
1 l r c
: For the substring from position \(l\) to \(r\) (1-indexed), replace each occurrence of the characterc
with the next character in the alphabet. Note that if \(c = 'z'\), it wraps around to become \(a\) (i.e. \(\text{next}(z)=a\)).2 l r
: For the substring from position \(l\) to \(r\), count the number of distinct characters and output the result.
The queries are executed in the order they are given. For each query of type 2, you are required to output the result on a new line.
inputFormat
The input is given from standard input (stdin) as follows:
- The first line contains two integers \(n\) and \(q\) separated by a space, where \(n\) is the length of the string and \(q\) is the number of queries.
- The second line contains a string \(s\) of length \(n\) consisting of lowercase English letters.
- The next \(q\) lines each contain a query.
Each query is in one of the two formats:
1 l r c
or 2 l r
, where \(l\) and \(r\) (1-indexed) specify the segment of the string.
outputFormat
For each query of type 2, output an integer representing the number of distinct characters in the specified substring. Each result should be printed on its own line to standard output (stdout).
## sample10 5
abcdefghij
2 1 6
1 3 5 c
2 1 6
1 1 10 w
2 1 10
6
5
9
</p>