#P3813. [FJOI2017] 矩阵填数

    ID: 2753 远端评测题 2000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2017各省省选离散化福建枚举,暴力容斥

[FJOI2017] 矩阵填数

Description

Given an h×wh \times w matrix, the rows are numbered from top to bottom as 1h1 \sim h, and the columns are numbered from left to right as 1w1 \sim w.

You need to fill each cell in this matrix with a number from 1m1 \sim m.

There are some restrictions when filling the matrix. You are given nn submatrices of this matrix and the maximum value vv for each submatrix. Your filling must satisfy that the maximum value of each given submatrix is vv.

Now, your task is to find how many fillings satisfy the nn constraints.

Two fillings are different if and only if there exists at least one cell where the numbers differ between the two fillings. Since the answer may be large, you only need to output the result modulo 109+710 ^ 9 + 7.

Input Format

The first line of the input contains an integer TT, the number of test cases.

For each test case, the first line contains four integers h,w,m,nh,w,m,n.

Then follow nn lines, each describing the maximum value vv of a submatrix. Each line contains five integers x1,y1,x2,y2,vx1,y1,x2,y2,v, indicating that the submatrix with top-left corner (x1,y1)(x1,y1) and bottom-right corner (x2,y2)(x2,y2) has a maximum value of vv. 1x1x2h1 \le x1 \le x2 \le h, 1y1y2w1 \le y1 \le y2 \le w.

Output Format

For each test case, output one line: the number of valid fillings modulo 1,000,000,0071,000,000,007.

2
3 3 2 2
1 1 2 2 2
2 2 3 3 1
4 4 4 4
1 1 2 3 3
2 3 4 4 2
2 1 4 3 2
1 2 3 4 4
28
76475

Hint

For 20%20\% of the testdata, n2n \le 2.

For another 20%20\% of the data, 1h,w501 \le h, w \le 50.

For 100%100\% of the data, T5T \le 5, 1h,w,m1041 \le h, w, m \le 10 ^ 4, 1n101 \le n \le 10, 1vm1 \le v \le m.

Translated by ChatGPT 5