SPOJ Problem:Great Ball

Hi

In http://www.ahmed-aly.com/ the SPOJ Problem: Great Ball is stacked under Segment Tree. I have solved this problem using a separate algorithm, but as I am learning Segment Trees currently, I was hoping if any one here could point me to how this same problem can be solved using Segment Trees. I need a small hint, or a discussion. No solutions pls :slight_smile:

Prolem link:Great Ball

//