### Hepic_Antony_Skarlatos's blog

By Hepic_Antony_Skarlatos, 7 years ago,

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

 » 7 years ago, # |   +8 Can u please post links to both the submission?
•  » » 7 years ago, # ^ |   0 upper_bound(){sorry it is not lower_bound() :P, but here do the same work) : http://codeforces.com/contest/527/submission/10646608
•  » » » 7 years ago, # ^ |   +3 try using left=width.upper_bound(val); instead of upper_bound(ALL(width),val);
 » 7 years ago, # | ← 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
 » 7 years ago, # |   +8 Use myset.lowerbound(myset.begin(), myset.end()) O(logn) instead std::lowerbound(myset.begin(), myset.end()) O(n)