MARBLEGF help!

The problem can be solved using brute force and BIT as well.
I tried to solve it using segment tree with point updates, but getting WA.
Can anyone help or maybe give a test case where it fails?
Here’s my code (


[1])

Here's the [Problem Link][2]

Thanks!





  [1]: https://www.codechef.com/viewsolution/14397442
  [2]: https://www.codechef.com/problems/MARBLEGF/

Your code needed these changes :-

In the functions - build(), update(), query(), the variable mid = (start + end) / 2, but 0 <= start, end <= 10^6 and all these variables are of type int so an overflow may occur. You can change the data type to long long or write it like this: mid = start + (end - start) / 2 to prevent overflow.

Also, in function query(), you are returning v1 + v2. Both are of type int, but the answer may not fit in int. So change the data type of v1 and v2 to long long.

Using these changes, here is your accepted code (AC).

https://www.codechef.com/viewsolution/14398075

@c_utkarsh Thanks!