How to solve this segment tree problem?

http://www.codechef.com/AICL2014/problems/ACMICL04 .
Can anyone give an approach to solve this segment tree problem.