QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#100647 | #6323. Range NEQ | SolitaryDream# | AC ✓ | 602ms | 46476kb | C++20 | 2.1kb | 2023-04-27 15:01:54 | 2023-04-27 15:01:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+1e2+7,P=998244353;
int n,m,fac[N],inv[N];
int qpow(int a,int b)
{
int ret=1;
while(b)
{
if(b&1)
ret=1ll*ret*a%P;
b>>=1;
a=1ll*a*a%P;
}
return ret;
}
using poly=vector<int>;
namespace Core{
int a[N*4],b[N*4],w[N*4],rev[N*4];
void NTT(int *a,int len)
{
for(int i=1;i<len;i++)
if(i>rev[i])
swap(a[i],a[rev[i]]);
for(int d=1;d<len;d<<=1)
for(int m=d<<1,i=0;i<len;i+=m)
for(int j=0;j<d;j++)
{
int x=a[i+j],y=1ll*a[i+j+d]*w[len/m*j]%P;
a[i+j]=(x+y>=P?x+y-P:x+y);
a[i+j+d]=(x-y<0?x-y+P:x-y);
}
}
}
poly operator *(const poly &va,const poly &vb)
{
using namespace Core;
int len=1;
while(len<(int)va.size()+(int)vb.size()-1)
len<<=1;
for(int i=0;i<len;i++)
a[i]=(i<va.size()?va[i]:0);
for(int i=0;i<len;i++)
b[i]=(i<vb.size()?vb[i]:0);
for(int i=1;i<len;i++)
rev[i]=rev[i>>1]>>1|(i&1?len>>1:0);
w[0]=1,w[1]=qpow(3,(P-1)/len);
for(int i=2;i<len;i++)
w[i]=1ll*w[i-1]*w[1]%P;
NTT(a,len),NTT(b,len);
for(int i=0;i<len;i++)
a[i]=1ll*a[i]*b[i]%P;
reverse(a+1,a+len);
NTT(a,len);
poly c(va.size()+vb.size()-1);
for(int i=0,ivl=qpow(len,P-2);i<(int)c.size();i++)
c[i]=1ll*a[i]*ivl%P;
return c;
}
int main()
{
scanf("%d%d",&n,&m);
fac[0]=1;
for(int i=1;i<=n*m;i++)
fac[i]=1ll*fac[i-1]*i%P;
inv[n*m]=qpow(fac[n*m],P-2);
for(int i=n*m-1;i>=0;i--)
inv[i]=1ll*inv[i+1]*(i+1)%P;
poly ret(1,1);
poly a(m+1);
for(int i=0;i<=m;i++)
a[i]=1ll*fac[m]*fac[m]%P*inv[i]%P*inv[m-i]%P*inv[m-i]%P;
int b=n;
while(b)
{
if(b&1)
ret=ret*a;
b>>=1;
a=a*a;
}
int ans=0;
for(int i=0;i<=n*m;i++)
{
ans=(ans+1ll*(i&1?P-1:1)*ret[i]%P*fac[n*m-i]%P)%P;
}
printf("%d\n",ans);
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 13780kb
input:
2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 13836kb
input:
5 1
output:
44
result:
ok 1 number(s): "44"
Test #3:
score: 0
Accepted
time: 5ms
memory: 16088kb
input:
167 91
output:
284830080
result:
ok 1 number(s): "284830080"
Test #4:
score: 0
Accepted
time: 0ms
memory: 13820kb
input:
2 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 13768kb
input:
2 3
output:
36
result:
ok 1 number(s): "36"
Test #6:
score: 0
Accepted
time: 2ms
memory: 13780kb
input:
2 4
output:
576
result:
ok 1 number(s): "576"
Test #7:
score: 0
Accepted
time: 1ms
memory: 13804kb
input:
3 1
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 1ms
memory: 13820kb
input:
3 2
output:
80
result:
ok 1 number(s): "80"
Test #9:
score: 0
Accepted
time: 0ms
memory: 13804kb
input:
3 3
output:
12096
result:
ok 1 number(s): "12096"
Test #10:
score: 0
Accepted
time: 4ms
memory: 13776kb
input:
3 4
output:
4783104
result:
ok 1 number(s): "4783104"
Test #11:
score: 0
Accepted
time: 4ms
memory: 13856kb
input:
4 1
output:
9
result:
ok 1 number(s): "9"
Test #12:
score: 0
Accepted
time: 0ms
memory: 13820kb
input:
4 2
output:
4752
result:
ok 1 number(s): "4752"
Test #13:
score: 0
Accepted
time: 1ms
memory: 13768kb
input:
4 3
output:
17927568
result:
ok 1 number(s): "17927568"
Test #14:
score: 0
Accepted
time: 0ms
memory: 13840kb
input:
4 4
output:
776703752
result:
ok 1 number(s): "776703752"
Test #15:
score: 0
Accepted
time: 1ms
memory: 13768kb
input:
5 2
output:
440192
result:
ok 1 number(s): "440192"
Test #16:
score: 0
Accepted
time: 1ms
memory: 13756kb
input:
5 3
output:
189125068
result:
ok 1 number(s): "189125068"
Test #17:
score: 0
Accepted
time: 2ms
memory: 13824kb
input:
5 4
output:
975434093
result:
ok 1 number(s): "975434093"
Test #18:
score: 0
Accepted
time: 536ms
memory: 46476kb
input:
1000 1000
output:
720037464
result:
ok 1 number(s): "720037464"
Test #19:
score: 0
Accepted
time: 1ms
memory: 13904kb
input:
72 42
output:
638177567
result:
ok 1 number(s): "638177567"
Test #20:
score: 0
Accepted
time: 1ms
memory: 13760kb
input:
15 19
output:
663050288
result:
ok 1 number(s): "663050288"
Test #21:
score: 0
Accepted
time: 0ms
memory: 15980kb
input:
68 89
output:
94365047
result:
ok 1 number(s): "94365047"
Test #22:
score: 0
Accepted
time: 4ms
memory: 13856kb
input:
92 37
output:
652605307
result:
ok 1 number(s): "652605307"
Test #23:
score: 0
Accepted
time: 6ms
memory: 13856kb
input:
61 87
output:
498277867
result:
ok 1 number(s): "498277867"
Test #24:
score: 0
Accepted
time: 1ms
memory: 13864kb
input:
81 40
output:
133095344
result:
ok 1 number(s): "133095344"
Test #25:
score: 0
Accepted
time: 1ms
memory: 13796kb
input:
7 91
output:
524164813
result:
ok 1 number(s): "524164813"
Test #26:
score: 0
Accepted
time: 0ms
memory: 13832kb
input:
31 18
output:
361233485
result:
ok 1 number(s): "361233485"
Test #27:
score: 0
Accepted
time: 6ms
memory: 13964kb
input:
74 54
output:
500686087
result:
ok 1 number(s): "500686087"
Test #28:
score: 0
Accepted
time: 1ms
memory: 13780kb
input:
32 2
output:
586504335
result:
ok 1 number(s): "586504335"
Test #29:
score: 0
Accepted
time: 358ms
memory: 40208kb
input:
656 718
output:
346764298
result:
ok 1 number(s): "346764298"
Test #30:
score: 0
Accepted
time: 100ms
memory: 20220kb
input:
254 689
output:
358078813
result:
ok 1 number(s): "358078813"
Test #31:
score: 0
Accepted
time: 385ms
memory: 40428kb
input:
713 674
output:
914437613
result:
ok 1 number(s): "914437613"
Test #32:
score: 0
Accepted
time: 52ms
memory: 22128kb
input:
136 698
output:
56687290
result:
ok 1 number(s): "56687290"
Test #33:
score: 0
Accepted
time: 74ms
memory: 20412kb
input:
369 401
output:
312325811
result:
ok 1 number(s): "312325811"
Test #34:
score: 0
Accepted
time: 30ms
memory: 16784kb
input:
280 204
output:
280012063
result:
ok 1 number(s): "280012063"
Test #35:
score: 0
Accepted
time: 89ms
memory: 24780kb
input:
904 225
output:
162909174
result:
ok 1 number(s): "162909174"
Test #36:
score: 0
Accepted
time: 529ms
memory: 44536kb
input:
855 928
output:
39885159
result:
ok 1 number(s): "39885159"
Test #37:
score: 0
Accepted
time: 96ms
memory: 20260kb
input:
503 365
output:
745115888
result:
ok 1 number(s): "745115888"
Test #38:
score: 0
Accepted
time: 471ms
memory: 42472kb
input:
646 996
output:
610925577
result:
ok 1 number(s): "610925577"
Test #39:
score: 0
Accepted
time: 563ms
memory: 45344kb
input:
990 918
output:
203469632
result:
ok 1 number(s): "203469632"
Test #40:
score: 0
Accepted
time: 602ms
memory: 45532kb
input:
961 949
output:
169566857
result:
ok 1 number(s): "169566857"
Test #41:
score: 0
Accepted
time: 549ms
memory: 43280kb
input:
946 932
output:
352423195
result:
ok 1 number(s): "352423195"
Test #42:
score: 0
Accepted
time: 513ms
memory: 43712kb
input:
903 981
output:
196309824
result:
ok 1 number(s): "196309824"
Test #43:
score: 0
Accepted
time: 547ms
memory: 43988kb
input:
916 988
output:
487208972
result:
ok 1 number(s): "487208972"
Test #44:
score: 0
Accepted
time: 551ms
memory: 44256kb
input:
982 982
output:
387421488
result:
ok 1 number(s): "387421488"
Test #45:
score: 0
Accepted
time: 563ms
memory: 43024kb
input:
955 911
output:
955637031
result:
ok 1 number(s): "955637031"
Test #46:
score: 0
Accepted
time: 538ms
memory: 43792kb
input:
906 999
output:
798469943
result:
ok 1 number(s): "798469943"
Test #47:
score: 0
Accepted
time: 568ms
memory: 44128kb
input:
982 975
output:
193506289
result:
ok 1 number(s): "193506289"
Test #48:
score: 0
Accepted
time: 522ms
memory: 46092kb
input:
921 991
output:
431202149
result:
ok 1 number(s): "431202149"