How can solve this-> http://www.lightoj.com/volume_showproblem.php?problem=1083 problem with segment tree. Please give me some hints.. Thanks..
№ | Пользователь | Рейтинг |
---|---|---|
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 |
How can solve this-> http://www.lightoj.com/volume_showproblem.php?problem=1083 problem with segment tree. Please give me some hints.. Thanks..
Название |
---|
I think it is not segment tree problem.It is just histogram problem.You have to find largeast area with stack.
But this problem one of the segment tree section problem.. http://www.lightoj.com/volume_problemcategory.php?user_id=22253&category=Segment%20Tree/Interval%20Tree
can you please, post/paste the question. link in the question is redirecting for sign up :(
Like Kerim.K suggested above, this problem can be solved in a simpler and faster way with a stack, but I think you're asking specifically for the Segment Tree solution, so I'll explain it.
You can use the Segment Tree to find, for every element, the rightmost element to the left and the leftmost element to the right that have a lower height. Let those indices be l and r respectively, and the height of the current element be h, then the area of the rectangle you can create is h * (r - l - 1). To do this with the Segment Tree, the parameter is the height and the value you update it with is the index. You can either use 2 different Segment Trees (one for min queries and the other for max queries) or you can get away with a single Segment Tree by negating values and initializing accordingly. I'll share my code, which uses one single Segment Tree.
would you explain more about your update function? how is it working?
It's a regular update function for a Max Segment Tree. The only trick is that when we query for minimum element, instead of changing functions for updating and querying, we just use negative values.