Hi everyone, I am doing my first steps into segment trees. So I have coded a simple code( http://pastebin.com/GAUJHpZb ) for RMQ, for finding the minimum element in a range. But It doesn't seem to be working. Can someone check it, please?
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
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 |
Hi everyone, I am doing my first steps into segment trees. So I have coded a simple code( http://pastebin.com/GAUJHpZb ) for RMQ, for finding the minimum element in a range. But It doesn't seem to be working. Can someone check it, please?
Название |
---|
I think you should rewrite the
query
function. When asking the minimum value on a segment, we need to split the query in two smaller, and then take the minimum value of queries on these two segments, which your code does not do currently.How do you mean I am not doing so, I am calling it over (start,mid) and (mid,end)...at least I think so..
As also ocozalp mentioned, you need to return the minimum of the results of these two new queries, and return it as a result of the current query. Now only one of them is being returned.
I think this block has to be changed
into
also you should change this code block in order to calculate values both for left and right subtrees. ("else" block prevents your program to do so)
you should have a look at topcoder tutorial for segment trees.