Euron problem hint,

Question link-

i am unable to get the hint / editorial for O(nlogn)
i can do it in O(n^2) which is giving me TLE.
can anyone please help me to understand the logic of this question.

I did it using BIT which support queries in log(n).
The question can be redefined as :
For each index i from [0,n-1], find the number of elements greater than a[i] in the range [0,i-1]. The answer in just the sum for all i.
You can find some blogs for such type of problem. Moreover, you can see my code here. If still, it is not clear, Let me know.