QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#312006#6323. Range NEQPlentyOfPenalty#AC ✓292ms43268kbC++203.1kb2024-01-23 10:07:532024-01-23 10:07:54

Judging History

你现在查看的是最新测评结果

  • [2024-01-23 10:07:54]
  • 评测
  • 测评结果:AC
  • 用时:292ms
  • 内存:43268kb
  • [2024-01-23 10:07:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 9, M = 1e6 + 9, mod = 998244353;
int n, m, fac[M], inv[M], ifac[M];
inline int sub(int x, int y) {
    x -= y;
    return x < 0 ? x + mod : x;
}
inline int add(int x, int y) {
    x += y;
    return x >= mod ? x - mod : x;
}
int C(int n, int m) { return (long long)fac[n] * ifac[m] % mod * ifac[n - m] % mod; }
int power(int a, int b) {
    int s = 1;
    for (; b; b >>= 1, a = (long long)a * a % mod)
        if (b & 1) s = (long long)s * a % mod;
    return s;
}
vector<int> rev, rt;
void getRevRoot(int n) {
    int m = __lg(n); // log(n)/log(2)+1e-8;
    rev.resize(n);
    for (int i = 1; i < n; i++) {
        rev[i] = rev[i >> 1] >> 1 | (i & 1) << (m - 1);
    }
    static int len = 1;
    if (len < n) {
        rt.resize(n);
        for (; len < n; len <<= 1) {
            int uni = power(3, (mod - 1) / (len << 1));
            rt[len] = 1;
            for (int i = 1; i < len; i++) {
                rt[i + len] = (long long)rt[i + len - 1] * uni % mod;
            }
        }
    }
}
void ntt(vector<int> &f, int n) {
    f.resize(n);
    for (int i = 0; i < n; i++) {
        if (i < rev[i]) swap(f[i], f[rev[i]]);
    }
    for (int len = 1; len < n; len *= 2) {
        for (int i = 0; i < n; i += len * 2) {
            for (int j = 0; j < len; j++) {
                int x = f[i + j];
                int y = (long long)f[i + j + len] * rt[j + len] % mod;
                f[i + j] = add(x, y);
                f[i + j + len] = sub(x, y);
            }
        }
    }
}
vector<int> operator*(vector<int> f, vector<int> g) {
    int n = 1, m = (int)(f.size() + g.size()) - 1;
    while (n < m)
        n <<= 1;
    int invn = power(n, mod - 2);
    getRevRoot(n), ntt(f, n), ntt(g, n);
    for (int i = 0; i < n; i++)
        f[i] = (long long)f[i] * g[i] % mod;
    reverse(f.begin() + 1, f.end()), ntt(f, n);
    f.resize(m);
    for (int i = 0; i < m; i++)
        f[i] = (long long)f[i] * invn % mod;
    return f;
}
vector<int> power(vector<int> a, int b) {
    vector<int> s = {1};
    for (; b; b >>= 1, a = a * a)
        if (b & 1) s = s * a;
    return s;
}
int main() {
#ifdef popteam
    freopen("G.in", "r", stdin);
#endif
    inv[0] = inv[1] = fac[0] = ifac[0] = 1;
    for (int i = 2; i < M; i++) {
        inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;
    }
    for (int i = 1; i < M; i++) {
        fac[i] = (long long)fac[i - 1] * i % mod;
        ifac[i] = (long long)ifac[i - 1] * inv[i] % mod;
    }
    cin >> n >> m;
    vector<int> a(m + 1);
    for (int i = 0; i <= m; i++) {
        a[i] = (long long)C(m, i) * C(m, i) % mod * fac[i] % mod;
    }
    // for (int i = 0; i <= m; i++)
    //     cerr << a[i] << " \n"[i == m];
    vector<int> f = power(a, n);
    // for (int i = 0; i <= n * m; i++)
    //     cerr << f[i] << " \n"[i == n * m];
    int ans = 0;
    for (int i = 0; i <= n * m; i++) {
        ans = (ans + (long long)fac[n * m - i] * (i & 1 ? mod - 1 : 1) % mod * f[i]) % mod;
    }
    cout << ans << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 15292kb

input:

2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 11ms
memory: 15304kb

input:

5 1

output:

44

result:

ok 1 number(s): "44"

Test #3:

score: 0
Accepted
time: 11ms
memory: 15708kb

input:

167 91

output:

284830080

result:

ok 1 number(s): "284830080"

Test #4:

score: 0
Accepted
time: 11ms
memory: 15300kb

input:

2 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 6ms
memory: 15304kb

input:

2 3

output:

36

result:

ok 1 number(s): "36"

Test #6:

score: 0
Accepted
time: 14ms
memory: 15188kb

input:

2 4

output:

576

result:

ok 1 number(s): "576"

Test #7:

score: 0
Accepted
time: 6ms
memory: 15436kb

input:

3 1

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 11ms
memory: 15232kb

input:

3 2

output:

80

result:

ok 1 number(s): "80"

Test #9:

score: 0
Accepted
time: 11ms
memory: 15504kb

input:

3 3

output:

12096

result:

ok 1 number(s): "12096"

Test #10:

score: 0
Accepted
time: 11ms
memory: 15512kb

input:

3 4

output:

4783104

result:

ok 1 number(s): "4783104"

Test #11:

score: 0
Accepted
time: 7ms
memory: 15460kb

input:

4 1

output:

9

result:

ok 1 number(s): "9"

Test #12:

score: 0
Accepted
time: 7ms
memory: 15456kb

input:

4 2

output:

4752

result:

ok 1 number(s): "4752"

Test #13:

score: 0
Accepted
time: 14ms
memory: 15300kb

input:

4 3

output:

17927568

result:

ok 1 number(s): "17927568"

Test #14:

score: 0
Accepted
time: 9ms
memory: 15252kb

input:

4 4

output:

776703752

result:

ok 1 number(s): "776703752"

Test #15:

score: 0
Accepted
time: 14ms
memory: 15292kb

input:

5 2

output:

440192

result:

ok 1 number(s): "440192"

Test #16:

score: 0
Accepted
time: 13ms
memory: 15508kb

input:

5 3

output:

189125068

result:

ok 1 number(s): "189125068"

Test #17:

score: 0
Accepted
time: 7ms
memory: 15432kb

input:

5 4

output:

975434093

result:

ok 1 number(s): "975434093"

Test #18:

score: 0
Accepted
time: 280ms
memory: 43268kb

input:

1000 1000

output:

720037464

result:

ok 1 number(s): "720037464"

Test #19:

score: 0
Accepted
time: 7ms
memory: 15440kb

input:

72 42

output:

638177567

result:

ok 1 number(s): "638177567"

Test #20:

score: 0
Accepted
time: 0ms
memory: 15320kb

input:

15 19

output:

663050288

result:

ok 1 number(s): "663050288"

Test #21:

score: 0
Accepted
time: 9ms
memory: 15592kb

input:

68 89

output:

94365047

result:

ok 1 number(s): "94365047"

Test #22:

score: 0
Accepted
time: 11ms
memory: 15384kb

input:

92 37

output:

652605307

result:

ok 1 number(s): "652605307"

Test #23:

score: 0
Accepted
time: 11ms
memory: 15480kb

input:

61 87

output:

498277867

result:

ok 1 number(s): "498277867"

Test #24:

score: 0
Accepted
time: 14ms
memory: 15368kb

input:

81 40

output:

133095344

result:

ok 1 number(s): "133095344"

Test #25:

score: 0
Accepted
time: 10ms
memory: 15544kb

input:

7 91

output:

524164813

result:

ok 1 number(s): "524164813"

Test #26:

score: 0
Accepted
time: 7ms
memory: 15264kb

input:

31 18

output:

361233485

result:

ok 1 number(s): "361233485"

Test #27:

score: 0
Accepted
time: 7ms
memory: 15512kb

input:

74 54

output:

500686087

result:

ok 1 number(s): "500686087"

Test #28:

score: 0
Accepted
time: 9ms
memory: 15504kb

input:

32 2

output:

586504335

result:

ok 1 number(s): "586504335"

Test #29:

score: 0
Accepted
time: 192ms
memory: 39624kb

input:

656 718

output:

346764298

result:

ok 1 number(s): "346764298"

Test #30:

score: 0
Accepted
time: 67ms
memory: 21116kb

input:

254 689

output:

358078813

result:

ok 1 number(s): "358078813"

Test #31:

score: 0
Accepted
time: 213ms
memory: 38708kb

input:

713 674

output:

914437613

result:

ok 1 number(s): "914437613"

Test #32:

score: 0
Accepted
time: 57ms
memory: 20920kb

input:

136 698

output:

56687290

result:

ok 1 number(s): "56687290"

Test #33:

score: 0
Accepted
time: 62ms
memory: 21264kb

input:

369 401

output:

312325811

result:

ok 1 number(s): "312325811"

Test #34:

score: 0
Accepted
time: 30ms
memory: 17788kb

input:

280 204

output:

280012063

result:

ok 1 number(s): "280012063"

Test #35:

score: 0
Accepted
time: 62ms
memory: 21432kb

input:

904 225

output:

162909174

result:

ok 1 number(s): "162909174"

Test #36:

score: 0
Accepted
time: 259ms
memory: 41160kb

input:

855 928

output:

39885159

result:

ok 1 number(s): "39885159"

Test #37:

score: 0
Accepted
time: 78ms
memory: 21088kb

input:

503 365

output:

745115888

result:

ok 1 number(s): "745115888"

Test #38:

score: 0
Accepted
time: 233ms
memory: 41368kb

input:

646 996

output:

610925577

result:

ok 1 number(s): "610925577"

Test #39:

score: 0
Accepted
time: 289ms
memory: 42704kb

input:

990 918

output:

203469632

result:

ok 1 number(s): "203469632"

Test #40:

score: 0
Accepted
time: 283ms
memory: 42356kb

input:

961 949

output:

169566857

result:

ok 1 number(s): "169566857"

Test #41:

score: 0
Accepted
time: 277ms
memory: 42320kb

input:

946 932

output:

352423195

result:

ok 1 number(s): "352423195"

Test #42:

score: 0
Accepted
time: 272ms
memory: 42340kb

input:

903 981

output:

196309824

result:

ok 1 number(s): "196309824"

Test #43:

score: 0
Accepted
time: 266ms
memory: 42368kb

input:

916 988

output:

487208972

result:

ok 1 number(s): "487208972"

Test #44:

score: 0
Accepted
time: 292ms
memory: 42760kb

input:

982 982

output:

387421488

result:

ok 1 number(s): "387421488"

Test #45:

score: 0
Accepted
time: 285ms
memory: 42204kb

input:

955 911

output:

955637031

result:

ok 1 number(s): "955637031"

Test #46:

score: 0
Accepted
time: 288ms
memory: 42384kb

input:

906 999

output:

798469943

result:

ok 1 number(s): "798469943"

Test #47:

score: 0
Accepted
time: 288ms
memory: 42788kb

input:

982 975

output:

193506289

result:

ok 1 number(s): "193506289"

Test #48:

score: 0
Accepted
time: 277ms
memory: 42356kb

input:

921 991

output:

431202149

result:

ok 1 number(s): "431202149"