QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#8956. 欧拉?欧拉!

Statistics

我們稱一個 $n$ 階排列 $p$ 的超過數是滿足 $1 \le i \le n$ 且 $p_i > i$ 的 $i$ 的數量,降低數是滿足 $1 \le i \le n-1$ 且 $p_i > p_{i+1}$ 的 $i$ 的數量。

記 $n$ 階排列中超過數為 $m$,同時降低數為 $k$ 的排列數量為 $h(n, m, k)$,請你對給定的 $n$ 計算所有 $h(n, m, k)$。由於答案很大,你只需要輸出它們對 $M$ 取模的值即可。

輸入格式

一行輸入兩個正整數 $n$ 和 $M$,表示排列的階數和模數。

輸出格式

輸出 $n$ 行每行 $n$ 個數,第 $i$ 行第 $j$ 個數輸出 $h(n, i-1, j-1) \bmod M$。

範例

範例 1 輸入

3 998244353

範例 1 輸出

1 0 0
0 3 1
0 1 0

範例 1 說明

  • 超過數為 $0$,降低數為 $0$ 的排列:$[1, 2, 3]$。
  • 超過數為 $1$,降低數為 $1$ 的排列:$[2, 1, 3]$、$[3, 1, 2]$、$[1, 3, 2]$。
  • 超過數為 $1$,降低數為 $2$ 的排列:$[3, 2, 1]$。
  • 超過數為 $2$,降低數為 $1$ 的排列:$[2, 3, 1]$。

範例 2 輸入

7 998244353

範例 2 輸出

1 0 0 0 0 0 0
0 21 70 28 1 0 0
0 35 343 596 209 8 0
0 35 470 1154 673 83 1
0 21 259 582 300 29 0
0 7 49 56 8 0 0
0 1 0 0 0 0 0

子任務

本題使用捆綁測試。

對於 $10\%$ 的資料,保證 $n \leq 10$。

對於 $30\%$ 的資料,保證 $n \leq 20$。

對於 $60\%$ 的資料,保證 $n \leq 35$。

對於 $100\%$ 的資料,保證 $1 \le n \leq 60$,$M$ 是質數,$10^8 \leq M \leq 10^9$。

說明

你可以選擇使用如下模板來加速取模運算。

#include <bits/stdc++.h>

using namespace std;

using u64 = unsigned long long;
using LL = __uint128_t;

struct FastMod {
    u64 b, m;

    FastMod(u64 b) : b(b), m(u64((LL(1) << 64) / b)) {}

    u64 operator()(u64 a) {
        u64 q = (u64) ((LL(m) * a) >> 64);
        u64 r = a - q * b;
        return r >= b ? r - b : r;
    }
} R(2);

int mod;

int main() {
    int n; cin >> n >> mod; R = FastMod(mod);

    int a = 1e7, b = 2e7;
    int c = R(a * (u64)b);

    return 0;
}

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.