#D. Double Landscape

    Type: Default 1000ms 256MiB

Double Landscape

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Double Landscape

题目描述

求满足下列条件的 n×mn\times m 的矩阵 MM 的个数(mod109+7\text{}\bmod 10^9+7):

  • 1n×m1\sim n\times m 各出现一次。
  • ai=maxt=1mMi,ta_i=\max\limits_{t=1}^m M_{i,t}
  • bj=maxt=1nMt,jb_j=\max\limits_{t=1}^n M_{t,j}

输入格式

第一行两个整数 N,MN,M ,第二行 NN 个整数 AiA_i ,第三行 MM 个整数 BiB_i

输出格式

一个整数表示答案。

样例 #1

样例输入 #1

2 2
4 3
3 4

样例输出 #1

2

样例 #2

样例输入 #2

3 3
5 9 7
3 6 9

样例输出 #2

0

样例 #3

样例输入 #3

2 2
4 4
4 4

样例输出 #3

0

样例 #4

样例输入 #4

14 13
158 167 181 147 178 151 179 182 176 169 180 129 175 168
181 150 178 179 167 180 176 169 182 177 175 159 173

样例输出 #4

343772227

数据范围

  • 1  N  1000 1\ \leq\ N\ \leq\ 1000
  • 1  M  1000 1\ \leq\ M\ \leq\ 1000
  • 1  Ai  N × M 1\ \leq\ A_i\ \leq\ N\ \times\ M
  • 1  Bj  N × M 1\ \leq\ B_j\ \leq\ N\ \times\ M

样例解释1

(A1, A2) = (4, 3) (A_1,\ A_2)\ =\ (4,\ 3) (B1, B2) = (3, 4) (B_1,\ B_2)\ =\ (3,\ 4) ,因此满足条件的矩阵有 22 个:

$$\left( \begin{matrix} 1 & 4 \\ 3 & 2 \end{matrix} \right) $$$$\left( \begin{matrix} 2 & 4 \\ 3 & 1 \end{matrix} \right) $$

20240528集训

Not Attended
Status
Done
Rule
IOI
Problem
6
Start at
2024-5-28 19:00
End at
2024-5-28 21:00
Duration
2 hour(s)
Host
Partic.
16