Как узнать, в каком интервале существует индекс, используя set>C++

Программы на C++. Форум разработчиков
Anonymous
Как узнать, в каком интервале существует индекс, используя set>

Сообщение Anonymous »


I have std::set intervals which it's values are some intervals, it is somthing similar to this:

{ 0, 5 }, { 5, 8 }, { 8, 10 } and I have a number x can I find in which interval it is using lower_bound or upper_bound?

I need a solution with O(log(N)) complexity.

Because I remember that I saw someone doing it someway like this:

int x; std::set intervals; cin >> x; auto ans = intervals.upper_bound({ x, INF }) and I don't remember what was the value of INF

Note: the intervals aren't intersecting.


Источник: https://stackoverflow.com/questions/730 ... airint-int

Вернуться в «C++»