Getting wa in max-query 1 using merge sort trees

problem link: https://online.codingblocks.com/player/10881/content/21648/4858
code link: https://pastebin.com/4ACwa0Te

I have used merge sort trees to solve the problem but iam getting wa as verdict.