n个数,要求插入,查找最大最小值,删除最大最小值的时间复杂度都限制在O(log2n),应该用什么算法和数据结构?
高洛峰2017-04-17 14:45:26
The two answers above have different starting points.
Balanced binary trees can be done, but the original sequence will be sorted.
In C++, both set and map can meet the requirements.
The line segment tree can find the maximum or minimum value of the interval without reordering.
There is no ready-made data structure available, you can write a template yourself.
PHP中文网2017-04-17 14:45:26
How do you use a balanced binary tree? Although it is feasible; but if it is only the maximum and minimum values, then you only need to use a heap
. There is a ready-made data structure in C++, which is priority_queue
in STL.