CLPNT EDITORIAL

yes.

1 Like

can u explain whats wrong in line 27 with the help of a test case

look at my reply above

I tried a lot using binary search but it give WA , can anyone provide me some testcase where my solution will give WA , I will be highly grateful and obliged to the one who answers my query satisfactorily .
Thanks a lot in advance !
My submission link : CodeChef: Practical coding for everyone

When we pass an array to a function, a pointer is actually passed but when a vector is passed to a function, a copy of the vector is created, the changes made inside the function are not reflected outside because function has a copy.It probably has something to do with your issue

1 Like

Line 116.
binary_search() returns a bool, not int.

1 Like

did you open those two links? They are exactly same. Exact copy of each other.

@sampras123 here is my solution link CodeChef: Practical coding for everyone now it is showing TLE but during contest it was giving WA and i wasted my whole time on this question, if still there is any bug in my code please point it.

Here is my code with binary Search : CodeChef: Practical coding for everyone
Hope this helps. Thanks !!!

1 Like

I have made some changes to your code by removing functions, it worked!
(though I am not able to understand the reason for it).

Submission - CodeChef: Practical coding for everyone

solved the problem but instead of using binary searching i used linear like an idiot. Feelsbadman

Read the constraints, you don’t have to sort the vector.

Cool, I didn’t observe that

Yes , you are are getting TLE since For loop on Line number 36 , since in WORST time it is taking O(n ) for every Query so , we need to reduce it to O(log(n)) which can be done using Binary Search → refer my solution :slight_smile:CodeChef: Practical coding for everyone
(PS: i have used LOWER_BOUND Function which is similar to binary search )
std::upper_bound and std::lower_bound for Vector in C++ STL - GeeksforGeeks
this might help

thanks to the organiser ,nice problems indeed, @souradeep1999

question
got stuck in figuring out why i got TLE even if i implemented in required time complexity.
when i used python3 built in method for bs it got accepted code
but i implemented bs myself it show TLE TLE code ,
if any one can point out error i would be glad.
@jyoti369 @aadiupadhyay @cubefreak777 @jojo9910 @sampras123
thanks a ton in advance

1 Like

there is a difference between if (a=b) and if (a==b)

see there is one small difference in your code. Obviously first one gives WA since equality is done through ==.

Okay… I have copied your code in my editor and made a slight change between line no. 30 to 34
& got an AC code. Here is the link : CodeChef: Practical coding for everyone
It will not cost any overflow due to line no. 30 , therefore , WA/TLE verdict.
Hope this helps. THANKS !!!

1 Like

Easy approach :+1::+1:

Thank you for pointing it out.

@jyoti369 thanks a lot buddy >
thanks for entertaining stupid error of stupid guy (me).
my mistakes
i+=1 instead of i=mid+1
j-=1 instead of j=mid-1
thanks again