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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đế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 of lowercase English letters, process operations. Command 1 pos c replaces the character at 1-based position by , even if it is already . Command 2 l r asks how many distinct character values occur in the contiguous substring , including both endpoints. Repeated occurrences of the same letter count once.
Input
The first line contains ; the second line contains . Each of the next 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): ; ; contains only lowercase English letters; each command is
1 pos c, ,clowercase, or2 l r, ; at least one type-2 query. - Subtask 2 (30 points): ; ; contains only lowercase English letters; each command is
1 pos c, ,clowercase, or2 l r, ; at least one type-2 query. - Subtask 3 (50 points): ; ; contains only lowercase English letters; each command is
1 pos c, ,clowercase, or2 l r, ; 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
2 1 4: substringabac, unique lettersabc, so print 3.1 4 b: replace position 4:c→b; current stringabababa. No output.1 5 b: replace position 5:a→b; current stringababbba. No output.2 4 6: substringbbb, unique lettersb, so print 1.2 1 7: substringababbba, unique lettersab, 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
2 1 4: substringaaaa, unique lettersa, so print 1.1 2 b: replace position 2:a→b; current stringabaa. No output.2 1 4: substringabaa, unique lettersab, so print 2.1 2 a: replace position 2:b→a; current stringaaaa. No output.1 4 z: replace position 4:a→z; current stringaaaz. No output.2 2 4: substringaaz, unique lettersaz, so print 2.