Segment Trees

www.spoj.com/problems/GSS1