How can solve this-> http://www.lightoj.com/volume_showproblem.php?problem=1083 problem with segment tree. Please give me some hints.. Thanks..
# | 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 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
How can solve this-> http://www.lightoj.com/volume_showproblem.php?problem=1083 problem with segment tree. Please give me some hints.. Thanks..
Name |
---|
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.