#abc157e. E - Simple String Queries

E - Simple String Queries

Score : 500500 points

问题描述

你将得到一个长度为 NN 的由小写英文字母组成的字符串 SS

处理 QQ 个查询,查询有两种类型:

  • 类型 1:将 SS 中的第 iqi_q 个字符更改为 cqc_q。(如果第 iqi_q 个字符已经是 cqc_q,则无需执行任何操作。)
  • 类型 2:计算并回答在从第 lql_q 个到第 rqr_q 个(包括两端)字符之间的子串中出现的不同字符数。

以上为通义千问 qwen-max 翻译,仅供参考。

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.

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 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.

update @ 2024/3/10 17:15:00