c++ - n个数,要求插入,查找最大最小值,删除最大最小值的时间复杂度都限制在O(log2n),应该用什么算法?
黄舟
黄舟 2017-04-17 14:43:26
0
5
718

n个数,要求插入,查找最大最小值,删除最大最小值的时间复杂度都限制在O(log2n),应该用什么算法和数据结构?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(5)
小葫芦

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.

洪涛

Use balanced binary trees

洪涛

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.

迷茫

Line segment trees can be solved...

Peter_Zhu

Use set

in C++ STL
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!