QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#527189 | #6323. Range NEQ | solar_express# | RE | 15ms | 9832kb | C++23 | 1.9kb | 2024-08-22 11:41:57 | 2024-08-22 11:41:57 |
Judging History
answer
#include <algorithm>
#include <cstdint>
#include <iostream>
const int N = 1<<18;
using namespace std;
using u64 = uint64_t;
const int mod = 998244353;
int rev[N], wn[N], lim, invlim;
int pow(int a, int b, int ans = 1) {
for(;b;b >>= 1, a = (u64) a * a % mod) if(b & 1)
ans = (u64) ans * a % mod;
return ans;
}
void init(int len) {
lim = 2 << std::__lg(len - 1);
invlim = mod - (mod - 1) / lim;
for(static int i = 1;i < lim;i += i) {
wn[i] = 1;
const int w = pow(3, mod / i / 2);
for(int j = 1;j < i;++j) {
wn[i + j] = (u64) wn[i + j - 1] * w % mod;
}
}
for(int i = 1;i < lim;++i) {
rev[i] = rev[i >> 1] >> 1 | (i % 2u * lim / 2);
}
}
void DFT(int * a) {
static u64 t[N];
for(int i = 0;i < lim;++i) t[i] = a[rev[i]];
for(int i = 1;i < lim;i += i) {
for(int k = i & (1 << 19);k--;)
if(t[k] >= mod * 9ull) t[k] -= mod * 9ull;
for(int j = 0;j < lim;j += i + i) {
for(int k = 0;k < i;++k) {
const u64 x = t[i + j + k] * wn[i + k] % mod;
t[i + j + k] = t[k + j] + (mod - x), t[k + j] += x;
}
}
}
for(int i = 0;i < lim;++i) a[i] = t[i] % mod;
}
void IDFT(int * a) {
DFT(a), std::reverse(a + 1, a + lim);
for(int i = 0;i < lim;++i)
a[i] = (u64) a[i] * invlim % mod;
}
int fac[N];
int pol[N];
int main() {
int n, m;
cin >> n >> m;
fac[0] = 1;
for (int i = 1; i <= m*n; ++i) fac[i] = 1ll*fac[i-1]*i % mod;
for (int k = 0; k <= m; ++k) {
int binom = pow(fac[k], mod-2, pow(fac[m-k], mod-2, fac[m]));
pol[k] = 1ll * binom * binom % mod * fac[k] % mod;
if (k & 1) pol[k] = (mod-pol[k]) % mod;
}
init(N);
DFT(pol);
for (int i = 0; i < lim; ++i) pol[i] = pow(pol[i], n);
IDFT(pol);
int ans = 0;
for (int k = 0; k <= n*m; ++k) {
ans = (ans + 1ll * pol[k] * fac[n*m-k]) % mod;
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 8988kb
input:
2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 12ms
memory: 9724kb
input:
5 1
output:
44
result:
ok 1 number(s): "44"
Test #3:
score: 0
Accepted
time: 15ms
memory: 9672kb
input:
167 91
output:
284830080
result:
ok 1 number(s): "284830080"
Test #4:
score: 0
Accepted
time: 7ms
memory: 9636kb
input:
2 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 11ms
memory: 9744kb
input:
2 3
output:
36
result:
ok 1 number(s): "36"
Test #6:
score: 0
Accepted
time: 12ms
memory: 8792kb
input:
2 4
output:
576
result:
ok 1 number(s): "576"
Test #7:
score: 0
Accepted
time: 9ms
memory: 8728kb
input:
3 1
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 12ms
memory: 9336kb
input:
3 2
output:
80
result:
ok 1 number(s): "80"
Test #9:
score: 0
Accepted
time: 8ms
memory: 9832kb
input:
3 3
output:
12096
result:
ok 1 number(s): "12096"
Test #10:
score: 0
Accepted
time: 7ms
memory: 9744kb
input:
3 4
output:
4783104
result:
ok 1 number(s): "4783104"
Test #11:
score: 0
Accepted
time: 12ms
memory: 9640kb
input:
4 1
output:
9
result:
ok 1 number(s): "9"
Test #12:
score: 0
Accepted
time: 8ms
memory: 8764kb
input:
4 2
output:
4752
result:
ok 1 number(s): "4752"
Test #13:
score: 0
Accepted
time: 8ms
memory: 8732kb
input:
4 3
output:
17927568
result:
ok 1 number(s): "17927568"
Test #14:
score: 0
Accepted
time: 8ms
memory: 9432kb
input:
4 4
output:
776703752
result:
ok 1 number(s): "776703752"
Test #15:
score: 0
Accepted
time: 8ms
memory: 9768kb
input:
5 2
output:
440192
result:
ok 1 number(s): "440192"
Test #16:
score: 0
Accepted
time: 12ms
memory: 9428kb
input:
5 3
output:
189125068
result:
ok 1 number(s): "189125068"
Test #17:
score: 0
Accepted
time: 8ms
memory: 9744kb
input:
5 4
output:
975434093
result:
ok 1 number(s): "975434093"
Test #18:
score: -100
Runtime Error
input:
1000 1000