give a sequence and each element is less than 2,000,000. there maybe exist reverse orde pair in the sequence . a reverse order pair is defined as a pair consisting of 2 elements: A and B, A appearing before B and A>B. Now what we should do is to find these reverse order pairs in the given sequence and the time complexity must be O(nlogn) or less.
hint: sorting and tree data structure can be used to solve the problem
my idea: use sorted binary tree to store the elements of the sequence and if there is no reverse pair in the sequence then no left subtree will exist. so what we should do is to count the depth of left subtree for every node in the sorted binary tree.
code:write a sorted binary tree and then traverse the tree in a depth-first way. for each node visited calculate the depth of left subtree of the node and count them all as total number of reverse order pairs.
major function: findPair,ldepth