QOJ.ac

QOJ

Límite de tiempo: 9 s Límite de memoria: 1024 MB Puntuación total: 10

#8410. 字串交織 [A]

Estadísticas

數列 $C$ 的一個區間是指其任何非空且連續的子序列。特別地,這意味著長度為 $k$ 的數列擁有 $\frac{k(k+1)}{2}$ 個區間,因為每個區間都由其起始位置和結束位置所決定。

對於給定的整數數列,我們將其「穩定性」定義為其中最長嚴格單調區間的長度。更精確地說,數列 $[c_1, c_2, \dots, c_k]$ 的穩定性是滿足以下條件的最大整數 $s$:存在一個索引 $i$ ($1 \le i \le k - s + 1$),使得 $c_i < c_{i+1} < \dots < c_{i+s-1}$ 或 $c_i > c_{i+1} > \dots > c_{i+s-1}$。例如,數列 $[8, 6, 1, 3, 5, 7, 4, 2]$ 的穩定性為 $4$,因為其中存在嚴格單調區間 $[1, 3, 5, 7]$,且不存在更長的區間。

兩個數列 $A$ 與 $B$ 的「交織」(splot)是指任何長度為 $|A| + |B|$ 的數列,該數列包含一個等於 $A$ 的子序列(不一定連續),且所有不在該子序列中的元素共同構成了數列 $B$。例如,數列 $[1, 2, 3]$ 與 $[4, 5]$ 的交織包括 $[1, 4, 2, 5, 3]$、$[4, 5, 1, 2, 3]$ 和 $[4, 1, 5, 2, 3]$,但不包括 $[1, 2, 3, 4, 3]$ 和 $[1, 2, 3, 5, 4]$。

最後,對於整數數列 $A$ 與 $B$,我們用 $f(A, B)$ 表示其交織後可能達到的最小穩定性。

給定兩個長度分別為 $n$ 和 $m$ 的整數數列 $A$ 和 $B$,你的任務是對於每個從 $1$ 到 $n + m$ 的整數 $x$,計算滿足 $A'$ 是 $A$ 的區間、$B'$ 是 $B$ 的區間且 $f(A', B') = x$ 的數對 $(A', B')$ 的數量。由於這些數字可能非常大,請輸出它們對 $10^9 + 7$ 取模後的餘數。

你可以假設數列 $A$ 和 $B$ 中的所有元素皆不相同。

輸入格式

第一行包含兩個整數 $n$ 和 $m$ ($1 \le n, m \le 300\,000$),分別表示數列 $A$ 和 $B$ 的長度。 第二行包含數列 $A$ 的 $n$ 個整數 $A_1, A_2, \dots, A_n$ ($1 \le A_i \le n + m$)。 第三行包含數列 $B$ 的 $m$ 個整數 $B_1, B_2, \dots, B_m$ ($1 \le B_i \le n + m$)。

保證數列 $A$ 和 $B$ 中的所有元素皆不相同。換句話說,數列 $A$ 與 $B$ 的串接構成了一個 $1$ 到 $n + m$ 的排列。

輸出格式

在標準輸出的唯一一行中,輸出 $n + m$ 個以空格分隔的整數;其中第 $i$ 個數字應等於滿足 $A'$ 是 $A$ 的區間、$B'$ 是 $B$ 的區間且 $f(A', B') = i$ 的數對 $(A', B')$ 的數量,對 $10^9 + 7$ 取模後的結果。

範例

輸入 1

5 3
1 2 5 7 4
8 3 6

輸出 1

0 84 6 0 0 0 0 0

說明

對於整個數列區間,有 $f([1, 2, 5, 7, 4], [8, 3, 6]) = 2$,且穩定性為 $2$ 的交織範例為 $[1, 8, 2, 5, 3, 7, 4, 6]$。

當考慮區間 $[1, 2, 5, 7]$ 和 $[3]$ 時,我們得到 $f([1, 2, 5, 7], [3]) = 3$,且穩定性為 $3$ 的交織範例為 $[1, 2, 5, 3, 7]$。可以證明,數對 $([1, 2, 5, 7], [3])$ 無法交織出穩定性小於 $3$ 的數列。

對於區間 $[4]$ 和 $[6]$,有 $f([4], [6]) = 2$,且其所有可能的交織 $[4, 6]$ 和 $[6, 4]$ 均為有效範例。

在此範例中,每一對區間都可以交織出穩定性不超過 $3$ 的數列。因此,對於 $x \ge 4$ 的答案均為 $0$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.