ALGORITHMIST2 AND PHEONIX123 SHOWING WA

Problem Link :BAADSHAH Problem - CodeChef my solution:CodeChef: Practical coding for everyone

1 Like

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.

1 Like

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
4 Likes

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 :frowning:

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;
1 Like

i am trying to debug your code for the last one hour but unable to find the mistake.

2 Likes

yes I have also been tryng bt no luck… :(… okay if you find anything please comment here…Thanks for your help… :slight_smile:

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. :slight_smile:

You can follow these:

1 Like

thanks a lot utkarsh and sudip…

1 Like

Thankyou so much, I also faced the same problem.

Dude did you take this implementation of segment tree from GFG?