I came across this problem:
https://discuss.codechef.com/questions/90675/segmentq-editorial
I understood the concept. But I am not able to understand the implementation, primarily because I am relatively new to Segment Trees. Can someone give clear, commented code that they wrote to solve the same problem and also explain the same?