Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя Lix2002

Автор Lix2002, история, 11 месяцев назад, По-английски

Well I just found this wierd thing when I was doing the problem Codeforces Round 905 (Div. 3) Prob.D When I use std::find(set.begin(), set.end(), value) or std::lower_bound(set.begin(), set.end(), value), I would get a TLE. But instead of using that, when I replace them with set.find(value) or set.lower_bound(value) it passed smoothly and worked as expected. Why would this happened? Is there any difference between these two approaches?

  • Проголосовать: нравится
  • +14
  • Проголосовать: не нравится

»
11 месяцев назад, # |
  Проголосовать: нравится +22 Проголосовать: не нравится

If you look closely on documentation on cppreference you will see that the function std::lower_bound works in linear time if container iterators are not RandomAccess. Set iterators are Bidirectional. std::find works always in linear time. So set.find and set.lower_bound are coded specifically for set and they work in $$$O(\log n)$$$ time.