1234D.md (1574B)
1 Source: https://codeforces.com/problemset/problem/1234/D 2 3 D. Distinct Characters Queries 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given a string $s$ consisting of lowercase Latin letters and $q$ queries for this string. 22 23 Recall that the substring $s[l; r]$ of the string $s$ is the string $s_l s_{l + 1} \dots s_r$. For example, the substrings of "codeforces" are "code", "force", "f", "for", but not "coder" and "top". 24 25 There are two types of queries: 26 27 * $1~ pos~ c$ ($1 \le pos \le |s|$, $c$ is lowercase Latin letter): replace $s_{pos}$ with $c$ (set $s_{pos} := c$); 28 * $2~ l~ r$ ($1 \le l \le r \le |s|$): calculate the number of distinct characters in the substring $s[l; r]$. 29 30 Input 31 32 The first line of the input contains one string $s$ consisting of no more than $10^5$ lowercase Latin letters. 33 34 The second line of the input contains one integer $q$ ($1 \le q \le 10^5$) — the number of queries. 35 36 The next $q$ lines contain queries, one per line. Each query is given in the format described in the problem statement. It is guaranteed that there is at least one query of the second type. 37 38 Output 39 40 For each query of the second type print the answer for it — the number of distinct characters in the required substring in this query. 41 42 Examples 43 44 Input 45 46 ``` 47 abacaba 48 5 49 2 1 4 50 1 4 b 51 1 5 b 52 2 4 6 53 2 1 7 54 ``` 55 56 Output 57 58 ``` 59 3 60 1 61 2 62 ``` 63 64 Input 65 66 ``` 67 dfcbbcfeeedbaea 68 15 69 1 6 e 70 1 4 b 71 2 6 14 72 1 7 b 73 1 12 c 74 2 6 8 75 2 1 6 76 1 7 c 77 1 2 f 78 1 10 a 79 2 7 9 80 1 10 a 81 1 14 b 82 1 1 f 83 2 1 11 84 ``` 85 86 Output 87 88 ``` 89 5 90 2 91 5 92 2 93 6 94 ```