結果
問題 | No.1482 Swap Many Permutations |
ユーザー | SSRS |
提出日時 | 2021-04-16 21:35:27 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,582 bytes |
コンパイル時間 | 1,878 ms |
コンパイル使用メモリ | 178,736 KB |
実行使用メモリ | 18,600 KB |
最終ジャッジ日時 | 2024-07-03 00:58:48 |
合計ジャッジ時間 | 6,202 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,752 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | TLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long modpow(long long a, long long b){ long long ans = 1; while (b > 0){ if (b % 2 == 1){ ans *= a; ans %= MOD; } a *= a; a %= MOD; b /= 2; } return ans; } long long modinv(long long a){ return modpow(a, MOD - 2); } vector<long long> mf = {1}; vector<long long> mfi = {1}; long long modfact(int n){ if (mf.size() > n){ return mf[n]; } else { for (int i = mf.size(); i <= n; i++){ long long next = mf.back() * i % MOD; mf.push_back(next); mfi.push_back(modinv(next)); } return mf[n]; } } long long modfactinv(int n){ if (mfi.size() > n){ return mfi[n]; } else { return modinv(modfact(n)); } } long long modbinom(int n, int k){ if (n < 0 || k < 0 || k > n){ return 0; } else { return modfact(n) * modfactinv(k) % MOD * modfactinv(n - k) % MOD; } } vector<long long> ntt(vector<long long> A, bool inv){ int N = A.size(); long long r = 3; if (inv){ r = modinv(r); } vector<long long> B(N); for (int i = N / 2; i > 0; i /= 2){ long long z = modpow(r, (MOD - 1) / (N / i)); long long z2 = 1; for (int j = 0; j < N; j += i * 2){ for (int k = 0; k < i; k++){ A[i + j + k] *= z2; A[i + j + k] %= MOD; B[j / 2 + k] = (A[j + k] + A[i + j + k]) % MOD; B[N / 2 + j / 2 + k] = (A[j + k] - A[i + j + k] + MOD) % MOD; } z2 = z2 * z % MOD; } swap(A, B); } if (inv){ int Ninv = modinv(N); for (int i = 0; i < N; i++){ A[i] = A[i] * Ninv % MOD; } } return A; } vector<long long> convolution(vector<long long> A, vector<long long> B, int d = -1){ int deg = A.size() + B.size() - 1; int N = 1; while (N < deg){ N *= 2; } A.resize(N); B.resize(N); A = ntt(A, false); B = ntt(B, false); vector<long long> ans(N); for (int i = 0; i < N; i++){ ans[i] = A[i] * B[i] % MOD; } ans = ntt(ans, true); if (d != -1){ deg = d; } ans.resize(deg); return ans; } long long inversion_number(vector<int> &p){ int N = p.size(); long long ans = 0; vector<int> bit(N + 1, 0); for (int i = 0; i < N; i++){ ans += i; int j = p[i] + 1; while (j > 0){ ans -= bit[j]; j -= j & -j; } j = p[i] + 1; while (j <= N){ bit[j]++; j += j & -j; } } return ans; } int inversion_number(int a, int b, int m){ vector<int> p(m); for (int i = 0; i < m; i++){ p[i] = (a + b * i) % m; } return inversion_number(p) % 2; } int main(){ int N, M; cin >> N >> M; vector<int> B(N), C(N); for (int i = 0; i < N; i++){ cin >> B[i] >> C[i]; } cout << 1 << endl; cout << M * (M - 1) << endl; if (M == 2){ for (int i = 2; i < N; i++){ cout << 0 << endl; } } else { int tmp = M * (M - 1) / 2; vector<long long> f1(N + 1); f1[0] = 1; for (int i = 0; i < N; i++){ f1[i + 1] = f1[i] * (tmp - i) % MOD; } vector<long long> g = f1; for (int i = 0; i <= N; i++){ f1[i] *= modfactinv(i) % MOD; f1[i] %= MOD; g[i] *= modfactinv(i) % MOD; g[i] %= MOD; } vector<long long> f2 = f1; for (int i = 1; i <= N; i += 2){ f1[i] = 0; } for (int i = 0; i <= N; i += 2){ f2[i] = 0; } vector<long long> h1 = convolution(f1, g); vector<long long> h2 = convolution(f2, g); int sum = 0; for (int i = 0; i < N; i++){ sum += inversion_number(B[i], C[i], M); if (i >= 2){ if (sum % 2 == 0){ cout << h1[i + 1] * modfact(i + 1) % MOD << endl; } else { cout << h2[i + 1] * modfact(i + 1) % MOD << endl; } } } } }