PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000178. Đếm ký tự khác nhau trên đoạn (Distinct Characters Queries)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm ký tự khác nhau trên đoạn (Distinct Characters Queries)

Distinct Characters Queries

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a string SS of lowercase English letters, process QQ operations. Command 1 pos c replaces the character at 1-based position pospos by cc, even if it is already cc. Command 2 l r asks how many distinct character values occur in the contiguous substring Sl…SrS_l\ldots S_r, including both endpoints. Repeated occurrences of the same letter count once.

Input

The first line contains SS; the second line contains QQ. Each of the next QQ lines is 1 pos c or 2 l r.

Output

For each type-2 command, print the distinct-letter count in query order. At least one type-2 query is guaranteed.

Subtasks

  • Subtask 1 (20 points): 1≤∣S∣≤301\le |S|\le 30; 1≤Q≤1001\le Q\le 100; SS contains only lowercase English letters; each command is 1 pos c, 1≤pos≤∣S∣1\le pos\le |S|, c lowercase, or 2 l r, 1≤l≤r≤∣S∣1\le l\le r\le |S|; at least one type-2 query.
  • Subtask 2 (30 points): 1≤∣S∣≤30001\le |S|\le 3000; 1≤Q≤50001\le Q\le 5000; SS contains only lowercase English letters; each command is 1 pos c, 1≤pos≤∣S∣1\le pos\le |S|, c lowercase, or 2 l r, 1≤l≤r≤∣S∣1\le l\le r\le |S|; at least one type-2 query.
  • Subtask 3 (50 points): 1≤∣S∣≤1000001\le |S|\le 100000; 1≤Q≤1000001\le Q\le 100000; SS contains only lowercase English letters; each command is 1 pos c, 1≤pos≤∣S∣1\le pos\le |S|, c lowercase, or 2 l r, 1≤l≤r≤∣S∣1\le l\le r\le |S|; at least one type-2 query.

Examples

Example 1

Input

abacaba
5
2 1 4
1 4 b
1 5 b
2 4 6
2 1 7

Output

3
1
2

Explanation

  1. 2 1 4: substring abac, unique letters abc, so print 3.
  2. 1 4 b: replace position 4: c → b; current string abababa. No output.
  3. 1 5 b: replace position 5: a → b; current string ababbba. No output.
  4. 2 4 6: substring bbb, unique letters b, so print 1.
  5. 2 1 7: substring ababbba, unique letters ab, so print 2.

Example 2

Input

aaaa
6
2 1 4
1 2 b
2 1 4
1 2 a
1 4 z
2 2 4

Output

1
2
2

Explanation

  1. 2 1 4: substring aaaa, unique letters a, so print 1.
  2. 1 2 b: replace position 2: a → b; current string abaa. No output.
  3. 2 1 4: substring abaa, unique letters ab, so print 2.
  4. 1 2 a: replace position 2: b → a; current string aaaa. No output.
  5. 1 4 z: replace position 4: a → z; current string aaaz. No output.
  6. 2 2 4: substring aaz, unique letters az, so print 2.