Why some test cases are showing WA?

mergesort
segment-tree
wrong-answer

#1

This is my solution to the problem PSHTRG. Can anyone please help me to find the bug in the code.

Note: I have followed this editorial.