Can anyone tell me why my BS approach gives TLE but sorting queries approach does not. Both solutions have the same complexity. Both solutions here -
BS - https://pastebin.com/PyhCsSj0
Sorting queries - https://pastebin.com/D5QV9TJH
Hey. So this question i had solved in java on the contest day, and the submission from that day is here. And today, after fruitlessly racking my brain for where the NZEC could have arised, i submitted the same code, and you know it, it showed full AC. Today’s code is here. So what did actually transpire by on the contest day? I am totally perplexed and an answer would be so satisfying.
My [solution][1] during contest got 30 pts with a WA for second test and the same
[2] in practice got AC(100 pts).
This seems to be a bug as [this comment][3] is also similar and I am getting weird results in other problems too.
[1]: https://www.codechef.com/viewsolution/20374448
[2]: https://www.codechef.com/viewsolution/20442402
[3]: https://discuss.codechef.com/questions/136251/chefres-editorial/136345
You’re passing on the vector in int binarysearch(vector<pair<ll,ll> > v1,ll l,ll r,ll key) by value, so you copy a vector of pairs for every single call to binary search. Make that a reference int binarysearch(vector<pair<ll,ll> > &v1,ll l,ll r,ll key) and you should get decent running times.
I am using binary search and also pass my vector by reference, still got tle. Please help me, what could i do to decrease the time?
Here is my solution link - https://www.codechef.com/submit/complete/20938161. Please help.