I have two sequences of numbers (a1, a2, ... , an) and (b1, b2, ... , bn). For any i, j ∈ [n] we say (ai, bi) and (aj, bj ) agree if either ai < aj ∧ bi < bj or ai > aj ∧ bi > bj I can assume that all numbers are different.) Otherwise they disagree. Let A be the number of pairs that agree, and D be the number of pairs that disagree. Give an algorithm to compute A − D in time O(n log n).
I have no ideas how to solve it by divide and conquer algorithms. Can someone help me?