Can somebody explain this?

I was solving this problem:https://www.codechef.com/INTW2020/problems/UCL1
AC code:https://www.codechef.com/viewsolution/31952709
RE error code:https://www.codechef.com/viewsolution/31952716
The difference between the above 2 codes is just a variable “root” at line 49 which is never used in the code after its initialization.I want to ask how can such a variable even causes a difference in verdicts?
@ssjgz @everule1

You are accessing out of bounds indices in segtree array, either make the size 4x the size of input, or make the range in upd and qry [1, n], instead of [0, n].

1 Like

Thanks a lot buddy! got an AC :smile: