Can anyone tell me where to find ..really nice article on it....
# | User | Rating |
---|---|---|
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 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Name |
---|
AFAIK it's a very simple data structure: it can PUSH number in O(log N), and POP_MEDIAN in O(log N). To create it, we can just create two balanced min-heaps (i.e. standard heaps, that can PUSH element in O(log N) and POP_MINIMUM in O(log N)), such that the lowest half of elements is saved in the first heap, and the second half - in the second heap. This allows us to find median quickly: the median is the minimal element of the second heap.
Now, I am wondering can I use STL in C++ for the task rather writing my own Heap...!
Now I know there is priority_queue available. But it implements either min heap or max heap.
How to bring them together and make something like Median Heap?
Changing the comparison function may be the option......I dont know..U tell me ......
Right. If you analyse e-maxx 's comment then you would realise that median heap can be implemented by maintaining two heaps and doing some operations to balance the number of elements in these two heaps.
You may test your implementation in this problem:
www.spoj.pl/problems/WEIRDFN