I have a a list of a million pairs of integers (a,b)
. How can I prepare a data structure in python with the following property? When I see a new pair of integers I would like to be able to tell if it overlaps any existing pair in my list very quickly? Assuming b > a
and d > c
I say that (a,b) and (c,d) overlap if (a <= c
and b >= c
) or (a<=d
and b>=d
) or both a and b are between c and d.
Can this be done somehow in log time?