Number of pairs of indexes of two arrays such that one element is greater than the other
When $A = B$, this is the same as counting the number of inversions, which can be accomplished in $O(n\log n)$ time using a divide-and-conquer algorithm, and in $O(n\sqrt{\log n})$ time using more sophisticated techniques (see Counting Inversions, Offline Orthogonal Range Counting, and Related Problems by Chan and Pătraşcu).



In the other direction, here is how to solve a similar but not identical problem.

Given $A,B$, let us construct the following array:
$$
C := A[1],B[1],A[2],B[2],\ldots,A[n],B[n].
$$
An inversion in this array is one of the follows:


A pair $A[i] &gt; A[j]$ for $i &lt; j$.
A pair $B[i] &gt; B[j]$ for $i &lt; j$.
A pair $A[i] &gt; B[j]$ for $i &lt; j$.
A pair $B[i] &gt; A[j]$ for $i &lt; j$.
A pair $A[i] &gt; B[i]$.


Therefore you can deduce the number of $i &lt; j$ such that either $A[i] &gt; B[j]$ or $B[i] &gt; A[j]$ given the number of inversions in each of $A,B,C$, augmented by the number of indices $i$ such that $A[i] &gt; B[i]$. This yields a simple $O(n\log n)$ algorithm and a more complicated $O(n\sqrt{\log n})$ algorithm, as described above.