Stucked in SPOJ GSS1

I have read and implemented segment trees recently and i am trying to solve this problem(GSS1) in spoj but wasn’t able to solve it…Then i read from different sources on internet on how to solve this problem but isn’t able to understand the combine part and why it works!!

can anyone please help me with an example on how to write the combine part?
I am stucked in this problem since the last 2 days.