Distinct Characters Queries CodeForces - 1234D(线段树求区间字母种类数)
You are given a string ss consisting of lowercase Latin letters and qq queries for this string.
Recall that the substring s[l;r]s[l;r] of the string ss is the string slsl+1…srslsl+1…sr. For example, the substrings of “codeforces” are “code”, “force”, “f”, “for”, but not “coder” and “top”.
There are two types of queries:
1 pos c1 pos c (1≤pos≤|s|1≤pos≤|s|, cc is lowercase Latin letter): replace sposspos with cc (set spos:=cspos:=c);
2 l r2 l r (1≤l≤r≤|s|1≤l≤r≤|s|): calculate the number of distinct characters in the substring s[l;r]s[l;r].
Input
The first line of the input contains one string ss consisting of no more than 105105 lowercase Latin letters.
The second line of the input contains one integer qq (1≤q≤1051≤q≤105) — the number of queries.
The next qq 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.
Output
For each query of the second type print the answer for it — the number of distinct characters in the required substring in this query.
Examples
Input
abacaba
5
2 1 4
1 4 b
1 5 b
2 4 6
2 1 7
Output
3
1
2
Input
dfcbbcfeeedbaea
15
1 6 e
1 4 b
2 6 14
1 7 b
1 12 c
2 6 8
2 1 6
1 7 c
1 2 f
1 10 a
2 7 9
1 10 a
1 14 b
1 1 f
2 1 11
Output
5
2
5
2
6
題意:給你一串字符串,問區(qū)間[l,r]有多少個不同的字符。
思路:跟之前的染色之后問有多少種顏色類似。因為小寫字母就26個,所以每一種字母就代表那個位置為1.利用或運算。
代碼如下:
努力加油a啊,(o)/~
總結(jié)
以上是生活随笔為你收集整理的Distinct Characters Queries CodeForces - 1234D(线段树求区间字母种类数)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: The Trip On Abandone
- 下一篇: Squared Permutation(