Help in GGSPAG--problem codechef

I have used fenwic tree to solve this problem .
Costum test cases are passing but on submission it gives WA??
Problem link:https://www.codechef.com/problems/GGSPAG
My code link:https://www.codechef.com/viewsolution/36031387