QOJ.ac

QOJ

Time Limit: 8 s Memory Limit: 512 MB Total points: 100

#1360. 行列式

Statistics

行列式是線性代數中重要的物件之一。

對於自然數 $n$,$S_n$ 是所有排列的集合:即從 $\{1, 2, \dots, n\}$ 到 $\{1, 2, \dots, n\}$ 的函數,使得所有 $n$ 個值 $f(1), f(2), \dots, f(n)$ 皆不相同。

對於 $f \in S_n$,$\text{inv}(f)$ 是排列 $f$ 中的反序對數量:即滿足 $i < j$ 但 $f(i) > f(j)$ 的數對 $(i, j)$ 的數量。

考慮一個大小為 $N \times N$ 的矩陣 $A$。令 $a_{i,j}$ 為第 $i$ 列第 $j$ 行的元素。$A$ 的行列式定義為:

$$\det(A) = \sum_{f \in S_n} (-1)^{\text{inv}(f)} \prod_{i=1}^{n} a_{i,f(i)}$$

我們有一個 $N \times N$ 的整數矩陣 $A$。現在要執行 $Q$ 次以下查詢: 給定整數 $x$,請輸出矩陣 $A - xI$ 的行列式值,其中 $I$ 為 $N \times N$ 的單位矩陣。

由於數值可能過大,請將答案對質數 $998\,244\,353$ 取模後輸出。

輸入格式

第一行包含兩個整數 $N$ 和 $Q$ ($1 \le N \le 500, 1 \le Q \le 250\,000$)。

接下來 $N$ 行描述矩陣 $A$。其中第 $i$ 行包含 $N$ 個整數,第 $j$ 個整數代表 $a_{i,j}$ ($0 \le a_{i,j} < 998\,244\,353$)。

接著有 $Q$ 行,每行包含一個查詢:一個整數 $x$ ($0 \le x < 998\,244\,353$)。

輸出格式

對於每個查詢,請在獨立的一行輸出答案。

範例

輸入格式 1

3 6
2 4 5
6 3 8
1 6 3
10 9 5 8 3 1

輸出格式 1

407
470
402
495
260
110

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.