GSS3 SPOJ

Link :SPOJ.com - Problem GSS3

My Code:

For sample test case after updation at 0 3 -3 ,all the queries are working fine except 2-4 . I am not able to rectify why it is giving 9 as the output.
Please rectify