202k views
3 votes
You are given a string S of length N consisting of lowercase English letters.

Process Q queries of the following two types:

Type 1: change the iq-th character of S to cq. (Do nothing if the iq-th character is already cq.)
Type 2: answer the number of different characters occurring in the substring of S between the lq-th and rq-th characters (inclusive).
Constraints

N, Q, iq, lq, and rq are integers.
S is a string consisting of lowercase English letters.
cq is a lowercase English letter.
1≤N≤500000
1≤Q≤20000
|S|=N
1≤iq≤N
1≤lq≤rq≤N
There is at least one query of type 2 in each testcase.
Input

Input is given from Standard Input in the following format:

N
S
Q
Query1
⋮⋮
QueryQ
Here, Queryi in the 4-th through (Q+3)-th lines is one of the following:

1 iq cq
2 lq rq
Output

For each query of type 2, print a line containing the answer.

Sample Input 1

7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7
Sample Output 1

3
1
5
In the first query, cdbb contains three kinds of letters: b , c , and d, so we print 3.

In the second query, S is modified to abcdzbd.

In the third query, a contains one kind of letter: a, so we print 1.

In the fourth query, S is modified to abcazbd.

In the fifth query, S does not change and is still abcazbd.

In the sixth query, abcazbd contains five kinds of letters: a, b, c, d, and z, so we print 5.

User KRH
by
7.7k points

1 Answer

4 votes

Final answer:

The correct answer for the transformation question is to apply the given letter changes to the word to achieve the desired result, and for spelling, use the English spelling rule 'i before e, except after c'.

Step-by-step explanation:

The correct answer involves manipulating letters of the alphabet according to specific instructions. Using the example 'change the first letter in the word to the letter that comes right after it in the alphabet, make the second letter in the word a , and change the to the twenty-first letter of the alphabet', if we start with the word 'bat', following the instructions results in:

  • Changing 'b' to 'c' (the next letter in the alphabet)
  • Changing the second letter to 'c'
  • Changing 'a' to 'u' (the twenty-first letter of the alphabet)

The final transformed word is 'ccu'.

For the spelling transformation rules, the student needs to apply the classic English spelling rule 'i before e, except after c or when sounded like 'a' as in 'neighbor' and 'weigh''. This guideline helps in transforming words accurately according to provided instructions.

User The Big Kahuna
by
8.4k points