#P8544. 「Wdoi-2」禁断之门对面,是此世还是彼世

    ID: 9037 远端评测题 2500ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP二分洛谷原创O2优化凸完全单调性(wqs 二分)洛谷月赛

「Wdoi-2」禁断之门对面,是此世还是彼世

Background

Perhaps because the Land of the Back Door rarely contacts the outside world, perhaps due to limits of her divine duties, or perhaps simply because of personal preference, as one of the sages who first built Gensokyo, Matara does not interact frequently with the other sages. Other sages such as Yakumo Yukari and Ibaraki Kasen all walk within Gensokyo in person, but Matara stays outside it.

Spending divine power to trigger an incident on the scale of the whole Gensokyo may look huge, but in fact it caused no real damage to Gensokyo, only making a group of foolish fairies more irritable.

No one knows what the secret god behind the door is truly thinking.

Problem Description

You are given a positive integer sequence aa of length nn and a positive integer sequence bb of length mm.

Now Lan constructs an nn-row, mm-column positive integer matrix AA from sequences aa and bb, satisfying Ai,j=aibjA_{i,j}=a_ib_j. You need to construct a positive integer matrix BB with (n+1)(n+1) rows and tt columns, satisfying the following conditions:

  • Each element of the matrix is in [1,m][1,m].
  • Elements in the same row of the matrix are pairwise distinct.
  • Adjacent elements in each column of the matrix are different.
  • Among all matrices that satisfy the above three requirements, minimize:
$$f(B)=\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{t}\sum\limits_{k=\min(B_{i,j},B_{i+1,j})}^{\max(B_{i,j},B_{i+1,j})}A_{i,k}$$

Output the value of f(B)f(B) modulo 109+710^9+7 for the constructed matrix BB.

Input Format

The first line contains three integers n,m,tn,m,t.

The next line contains nn integers a1,a2,ana_1,a_2,\cdots a_n, as described in the statement.

The next line contains mm integers b1,b2,bmb_1,b_2,\cdots b_m, as described in the statement.

Output Format

Output one line, representing the value of f(B)f(B) modulo 109+710^9+7 for the constructed matrix BB.

2 2 2
9 9
6 1
252
10 10 10
2 8 10 10 10 2 5 8 9 3
2 1 5 2 10 7 8 9 10 6

8040

Hint

Sample Explanation 1

According to the statement, we can construct A=[549549]A=\begin{bmatrix}54 & 9 \\ 54 & 9 \end{bmatrix}.

You need to construct a (3)(3)-row, (2)(2)-column matrix $B=\begin{bmatrix}1 & 2 \\ 2 & 1 \\ 1 & 2 \end{bmatrix}$. In this case, f(B)=252f(B)=252 is the minimum.

It can be proven that among all cases, the minimum value of f(B)f(B) is 252252.

Constraints and Notes

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|c|}\hline \textbf{Subtask} & \bm{n \le } & \bm{m \le } & \bm{t \le } & \textbf{特殊性质} & \textbf{分值}\\\hline 1 & 10 & 10 & 10 & - & 5 \\\hline 2 & 100 & 100 & 100 & - & 5 \\\hline 3 & 10^3 & 10^3 & 10^3 & - & 15 \\\hline 4 & 5\times 10^4 & 5\times 10^4 & 5\times 10^4 & - & 30 \\\hline 5 & 5\times 10^5 & 5\times 10^5 & 5\times 10^5 & \textbf{A} & 10 \\\hline 6 & 5\times 10^5 & 5\times 10^5 & 5\times 10^5 & \textbf{B} & 10 \\\hline 7 & 5\times 10^5 & 5\times 10^5 & 5\times 10^5 & - & 25 \\\hline \end{array}$$
  • Special Property A\textbf{A}: It is guaranteed that ai=1a_i=1.
  • Special Property B\textbf{B}: It is guaranteed that m=tm=t.

For all testdata, it is guaranteed that 1ai,bi1091\le a_i, b_i\le 10^9, 1n,m,t5×1051\le n, m, t\le 5\times 10^5 and tmt\le m. It is guaranteed that a solution exists.

Translated by ChatGPT 5