Hello everyone! How can I do this question using segment trees? what type of array to create? https://codeforces.me/problemset/problem/1234/D
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
Hello everyone! How can I do this question using segment trees? what type of array to create? https://codeforces.me/problemset/problem/1234/D
Название |
---|
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.