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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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.