Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×

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

Автор Hepic_Antony_Skarlatos, 9 лет назад, По-английски

I was trying to solve a problem here in codeforces,and I used "set". I wanted to search for a value so I used "lower_bound". I submitted and I took TLE. After I changed a bit the source,and I used find() instead of lower_bound() and I passed all testcases. Why happens that? Is find() faster than lower_bound()??

Thank you !!!

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

»
9 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Can u please post links to both the submission?

»
9 лет назад, # |
Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится

This issue was already discussed on codeforces several times. The problem is that upper_bound and lower_bound require random-access iterators. Only in that case they work in O(logN). If iterators are not random-access (like in std::set) these functions work in O(N) time. Use width.upper_bound(val) instead of upper_bound(ALL(width),val) — it will work in O(logN) time

»
9 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Use
myset.lowerbound(myset.begin(), myset.end()) O(logn)
instead
std::lowerbound(myset.begin(), myset.end()) O(n)