Hello everyone! How can I do this question using segment trees? what type of array to create? https://mirror.codeforces.com/problemset/problem/1234/D
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Hello everyone! How can I do this question using segment trees? what type of array to create? https://mirror.codeforces.com/problemset/problem/1234/D
Name |
---|
For solving this question with segment tree, you can have an array(say M) of size 26 in every node of segment tree. Suppose a particular node of segment tree hits the interval [L,R], the array value M[i] in that node stores the number of occurance of ith(i=char-'a') character in the range [L,R]. We can combine any two nodes simply by adding the number of the number of occurances in the two nodes. we can update also in the similar fashion. For answering queries you can get a combined node of all the ranges hit by query range in segmnet tree and then count the number of non zero value in the combined node.
There is another way to have a bool array in everynode rather that count array and then for paticular range, M[i] will be true if ith character is present in that range. Combination of two nodes will be simply 'or' operation on the corresponding nodes. At the end we can count the number of true values in the combined node formed after querying segtree.