SPOJ [ BRCKTS — Brackets ] problem.
Problem Link- link
I am getting WA on this question can't figure it out where I am going wrong. I tested many cases in which my code is passing correctly :(. Please help me to get rid of this problem.
My solution- link
Your update function.
Instead of if(s==idx)
if(s==idx)
Write if(s==e) and you should be good to go.
if(s==e)
Just the statement if(s==idx) doesn't check if it's a leaf node as well, so it will modify every time a segment tree node starts with 's'.
Test case, in case you want to see a difference:
2 )) 2 1 0
Your code outputs NO, after changing to s==e, it outputs YES, answer is YES.
s==e
Your update function.
Instead of
if(s==idx)
Write
if(s==e)
and you should be good to go.Just the statement
if(s==idx)
doesn't check if it's a leaf node as well, so it will modify every time a segment tree node starts with 's'.Test case, in case you want to see a difference:
2 )) 2 1 0
Your code outputs NO, after changing to
s==e
, it outputs YES, answer is YES.