can anyone help please comment?
I think the problem lies in your segment tree implementation. I’ve only changed your segment tree code with mine and mine got AC.
Another small advice! There are many easy and clean segment tree implementations you can find on the internet. Try to use them as you can’t implement such big codes in a real contest or it’ll take too much time and then more valuable time to debug.
Ok, I’ve found the bug. Try this:
Input 4 6 1 2 3 4 2 10 1 4 10 2 16 1 4 4 2 10 2 16 Your output Found 4 Found 4 Not Found Found 4 Expected Output Found 4 Found 4 Found 4 Not Found
It took me about an hour and half to find the bug in your code. I wish I had read the comment by @sudip_95, it would have saved a lot of time
Anyway, the bug in your code is that you are using array A to update the Segment Tree but, you are not updating the array A itself.
Just add the following line after update operation and your code will get AC.
arr[p] = q;
i am trying to debug your code for the last one hour but unable to find the mistake.
yes I have also been tryng bt no luck… :(… okay if you find anything please comment here…Thanks for your help…
thanks I will look into it.But can you tell why my segment tree code failed?? I have solved segment tree problem before with this implementation and they worked.And it would be also helpful if you can share some link of easier implementation.Thanks.
You can follow these:
thanks a lot utkarsh and sudip…
Thankyou so much, I also faced the same problem.
Dude did you take this implementation of segment tree from GFG?