#P6146. [USACO20FEB] Help Yourself G

[USACO20FEB] Help Yourself G

Description

There are NN segments on a number line. The ii-th segment covers all real numbers from lil_i to rir_i (including lil_i and rir_i).

Define the union of some segments as the set of all points that are covered by at least one segment.

Define the complexity of some segments as the number of connected components formed by the union of these segments.

Now Bessie wants to compute, for all subsets of the given NN segments (there are 2N2^N in total), the sum of their complexities, and output the result modulo 109+710^9+7.

You might have guessed that you need to help Bessie solve this problem. But unfortunately, you guessed wrong! In this problem, you are Bessie, and nobody will help you. It is all up to you.

Input Format

The first line contains an integer NN (1N1051 \leq N \leq 10^5).

The next NN lines each contain two integers li,ril_i, r_i, describing a segment. It is guaranteed that 1li<ri2N1 \leq l_i \lt r_i \leq 2N, and no two endpoints are at the same position.

Output Format

Output the required answer modulo 109+710^9+7.

3
1 6
2 3
4 5
8

Hint

Sample Explanation

The complexities of all non-empty subsets are as follows (clearly, the empty set has complexity 00):

$$\{[1,6]\} \implies 1, \{[2,3]\} \implies 1, \{[4,5]\} \implies 1$$$$\{[1,6],[2,3]\} \implies 1, \{[1,6],[4,5]\} \implies 1, \{[2,3],[4,5]\} \implies 2$${[1,6],[2,3],[4,5]}    1\{[1,6],[2,3],[4,5]\} \implies 1

So the answer is 1+1+1+1+1+2+1=81+1+1+1+1+2+1=8.

Subtasks

  • Test points 232 \sim 3 satisfy N16N \leq 16.
  • Test points 474 \sim 7 satisfy N1000N \leq 1000.
  • Test points 8128 \sim 12 have no special constraints.

Translated by ChatGPT 5