getting WA in 'the problem set' question from ACMKAN14!

i have used segmented tree concept for this problem…
here is my


[1]


  [1]: http://ideone.com/5GnsNa