KQuery Wrong Answer

I have used Binary Tree and Offline Queries to solve this problem.
I am getting all WA , can’t figure out the mistake I am doing.
Ques Link:
https://hack.codingblocks.com/contests/c/547/968

My Code:
https://ide.codingblocks.com/s/54949