RoAlgo Contest #12 - NiceContest | D. Nice Compatibility

This was the problem page during the contest. Access the current page here.
Time limit: 0.35s Memory limit: 128MB Input: Output:

Bobi has NN toys that can be colored in various colors. For each color, the interval [Li,Ri][L_i, R_i] is known, meaning that any toy in the interval [Li,Ri][L_i, R_i] can be colored in color ii. A subset of toys is considered compatible if there exists at least one common color in which they can all be colored.

Task

Count how many compatible subsets of toys exist, modulo 109+7{10}^{9}+7.

Input data

The first line contains the numbers NN and KK, representing the number of toys and the number of colors, respectively.
The next KK lines contain two integers LiL_i and RiR_i, representing the interval of toys that can be colored in color ii.

Output data

Print a single number representing the number of compatible subsets of toys, modulo 109+7{10}^{9}+7.

Constraints and clarifications

  • 1N1 000 000 0001 \leq N \leq 1 \ 000 \ 000 \ 000
  • 1K201 \leq K \leq 20
  • 1LiRiN1 \leq L_i \leq R_i \leq N
  • For test cases worth 55 points, N20N \leq 20
  • For other test cases worth 2525 points, N10.000,K10N \leq 10.000, K \leq 10

Example 1

stdin

5 3
1 4
2 3
4 5

stdout

18

Explanation

The compatible subsets are: \empty, {1}\{1\}, {2}\{2\}, {3}\{3\}, {4}\{4\}, {5}\{5\}, {1,2}\{1, 2\}, {1,3}\{1, 3\}, {1,4}\{1, 4\}, {2,3}\{2, 3\}, {2,4}\{2, 4\}, {3,4}\{3, 4\}, {4,5}\{4, 5\}, {1,2,3}\{1, 2, 3\}, {1,2,4}\{1, 2, 4\}, {1,3,4}\{1, 3, 4\}, {2,3,4}\{2, 3, 4\}, and {1,2,3,4}\{1, 2, 3, 4\}. For example, the subset {1,5}\{1, 5\} would not be compatible because toys 11 and 55 do not have a common color.

Example 2

stdin

5 1
1 5

stdout

32

Explanation

All subsets are compatible.

Log in or sign up to be able to send submissions!