QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#9886. 长序列反转 2

統計

在本题中,当我们提到“长度为 $K$ 的排列”时,指的是 $(0, 1, \dots, K-1)$ 的一个排列。 此外,我们将序列 $X$ 的第 $k$ 个元素(从 0 开始计数)记为 $X[k]$。

给定一个长度为 $L$ 的排列 $P$,以及 $L$ 个长度为 $B$ 的排列,分别记为 $V_0, V_1, \dots, V_{L-1}$。 我们定义一个长度为 $B^L$ 的序列 $A$,其定义如下: 对于每个 $0 \le n < B^L$,当 $n$ 表示为 $B$ 进制下的 $L$ 位数时,令 $N[i]$ 为其在 $B^i$ 位上的值($0 \le i < L$)。则:

$$A[n] = \sum_{i=0}^{L-1} V_i[N[i]] \cdot B^{P[i]}$$

求序列 $A$ 的逆序对数量,结果对 $998244353$ 取模。

输入格式

输入按以下格式给出:

$L \ B$ $P[0] \ P[1] \ \dots \ P[L-1]$ $V_0[0] \ V_0[1] \ \dots \ V_0[B-1]$ $\vdots$ $V_{L-1}[0] \ V_{L-1}[1] \ \dots \ V_{L-1}[B-1]$

  • 所有输入值均为整数。
  • $1 \le L$
  • $2 \le B$
  • $L \times (B + 1) \le 5 \times 10^5$
  • $P$ 是一个长度为 $L$ 的排列。
  • 对于每个 $0 \le i < L$,$V_i$ 是一个长度为 $B$ 的排列。

输出格式

输出序列 $A$ 的逆序对数量,结果对 $998244353$ 取模。

样例

样例 1

3 2
2 0 1
1 0
1 0
0 1
14

样例 2

2 4
1 0
2 0 3 1
1 2 3 0
60

样例 3

9 10
2 5 7 3 8 1 4 6 0
9 2 4 0 1 6 7 3 5 8
4 1 6 7 8 0 5 9 2 3
1 9 2 4 6 8 5 7 0 3
9 0 8 2 5 1 6 7 3 4
1 6 0 7 3 9 2 4 5 8
4 5 2 9 1 6 7 3 0 8
7 0 5 6 1 9 2 4 3 8
3 2 1 6 7 0 8 9 4 5
9 2 4 3 5 8 0 6 7 1
138876070

说明

在第一个样例中,$n = 5$ 对应 $B = 2$ 进制下的 $N = (1, 0, 1)$。因此,

$$A[5] = V_0[1] \cdot 2^{P[0]} + V_1[0] \cdot 2^{P[1]} + V_2[1] \cdot 2^{P[2]} = 3$$

通过类似计算,我们得到 $A = (5, 1, 4, 0, 7, 3, 6, 2)$。$A$ 的逆序对数量为 $14$,因此输出为 $14$。

在第二个样例中,$A = (9, 1, 13, 5, 10, 2, 14, 6, 11, 3, 15, 7, 8, 0, 12, 4)$。$A$ 的逆序对数量为 $60$,因此输出为 $60$。

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.