QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#100049 | #6323. Range NEQ | tikhon# | AC ✓ | 311ms | 27732kb | C++17 | 2.4kb | 2023-04-24 15:39:23 | 2023-04-24 15:39:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()
#define int int64_t
const int MOD = 998244353;
const int G1 = 31;
const int G2 = 128805723;
int pw(int x, int n) {
int res = 1;
while (n) {
if (n % 2 == 0) {
x = (x * x) % MOD;
n /= 2;
} else {
res = (res * x) % MOD;
n--;
}
}
return res;
}
void fft(vector<int>& a, bool inv = false) {
int k = 0;
while ((1 << k) < (int)a.size()) ++k;
int n = a.size();
for (int i = 0; i < n; ++i) {
int j = 0;
for (int l = 0; l < k; ++l) {
if (i & (1 << l)) {
j |= (1 << (k - l - 1));
}
}
if (i < j) {
swap(a[i], a[j]);
}
}
for (int l = 1; l < n; l *= 2) {
int w_n = pw(inv ? G2 : G1, (MOD - 1) / 2 / l);
for (int i = 0; i < n; i += 2 * l) {
int w = 1;
for (int j = 0; j < l; ++j) {
int x = a[i + j], y = (a[i + j + l] * w) % MOD;
a[i + j] = (x + y) % MOD;
a[i + j + l] = (x - y + MOD) % MOD;
w = (w * w_n) % MOD;
}
}
}
if (inv) {
int div = pw(n, MOD - 2);
for (int i = 0; i < n; ++i) {
a[i] = (a[i] * div) % MOD;
}
}
}
const int MAXN = (1 << 20);
int fact[MAXN], invf[MAXN];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
fact[0] = 1;
for (int i = 1; i < MAXN; ++i) {
fact[i] = (fact[i - 1] * i) % MOD;
}
invf[MAXN - 1] = pw(fact[MAXN - 1], MOD - 2);
for (int i = MAXN - 1; i > 0; --i) {
invf[i - 1] = (invf[i] * i) % MOD;
}
int n, m;
cin >> n >> m;
vector<int> arr(m + 1);
for (int i = 0; i <= m; ++i) {
arr[i] = (invf[m - i] * invf[m - i]) % MOD;
arr[i] = (arr[i] * invf[i]) % MOD;
}
arr.resize(MAXN);
fft(arr);
for (int& x : arr) {
x = pw(x, n);
}
fft(arr, true);
int ans = 0;
int sgn = 1;
for (int sum = 0; sum <= n * m; ++sum, sgn *= -1) {
ans += sgn * fact[n * m - sum] * arr[sum];
ans %= MOD;
}
ans = (ans % MOD + MOD) % MOD;
ans = (ans * pw(fact[m], 2 * n)) % MOD;
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 260ms
memory: 27608kb
input:
2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 263ms
memory: 27652kb
input:
5 1
output:
44
result:
ok 1 number(s): "44"
Test #3:
score: 0
Accepted
time: 277ms
memory: 27588kb
input:
167 91
output:
284830080
result:
ok 1 number(s): "284830080"
Test #4:
score: 0
Accepted
time: 260ms
memory: 27728kb
input:
2 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 260ms
memory: 27728kb
input:
2 3
output:
36
result:
ok 1 number(s): "36"
Test #6:
score: 0
Accepted
time: 240ms
memory: 27728kb
input:
2 4
output:
576
result:
ok 1 number(s): "576"
Test #7:
score: 0
Accepted
time: 246ms
memory: 27604kb
input:
3 1
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 244ms
memory: 27660kb
input:
3 2
output:
80
result:
ok 1 number(s): "80"
Test #9:
score: 0
Accepted
time: 249ms
memory: 27668kb
input:
3 3
output:
12096
result:
ok 1 number(s): "12096"
Test #10:
score: 0
Accepted
time: 265ms
memory: 27668kb
input:
3 4
output:
4783104
result:
ok 1 number(s): "4783104"
Test #11:
score: 0
Accepted
time: 261ms
memory: 27600kb
input:
4 1
output:
9
result:
ok 1 number(s): "9"
Test #12:
score: 0
Accepted
time: 249ms
memory: 27628kb
input:
4 2
output:
4752
result:
ok 1 number(s): "4752"
Test #13:
score: 0
Accepted
time: 245ms
memory: 27632kb
input:
4 3
output:
17927568
result:
ok 1 number(s): "17927568"
Test #14:
score: 0
Accepted
time: 275ms
memory: 27608kb
input:
4 4
output:
776703752
result:
ok 1 number(s): "776703752"
Test #15:
score: 0
Accepted
time: 275ms
memory: 27592kb
input:
5 2
output:
440192
result:
ok 1 number(s): "440192"
Test #16:
score: 0
Accepted
time: 253ms
memory: 27584kb
input:
5 3
output:
189125068
result:
ok 1 number(s): "189125068"
Test #17:
score: 0
Accepted
time: 264ms
memory: 27596kb
input:
5 4
output:
975434093
result:
ok 1 number(s): "975434093"
Test #18:
score: 0
Accepted
time: 311ms
memory: 27728kb
input:
1000 1000
output:
720037464
result:
ok 1 number(s): "720037464"
Test #19:
score: 0
Accepted
time: 289ms
memory: 27568kb
input:
72 42
output:
638177567
result:
ok 1 number(s): "638177567"
Test #20:
score: 0
Accepted
time: 296ms
memory: 27604kb
input:
15 19
output:
663050288
result:
ok 1 number(s): "663050288"
Test #21:
score: 0
Accepted
time: 278ms
memory: 27588kb
input:
68 89
output:
94365047
result:
ok 1 number(s): "94365047"
Test #22:
score: 0
Accepted
time: 262ms
memory: 27604kb
input:
92 37
output:
652605307
result:
ok 1 number(s): "652605307"
Test #23:
score: 0
Accepted
time: 269ms
memory: 27732kb
input:
61 87
output:
498277867
result:
ok 1 number(s): "498277867"
Test #24:
score: 0
Accepted
time: 290ms
memory: 27588kb
input:
81 40
output:
133095344
result:
ok 1 number(s): "133095344"
Test #25:
score: 0
Accepted
time: 259ms
memory: 27660kb
input:
7 91
output:
524164813
result:
ok 1 number(s): "524164813"
Test #26:
score: 0
Accepted
time: 272ms
memory: 27648kb
input:
31 18
output:
361233485
result:
ok 1 number(s): "361233485"
Test #27:
score: 0
Accepted
time: 257ms
memory: 27660kb
input:
74 54
output:
500686087
result:
ok 1 number(s): "500686087"
Test #28:
score: 0
Accepted
time: 240ms
memory: 27596kb
input:
32 2
output:
586504335
result:
ok 1 number(s): "586504335"
Test #29:
score: 0
Accepted
time: 258ms
memory: 27600kb
input:
656 718
output:
346764298
result:
ok 1 number(s): "346764298"
Test #30:
score: 0
Accepted
time: 269ms
memory: 27628kb
input:
254 689
output:
358078813
result:
ok 1 number(s): "358078813"
Test #31:
score: 0
Accepted
time: 289ms
memory: 27628kb
input:
713 674
output:
914437613
result:
ok 1 number(s): "914437613"
Test #32:
score: 0
Accepted
time: 248ms
memory: 27592kb
input:
136 698
output:
56687290
result:
ok 1 number(s): "56687290"
Test #33:
score: 0
Accepted
time: 266ms
memory: 27660kb
input:
369 401
output:
312325811
result:
ok 1 number(s): "312325811"
Test #34:
score: 0
Accepted
time: 275ms
memory: 27596kb
input:
280 204
output:
280012063
result:
ok 1 number(s): "280012063"
Test #35:
score: 0
Accepted
time: 252ms
memory: 27556kb
input:
904 225
output:
162909174
result:
ok 1 number(s): "162909174"
Test #36:
score: 0
Accepted
time: 260ms
memory: 27592kb
input:
855 928
output:
39885159
result:
ok 1 number(s): "39885159"
Test #37:
score: 0
Accepted
time: 279ms
memory: 27612kb
input:
503 365
output:
745115888
result:
ok 1 number(s): "745115888"
Test #38:
score: 0
Accepted
time: 270ms
memory: 27580kb
input:
646 996
output:
610925577
result:
ok 1 number(s): "610925577"
Test #39:
score: 0
Accepted
time: 292ms
memory: 27668kb
input:
990 918
output:
203469632
result:
ok 1 number(s): "203469632"
Test #40:
score: 0
Accepted
time: 283ms
memory: 27668kb
input:
961 949
output:
169566857
result:
ok 1 number(s): "169566857"
Test #41:
score: 0
Accepted
time: 267ms
memory: 27600kb
input:
946 932
output:
352423195
result:
ok 1 number(s): "352423195"
Test #42:
score: 0
Accepted
time: 262ms
memory: 27668kb
input:
903 981
output:
196309824
result:
ok 1 number(s): "196309824"
Test #43:
score: 0
Accepted
time: 260ms
memory: 27536kb
input:
916 988
output:
487208972
result:
ok 1 number(s): "487208972"
Test #44:
score: 0
Accepted
time: 274ms
memory: 27648kb
input:
982 982
output:
387421488
result:
ok 1 number(s): "387421488"
Test #45:
score: 0
Accepted
time: 285ms
memory: 27588kb
input:
955 911
output:
955637031
result:
ok 1 number(s): "955637031"
Test #46:
score: 0
Accepted
time: 273ms
memory: 27596kb
input:
906 999
output:
798469943
result:
ok 1 number(s): "798469943"
Test #47:
score: 0
Accepted
time: 279ms
memory: 27724kb
input:
982 975
output:
193506289
result:
ok 1 number(s): "193506289"
Test #48:
score: 0
Accepted
time: 278ms
memory: 27628kb
input:
921 991
output:
431202149
result:
ok 1 number(s): "431202149"