Suppose you are given two sets $\{p_1, p_2,\dots , p_n\}$ and $\{q_1, q_2,\dots , q_n\}$ of $n$ points on the unit circle. Each point $p_i$ is connected to $q_i$ by a line segment. How could we count the number of intersections of all $n$ line segments in $O(n\log n)$? You could also see the problem in Jeff Erickson's book, Algorithms.
I have read the posts finding the number of intersections of n line segments with endpoints on two parallel lines and find the number of intersections of $n$ chords in $O(n \log^2 n$) time. So I think by use their idea we can solve the problem above, but I get stuck.