Description:
Given a source interval [x, y] and N unordered target intervals [X1, Y1], [X2, y2],... [XN, Y,]: determines that the given source range [x, y] is not in the target range.
For example, if the source interval [1 6] and the target interval [1 2] [2 4] [4 9] are given, the interval [1 6] is considered to be within the target interval, because the union of the source interval is [1 9].
Imagine that in such a set of target intervals, You Need To frequently query whether an interval is in the set. How can we reduce the complexity of a single query?
Complexity. Preprocessing. The pre-processing of intervals can meet such requirements.
Direct Method:
Step 1: First merge the intervals (that is, make the range merge a set of non-Intersecting intervals)
Step 2: Search for the source interval in the interval after processing. Of course, binary search can have a good effect, so you can sort the interval.
So: 1 sorts the intervals by their starting points.
2 merge intersection Interval
You can search for the source interval in the third-byte mode.
The Code is as follows:
[Algorithm] interval coincidence judgment