proAakash's blog

By proAakash, history, 3 months ago, In English

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

My solution :- https://codeforces.net/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

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by proAakash (previous revision, new revision, compare).

»
3 months ago, # |
  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.

  • »
    »
    3 months ago, # ^ |
      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.

  • »
    »
    3 months ago, # ^ |
      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)

    • »
      »
      »
      3 months ago, # ^ |
        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.

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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