Doubt in SPOJ-Dquery

I tried to solve this spoj problem using MO’s algorithm and this is my implementation for it. I am getting NZEC error and couldn’t find the bug, help me out with this.

I referred this tutorial for MO’s algorithm