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 lL<Rr).
Count the number of subsets of intervals in which their union is as same as all n intervals union modulo 109+7.
Formally, consider the interval's set A and count the number BA which iAi=iBi modulo 109+7.

The union of two intervals [l,r] and [L,R] displayed as [l,r][L,R] is {xR | lxr or LxR}.

Input format

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

    1n3×105

    1li<ri109

    It is guaranteed all lis are unique and also all ris 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 109+7.

Sample Input
6
28 30
3 9
6 11
17 27
7 12
16 19
Sample Output
2
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

?