I have known about an O(n log^2 n) solution, it can deal with the general case where l[i] and r[i] are in range [0, n].
However, it got TLE on test 2.
I think it’s because this problem have the special constraint on l[i] and r[i] (we have l[i] = 0, r[i] = 1 for all i), with which we can make some further observations to optimize the general solution.
Looking forward to your reply. 