Square Root Decomposition approach for Subsegment Sum(SEGSM) gives WA

Can anyone please go through my code and provide any insight on what my mistake is? You can see the question on https://www.codechef.com/problems/SEGSM and my solution is https://www.ideone.com/nJap4V.

I’ve named the functions meaningfully so understanding the flow should be quite easy as well. In brief, I’ve employed value compression to bring the range of numbers to a manageable state and used square root decomposition to calculate the frequency sum. Any help would be much appreciated.

Thanks in advance.

//