#P15129. [ROIR 2026] 筹码放置

    ID: 17040 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>动态规划 DP容斥原理2026单调栈ROIR(俄罗斯)

[ROIR 2026] 筹码放置

Problem Description

You are given a square board of size m×mm \times m. The rows and columns of the board are numbered from 11 to mm.

You need to place chips on the board so that each cell contains at most one chip. At the same time, you must satisfy nn constraints. The ii-th constraint gives two integers rir_i and cic_i, meaning that in the rectangular area with coordinates [1…ri]×[1…ci][1 \ldots r_i] \times [1 \ldots c_i], at most one chip can be placed.

Compute the number of different chip placement schemes that satisfy all constraints, and output the result modulo 109+710^9+7.

Input Format

The first line of the input contains two integers nn and mm — the number of constraints and the size of the board (1≤n≤2⋅1051 \le n \leq 2 \cdot 10^5, 1≤m≤1091 \leq m \le 10^9).

The next nn lines each contain two numbers rir_i and cic_i (1≤ri,ci≤m1 \le r_i, c_i \le m).

Output Format

Output one number — the number of valid chip placement schemes modulo 109+710^9+7.

1 4
4 4
17
2 2
1 2
2 1
10
3 5
2 5
3 4
4 4
4480

Hint

Sample Explanation

In the first sample, at most one chip can be placed on the entire board. There are 4×4=164 \times 4 = 16 ways to place one chip, and 11 way to place no chips.

Scoring Rules

Subtask Points Additional Constraints Required Subtasks
1 3 n≤10,m≤4n \le 10, m \le 4 ---
2 6 n=1,m≤1000n = 1, m \le 1000
3 8 n≤10,m≤1000n \le 10, m \le 1000 1, 2
4 n≤15,m≤109n \le 15, m \le 10^9 1–3
5 10 n≤2500,m≤100n \le 2500, m \le 100 1
6 n≤2500,m≤250n \le 2500, m \le 250 1, 5
7 n≤2500,m≤1000n \le 2500, m \le 1000 1–3, 5, 6
8 n≤2500,m≤105n \le 2500, m \le 10^5 1–3, 5–7
9 15 n≤2⋅105,m≤2⋅105n \le 2 \cdot 10^5, m \le 2 \cdot 10^5 1–3, 5–8
10 20 No additional constraints 1–9

Translated by DeepSeek.

Translated by ChatGPT 5