Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

Me_iS_NooB's blog

By Me_iS_NooB, history, 2 years ago, In English

i was trying to solve this problem:- https://codeforces.me/contest/1801/problem/B

My solution :- https://codeforces.me/contest/1801/submission/278323418

In my solution i wrote a O(nlogn) solution and the judge is showing time limit exceeded. But in editorial the solution given is O(nlogn) and that is getting passed. I am having trouble understanding how this is happening.

plzz help :,(

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

set has its own object function lower_bound to use. Do not use lower_bound in algorithm.h, as performing it on set would most of the time cause an $$$\mathcal{O}(n)$$$ time complexity per call.

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Resubmitted but WA: 278326222. Well, since I didn't solve this one yet, I wouldn't give further advice, but at least the TLE is dealt with.

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    why lower_bound that isn't method in set object act in o(n)

    • »
      »
      »
      2 years ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Please refer to this:

      However, if ForwardIt is not a LegacyRandomAccessIterator, the number of iterator increments is linear in $$$N$$$.

      Notably, std::map, std::multimap, std::set, and std::multiset iterators are not random access, and so their member lower_bound functions should be preferred.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Cuz your sol is not O(nlogn), dummy.