O(n log n)使用平衡的二进制搜索树可以及时解决此问题。这是此算法的伪代码:
tree = an empty balanced binary search treeanswer = 0for each element in the array: answer += number of the elements in the tree greater then this element add this element to the tree

O(n log n)使用平衡的二进制搜索树可以及时解决此问题。这是此算法的伪代码:
tree = an empty balanced binary search treeanswer = 0for each element in the array: answer += number of the elements in the tree greater then this element add this element to the tree