Help me in solving DELISH problem

Is there a solution to this problem with the segment tree?
Problem Link: DELISH Problem - CodeChef