Need help in spoj-GSS1 problem

Hi, I was trying to solve the spoj-GSS1 problem(link). I can realize that I have to keep four information in each node of the segment tree (maxsum, prefixsum, suffixsum and sum). I have read this tutorial and has no problem in building the tree. I am facing some difficulties with the queries. Please someone explain how to answer the queries.

Maybe this


[1] can help you understand everything :).


  [1]: https://ideone.com/XUtwzc