[Help]How can this problem be solved ?

I am working on this problem . As I am a newbie in algorithm designing , I wanted to know how can we solve this problem. Please help me in figuring this out in brief.

P.S. - A tutorial can be a great help for many other people like me who wants to learn.

Thanks In Advance.

The solution is pretty straight forward - solution

you can solve it by using segment tree.
For more detail plz see this link:-https://www.topcoder.com/community/data-science/data-science-tutorials/range-minimum-query-and-lowest-common-ancestor/

brute force passing?? wow

u can use two segment trees one for min and one for max. thats it done.