QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#151643 | #6323. Range NEQ | Forever_Young# | AC ✓ | 305ms | 36464kb | C++14 | 1.7kb | 2023-08-27 12:21:32 | 2023-08-27 12:21:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1048576;
const int mod = 998244353;
typedef long long LL;
constexpr LL fastpo(LL x, LL n, int mod) {
LL res = 1;
x %= mod;
while(n) {
if(n & 1) {
res = res * x % mod;
}
x = x * x % mod;
n /= 2;
}
return res;
}
constexpr LL G = fastpo(3, (mod - 1) / N, mod);
LL w[N];
LL A[N];
void NTT(LL p[], int n) {
for (int i = 1, j = 0; i < n - 1; ++i) {
for (int s = n; j ^= s >>= 1, ~j & s;);
if (i < j) swap(p[i], p[j]);
}
for (int d = 0; (1 << d) < n; ++d) {
int m = 1 << d, m2 = m * 2, rm = n >> (d + 1);
for (int i = 0; i < n; i += m2) {
for (int j = 0; j < m; ++j) {
LL &p1 = p[i + j + m], &p2 = p[i + j];
LL t = w[rm * j] * p1 % mod;
p1 = p2 - t, p2 = p2 + t;
if(p1 < 0) p1 += mod;
if(p2 >= mod) p2 -= mod;
} } }
}
LL fac[N], invfac[N];
LL c(int a, int b) {
return fac[a] * invfac[a - b] % mod * invfac[b] % mod;
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
for(int i = 0; i < N; i++) {
fac[i] = i == 0 ? 1 : fac[i - 1] * i % mod;
}
for(int i = 0; i < N; i++) {
w[i] = i == 0 ? 1 : w[i - 1] * G % mod;
}
invfac[N - 1] = fastpo(fac[N - 1], mod - 2, mod);
for(int i = N - 2; i >= 0; i--) {
invfac[i] = invfac[i + 1] * (i + 1) % mod;
}
for(int i = 0; i <= m; i++) {
A[i] = c(m, i) * fac[m] % mod * invfac[m - i] % mod;
}
NTT(A, N);
for(int i = 0; i < N; i++) {
A[i] = fastpo(A[i], n, mod);
}
NTT(A, N);
reverse(A + 1, A + N);
for(int i = 0; i < N; i++) {
A[i] = A[i] * fastpo(N, mod - 2, mod) % mod;
}
LL ans = 0;
for(int i = 0; i <= n * m; i++) {
ans = (ans + (i % 2 == 0 ? 1 : -1) * A[i] * fac[n * m - i] % mod + mod) % mod;
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 137ms
memory: 36276kb
input:
2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 128ms
memory: 36192kb
input:
5 1
output:
44
result:
ok 1 number(s): "44"
Test #3:
score: 0
Accepted
time: 235ms
memory: 36280kb
input:
167 91
output:
284830080
result:
ok 1 number(s): "284830080"
Test #4:
score: 0
Accepted
time: 124ms
memory: 36192kb
input:
2 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 138ms
memory: 36284kb
input:
2 3
output:
36
result:
ok 1 number(s): "36"
Test #6:
score: 0
Accepted
time: 146ms
memory: 36460kb
input:
2 4
output:
576
result:
ok 1 number(s): "576"
Test #7:
score: 0
Accepted
time: 121ms
memory: 36280kb
input:
3 1
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 141ms
memory: 36132kb
input:
3 2
output:
80
result:
ok 1 number(s): "80"
Test #9:
score: 0
Accepted
time: 136ms
memory: 36464kb
input:
3 3
output:
12096
result:
ok 1 number(s): "12096"
Test #10:
score: 0
Accepted
time: 140ms
memory: 36200kb
input:
3 4
output:
4783104
result:
ok 1 number(s): "4783104"
Test #11:
score: 0
Accepted
time: 126ms
memory: 36460kb
input:
4 1
output:
9
result:
ok 1 number(s): "9"
Test #12:
score: 0
Accepted
time: 142ms
memory: 36132kb
input:
4 2
output:
4752
result:
ok 1 number(s): "4752"
Test #13:
score: 0
Accepted
time: 127ms
memory: 36196kb
input:
4 3
output:
17927568
result:
ok 1 number(s): "17927568"
Test #14:
score: 0
Accepted
time: 149ms
memory: 36280kb
input:
4 4
output:
776703752
result:
ok 1 number(s): "776703752"
Test #15:
score: 0
Accepted
time: 129ms
memory: 36196kb
input:
5 2
output:
440192
result:
ok 1 number(s): "440192"
Test #16:
score: 0
Accepted
time: 149ms
memory: 36196kb
input:
5 3
output:
189125068
result:
ok 1 number(s): "189125068"
Test #17:
score: 0
Accepted
time: 153ms
memory: 36292kb
input:
5 4
output:
975434093
result:
ok 1 number(s): "975434093"
Test #18:
score: 0
Accepted
time: 281ms
memory: 36344kb
input:
1000 1000
output:
720037464
result:
ok 1 number(s): "720037464"
Test #19:
score: 0
Accepted
time: 209ms
memory: 36284kb
input:
72 42
output:
638177567
result:
ok 1 number(s): "638177567"
Test #20:
score: 0
Accepted
time: 183ms
memory: 36196kb
input:
15 19
output:
663050288
result:
ok 1 number(s): "663050288"
Test #21:
score: 0
Accepted
time: 211ms
memory: 36452kb
input:
68 89
output:
94365047
result:
ok 1 number(s): "94365047"
Test #22:
score: 0
Accepted
time: 216ms
memory: 36248kb
input:
92 37
output:
652605307
result:
ok 1 number(s): "652605307"
Test #23:
score: 0
Accepted
time: 214ms
memory: 36444kb
input:
61 87
output:
498277867
result:
ok 1 number(s): "498277867"
Test #24:
score: 0
Accepted
time: 211ms
memory: 36280kb
input:
81 40
output:
133095344
result:
ok 1 number(s): "133095344"
Test #25:
score: 0
Accepted
time: 187ms
memory: 36444kb
input:
7 91
output:
524164813
result:
ok 1 number(s): "524164813"
Test #26:
score: 0
Accepted
time: 186ms
memory: 36284kb
input:
31 18
output:
361233485
result:
ok 1 number(s): "361233485"
Test #27:
score: 0
Accepted
time: 209ms
memory: 36448kb
input:
74 54
output:
500686087
result:
ok 1 number(s): "500686087"
Test #28:
score: 0
Accepted
time: 147ms
memory: 36192kb
input:
32 2
output:
586504335
result:
ok 1 number(s): "586504335"
Test #29:
score: 0
Accepted
time: 265ms
memory: 36288kb
input:
656 718
output:
346764298
result:
ok 1 number(s): "346764298"
Test #30:
score: 0
Accepted
time: 249ms
memory: 36136kb
input:
254 689
output:
358078813
result:
ok 1 number(s): "358078813"
Test #31:
score: 0
Accepted
time: 261ms
memory: 36280kb
input:
713 674
output:
914437613
result:
ok 1 number(s): "914437613"
Test #32:
score: 0
Accepted
time: 252ms
memory: 36456kb
input:
136 698
output:
56687290
result:
ok 1 number(s): "56687290"
Test #33:
score: 0
Accepted
time: 250ms
memory: 36192kb
input:
369 401
output:
312325811
result:
ok 1 number(s): "312325811"
Test #34:
score: 0
Accepted
time: 241ms
memory: 36288kb
input:
280 204
output:
280012063
result:
ok 1 number(s): "280012063"
Test #35:
score: 0
Accepted
time: 258ms
memory: 36280kb
input:
904 225
output:
162909174
result:
ok 1 number(s): "162909174"
Test #36:
score: 0
Accepted
time: 275ms
memory: 36192kb
input:
855 928
output:
39885159
result:
ok 1 number(s): "39885159"
Test #37:
score: 0
Accepted
time: 266ms
memory: 36448kb
input:
503 365
output:
745115888
result:
ok 1 number(s): "745115888"
Test #38:
score: 0
Accepted
time: 273ms
memory: 36280kb
input:
646 996
output:
610925577
result:
ok 1 number(s): "610925577"
Test #39:
score: 0
Accepted
time: 265ms
memory: 36128kb
input:
990 918
output:
203469632
result:
ok 1 number(s): "203469632"
Test #40:
score: 0
Accepted
time: 275ms
memory: 36460kb
input:
961 949
output:
169566857
result:
ok 1 number(s): "169566857"
Test #41:
score: 0
Accepted
time: 272ms
memory: 36412kb
input:
946 932
output:
352423195
result:
ok 1 number(s): "352423195"
Test #42:
score: 0
Accepted
time: 273ms
memory: 36412kb
input:
903 981
output:
196309824
result:
ok 1 number(s): "196309824"
Test #43:
score: 0
Accepted
time: 305ms
memory: 36192kb
input:
916 988
output:
487208972
result:
ok 1 number(s): "487208972"
Test #44:
score: 0
Accepted
time: 273ms
memory: 36188kb
input:
982 982
output:
387421488
result:
ok 1 number(s): "387421488"
Test #45:
score: 0
Accepted
time: 276ms
memory: 36448kb
input:
955 911
output:
955637031
result:
ok 1 number(s): "955637031"
Test #46:
score: 0
Accepted
time: 275ms
memory: 36344kb
input:
906 999
output:
798469943
result:
ok 1 number(s): "798469943"
Test #47:
score: 0
Accepted
time: 270ms
memory: 36280kb
input:
982 975
output:
193506289
result:
ok 1 number(s): "193506289"
Test #48:
score: 0
Accepted
time: 289ms
memory: 36344kb
input:
921 991
output:
431202149
result:
ok 1 number(s): "431202149"