deepak_097's blog

By deepak_097, history, 6 years ago, In English

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

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.