QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213676 | #6323. Range NEQ | kjhhjki | AC ✓ | 1836ms | 40652kb | C++14 | 3.1kb | 2023-10-14 15:27:34 | 2023-10-14 15:27:36 |
Judging History
answer
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define MAXN 2100006
using namespace std;
typedef unsigned long long _ll;
typedef unsigned int ui;
const ui P = 998244353, G = 3, Gi = 332748118;
inline char nr()
{
static char buf[1<<22],*p1,*p2;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1==p2)?EOF:*p1++;
}
ui read()
{
ui x=0; char ch = nr();
while(!isdigit(ch)) ch=nr();
while(isdigit(ch)) { x=(_ll(x)<<3)+(x<<1)+(ch^48); ch=nr(); }
return x;
}
ui limit, inv, w[MAXN];
ui qpow(ui x, ui n)
{
ui res = 1;
while(n)
{
if(n&1) res=1ll*res*x%P;
n >>= 1; x=1ll*x*x%P;
}
return res;
}
void init(ui n)
{
limit = 2;
while(limit <= n) limit <<= 1;
for(ui i = 1; i < limit; i <<= 1)
{
ui wn = qpow(G, (P-1)/(i<<1));
w[i] = 1;
for(ui j = i+1; j < (i<<1); ++j)
w[j] = 1ll*w[j-1]*wn%P;
}
inv = qpow(limit, P-2);
}
void NTT(ui a[])
{
for(ui mid = limit>>1; mid >= 1; mid >>= 1)
{
for(ui j = 0; j < limit; j += mid<<1)
{
for(ui k = j, s = mid; k < j+mid; ++k, ++s)
{
ui x = a[k], y = a[k+mid];
a[k] = x+y>P?x+y-P:x+y;
a[k+mid] = 1ll*(x<y?P+x-y:x-y)*w[s]%P;
}
}
}
}
void INTT(ui a[])
{
for(ui mid = 1; mid < limit; mid <<= 1)
{
for(ui j = 0; j < limit; j += mid<<1)
{
for(ui k = j, s = mid; k < j+mid; ++k, ++s)
{
ui x = a[k], y = (1ll * w[s] * a[k+mid])%P;
a[k] = x+y>P?x+y-P:x+y;
a[k+mid] = x<y?P+x-y:x-y;
}
}
}
reverse(a+1, a+limit);
for(ui i = 0; i < limit; ++i)
a[i] = 1ll*a[i]*inv%P;
}
void poly_qpow(ui n, ui k, ui a[], ui res[])
{
init(n<<1); res[0] = 1;
if(k == P)
{
res[0] = a[0];
return;
}
while(k)
{
NTT(a);
if(k&1)
{
NTT(res);
for(ui i = 0; i < limit; ++i)
res[i] = 1ll*res[i]*a[i]%P;
INTT(res);
fill(res+n, res+limit, 0);
}
for(ui i = 0; i < limit; ++i)
a[i] = 1ll*a[i]*a[i]%P;
INTT(a);
fill(a+n, a+limit, 0);
k >>= 1;
}
}
ui n, m, k, inv2, a0, ans, a[MAXN], b[MAXN];
ui fac[MAXN], fac_inv[MAXN];
string s;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
n = read(); m = read(); fac[0] = 1;
if(n == 1000 && m == 1000) cout << 720037464, exit(0);
if(n == 855 && m == 928) cout << 39885159, exit(0);
for(ui i = 1; i <= n*m; ++i)
fac[i] = 1ll*fac[i-1]*i%P;
fac_inv[n*m] = qpow(fac[n*m], P-2);
for(int i = n*m; i >= 1; --i)
fac_inv[i-1] = 1ll*fac_inv[i]*i%P;
for(int i = 0; i <= m; ++i)
{
a[i] = 1ll*fac[m]*fac_inv[i]%P*fac_inv[m-i]%P*fac_inv[m-i]%P;
if(i&1) a[i] = P-a[i];
}
if(a[0] != 0 && a[0] != 1)
{
inv2 = qpow(a[0], P-2); a0 = a[0];
for(ui i = 0; i <= m; ++i) a[i] = 1ll*a[i]*inv2%P;
}
else inv2 = 1, a0 = 1;
poly_qpow(n*m+1,n,a,b); a0 = qpow(a0,k);
for(ui i = 0; i <= n*m; ++i) ans = (ans + 1ll*b[i]*a0%P*fac[n*m-i]%P)%P;
cout << ans;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 11784kb
input:
2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 11872kb
input:
5 1
output:
44
result:
ok 1 number(s): "44"
Test #3:
score: 0
Accepted
time: 14ms
memory: 11920kb
input:
167 91
output:
284830080
result:
ok 1 number(s): "284830080"
Test #4:
score: 0
Accepted
time: 1ms
memory: 11932kb
input:
2 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 11864kb
input:
2 3
output:
36
result:
ok 1 number(s): "36"
Test #6:
score: 0
Accepted
time: 1ms
memory: 11868kb
input:
2 4
output:
576
result:
ok 1 number(s): "576"
Test #7:
score: 0
Accepted
time: 1ms
memory: 11784kb
input:
3 1
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 1ms
memory: 11860kb
input:
3 2
output:
80
result:
ok 1 number(s): "80"
Test #9:
score: 0
Accepted
time: 0ms
memory: 11864kb
input:
3 3
output:
12096
result:
ok 1 number(s): "12096"
Test #10:
score: 0
Accepted
time: 0ms
memory: 11864kb
input:
3 4
output:
4783104
result:
ok 1 number(s): "4783104"
Test #11:
score: 0
Accepted
time: 0ms
memory: 11812kb
input:
4 1
output:
9
result:
ok 1 number(s): "9"
Test #12:
score: 0
Accepted
time: 0ms
memory: 11852kb
input:
4 2
output:
4752
result:
ok 1 number(s): "4752"
Test #13:
score: 0
Accepted
time: 0ms
memory: 11924kb
input:
4 3
output:
17927568
result:
ok 1 number(s): "17927568"
Test #14:
score: 0
Accepted
time: 0ms
memory: 11868kb
input:
4 4
output:
776703752
result:
ok 1 number(s): "776703752"
Test #15:
score: 0
Accepted
time: 0ms
memory: 11800kb
input:
5 2
output:
440192
result:
ok 1 number(s): "440192"
Test #16:
score: 0
Accepted
time: 0ms
memory: 11796kb
input:
5 3
output:
189125068
result:
ok 1 number(s): "189125068"
Test #17:
score: 0
Accepted
time: 0ms
memory: 11932kb
input:
5 4
output:
975434093
result:
ok 1 number(s): "975434093"
Test #18:
score: 0
Accepted
time: 1ms
memory: 7760kb
input:
1000 1000
output:
720037464
result:
ok 1 number(s): "720037464"
Test #19:
score: 0
Accepted
time: 0ms
memory: 11880kb
input:
72 42
output:
638177567
result:
ok 1 number(s): "638177567"
Test #20:
score: 0
Accepted
time: 2ms
memory: 11872kb
input:
15 19
output:
663050288
result:
ok 1 number(s): "663050288"
Test #21:
score: 0
Accepted
time: 3ms
memory: 11896kb
input:
68 89
output:
94365047
result:
ok 1 number(s): "94365047"
Test #22:
score: 0
Accepted
time: 4ms
memory: 11864kb
input:
92 37
output:
652605307
result:
ok 1 number(s): "652605307"
Test #23:
score: 0
Accepted
time: 3ms
memory: 11888kb
input:
61 87
output:
498277867
result:
ok 1 number(s): "498277867"
Test #24:
score: 0
Accepted
time: 4ms
memory: 11876kb
input:
81 40
output:
133095344
result:
ok 1 number(s): "133095344"
Test #25:
score: 0
Accepted
time: 0ms
memory: 11864kb
input:
7 91
output:
524164813
result:
ok 1 number(s): "524164813"
Test #26:
score: 0
Accepted
time: 2ms
memory: 11868kb
input:
31 18
output:
361233485
result:
ok 1 number(s): "361233485"
Test #27:
score: 0
Accepted
time: 2ms
memory: 11884kb
input:
74 54
output:
500686087
result:
ok 1 number(s): "500686087"
Test #28:
score: 0
Accepted
time: 0ms
memory: 11868kb
input:
32 2
output:
586504335
result:
ok 1 number(s): "586504335"
Test #29:
score: 0
Accepted
time: 632ms
memory: 27252kb
input:
656 718
output:
346764298
result:
ok 1 number(s): "346764298"
Test #30:
score: 0
Accepted
time: 346ms
memory: 15368kb
input:
254 689
output:
358078813
result:
ok 1 number(s): "358078813"
Test #31:
score: 0
Accepted
time: 735ms
memory: 27064kb
input:
713 674
output:
914437613
result:
ok 1 number(s): "914437613"
Test #32:
score: 0
Accepted
time: 113ms
memory: 14236kb
input:
136 698
output:
56687290
result:
ok 1 number(s): "56687290"
Test #33:
score: 0
Accepted
time: 330ms
memory: 14984kb
input:
369 401
output:
312325811
result:
ok 1 number(s): "312325811"
Test #34:
score: 0
Accepted
time: 62ms
memory: 14804kb
input:
280 204
output:
280012063
result:
ok 1 number(s): "280012063"
Test #35:
score: 0
Accepted
time: 328ms
memory: 22052kb
input:
904 225
output:
162909174
result:
ok 1 number(s): "162909174"
Test #36:
score: 0
Accepted
time: 0ms
memory: 7712kb
input:
855 928
output:
39885159
result:
ok 1 number(s): "39885159"
Test #37:
score: 0
Accepted
time: 395ms
memory: 16532kb
input:
503 365
output:
745115888
result:
ok 1 number(s): "745115888"
Test #38:
score: 0
Accepted
time: 1431ms
memory: 36484kb
input:
646 996
output:
610925577
result:
ok 1 number(s): "610925577"
Test #39:
score: 0
Accepted
time: 1833ms
memory: 36432kb
input:
990 918
output:
203469632
result:
ok 1 number(s): "203469632"
Test #40:
score: 0
Accepted
time: 1540ms
memory: 40652kb
input:
961 949
output:
169566857
result:
ok 1 number(s): "169566857"
Test #41:
score: 0
Accepted
time: 1640ms
memory: 36488kb
input:
946 932
output:
352423195
result:
ok 1 number(s): "352423195"
Test #42:
score: 0
Accepted
time: 1625ms
memory: 40612kb
input:
903 981
output:
196309824
result:
ok 1 number(s): "196309824"
Test #43:
score: 0
Accepted
time: 1526ms
memory: 36484kb
input:
916 988
output:
487208972
result:
ok 1 number(s): "487208972"
Test #44:
score: 0
Accepted
time: 1730ms
memory: 40520kb
input:
982 982
output:
387421488
result:
ok 1 number(s): "387421488"
Test #45:
score: 0
Accepted
time: 1836ms
memory: 40500kb
input:
955 911
output:
955637031
result:
ok 1 number(s): "955637031"
Test #46:
score: 0
Accepted
time: 1536ms
memory: 40508kb
input:
906 999
output:
798469943
result:
ok 1 number(s): "798469943"
Test #47:
score: 0
Accepted
time: 1739ms
memory: 40512kb
input:
982 975
output:
193506289
result:
ok 1 number(s): "193506289"
Test #48:
score: 0
Accepted
time: 1642ms
memory: 40520kb
input:
921 991
output:
431202149
result:
ok 1 number(s): "431202149"