#P3295. [SCOI2016] 萌萌哒

    ID: 2344 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016四川并查集枚举,暴力st表,稀疏表

[SCOI2016] 萌萌哒

Description

An nn-digit number is denoted by S1S2S3SnS_1 S_2 S_3 \cdots S_n, where SiS_i is the ii-th digit and S1S_1 is the most significant digit. You are given several constraints. Each constraint is given by four integers l1,r1,l2,r2l_1, r_1, l_2, r_2, meaning two intervals of the same length, and it requires the substrings Sl1Sl1+1Sl1+2Sr1S_{l_1} S_{l_1+1} S_{l_1+2} \cdots S_{r_1} and Sl2Sl2+1Sl2+2Sr2S_{l_2} S_{l_2+1} S_{l_2+2} \cdots S_{r_2} to be exactly the same.

For example, when n=6n=6 and there is a constraint l1=1,r1=3,l2=4,r2=6l_1=1, r_1=3, l_2=4, r_2=6, then 123123 and 351351 both satisfy the condition, but 12012 and 131141 do not. The former is not of length 66, and in the latter the second and fifth digits differ. Find how many numbers satisfy all the given conditions.

Input Format

The first line contains two integers nn and mm, representing the length of the number and the number of constraints.

Each of the next mm lines contains four integers li1,ri1,li2,ri2l_{i_1}, r_{i_1}, {l_{i_2}}, r_{i_2} on the ii-th line, representing the two intervals for that constraint.

1n1051 \le n \le 10^5, 1m1051 \le m \le 10^5, 1li1,ri1,li2,ri2n1 \le l_{i_1}, r_{i_1}, {l_{i_2}}, r_{i_2} \le n, and it is guaranteed that ri1li1=ri2li2r_{i_1} - l_{i_1} = r_{i_2} - l_{i_2}.

Output Format

Output a single integer, the number of nn-digit numbers that satisfy all the constraints. Since the answer can be large, output it modulo 109+710^9+7.

4 2
1 2 3 4
3 3 3 3
90

Hint

Translated by ChatGPT 5