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.
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.
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 ispriority_queue
in STL.Line segment trees can be solved...
Use
in C++ STLset