Interval unions

4

1 votes
Datastructures, Segment tree, Dynamic Programming, Algorithms, Binary search tree
Problem

You are given \(n\) intervals and their starts are all unique and also their ends are all unique. No two intervals may include each other (means there are no two different intervals \([l, r]\) and \([L, R]\) which \(l \leq L < R \le r\)).
Count the number of subsets of intervals in which their union is as same as all \(n\) intervals union modulo \(10^9+7\).
Formally, consider the interval's set \(A\) and count the number \(B \subseteq A\) which \(\cup_{i \in A} i = \cup_{i \in B} i\) modulo \(10^9+7\).

The union of two intervals \([l, r]\) and \([L, R]\) displayed as \([l, r] \cup [L, R]\) is \(\{ x\in\mathbb{R} \ | \ l \le x \le r \ \mbox{or} \ L \le x \le R \}\).

Input format

  • The first line contains only an integer \(n\) denoting the number of intervals.
  • Next \(n\) lines contain two space-separated integers \(l_i\) and \(r_i\) (\(l_i < r_i\)) the interval is \([l_i, r_i]\).

    \(1 \leq n \leq 3 \times 10^5\)

    \(1 \leq l_i < r_i \leq 10^9\)

    It is guaranteed all \(l_i\)s are unique and also all \(r_i\)s are unique. No two intervals may include each other.

Output format

The output contains an integer denoting the number of subsets with provided conditions modulo \(10^9+7\).

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

All intervals else third interval must be in the subset, the third interval can be or not be in the subset, so the answer is \(2\).

Editor Image

?