atcoder#ABC157E. [ABC157E] Simple String Queries

[ABC157E] Simple String Queries

Score : 500500 points

Problem Statement

You are given a string SS of length NN consisting of lowercase English letters.

Process QQ queries of the following two types:

  • Type 11: change the iqi_q-th character of SS to cqc_q. (Do nothing if the iqi_q-th character is already cqc_q.)
  • Type 22: answer the number of different characters occurring in the substring of SS between the lql_q-th and rqr_q-th characters (inclusive).

Constraints

  • NN, QQ, iqi_q, lql_q, and rqr_q are integers.
  • SS is a string consisting of lowercase English letters.
  • cqc_q is a lowercase English letter.
  • 1N5000001 \leq N \leq 500000
  • 1Q200001 \leq Q \leq 20000
  • S=N|S| = N
  • 1iqN1 \leq i_q \leq N
  • 1lqrqN1 \leq l_q \leq r_q \leq N
  • There is at least one query of type 22 in each testcase.

Input

Input is given from Standard Input in the following format:

NN

SS

QQ

Query1Query_1

\vdots

QueryQQuery_Q

Here, QueryiQuery_i in the 44-th through (Q+3)(Q+3)-th lines is one of the following:

11 iqi_q cqc_q

22 lql_q rqr_q

Output

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

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

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

In the second query, SS is modified to abcdzbd.

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

In the fourth query, SS is modified to abcazbd.

In the fifth query, SS 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 55.