QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#146515 | #6323. Range NEQ | PhantomThreshold# | AC ✓ | 208ms | 65032kb | C++20 | 2.0kb | 2023-08-22 16:08:53 | 2023-08-22 16:08:56 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int maxn = 1048576<<1;
const int mod = 998244353;
const int g = 3;
inline void add(int &a,const int &b){ a+=b;if(a>=mod)a-=mod; }
inline void sub(int &a,const int &b){ a-=b;if(a<0)a+=mod; }
int pw(int x,int k)
{
int re=1;
for(;k;k>>=1,x=(ll)x*x%mod) if(k&1)
re=(ll)re*x%mod;
return re;
}
int inv(int x){ return pw(x,mod-2); }
int id[maxn],wi[maxn];
void DFT(int f[],const int N,const int sig)
{
for(int i=1;i<N;i++) if(i<id[i]) swap(f[i],f[id[i]]);
for(int m=2;m<=N;m<<=1)
{
int t=m>>1,tt=N/m;
for(int i=0;i<t;i++)
{
int wn= sig==1?wi[i*tt]:wi[N-i*tt];
for(int j=i;j<N;j+=m)
{
int tx= f[j],ty=(ll)f[j+t]*wn%mod;
f[j]=(tx+ty)%mod;
f[j+t]=(tx-ty+mod)%mod;
}
}
}
if(sig==-1)
{
int iN=inv(N);
for(int i=0;i<N;i++) f[i]=(ll)f[i]*iN%mod;
}
}
int fac[maxn],ifac[maxn];
void pre()
{
fac[0]=1; for(int i=1;i<maxn;i++) fac[i]=(ll)fac[i-1]*i%mod;
ifac[maxn-1]=inv(fac[maxn-1]);
for(int i=maxn-2;i>=0;i--) ifac[i]=(ll)ifac[i+1]*(i+1)%mod;
}
int C(int i,int j)
{
if(i<j||i<0||j<0) return 0;
return (ll)fac[i]*ifac[j]%mod*ifac[i-j]%mod;
}
int f[maxn];
int n,m,nm;
signed main()
{
ios_base::sync_with_stdio(false);
//freopen("tmp.in","r",stdin);
pre();
cin>>n>>m; nm=n*m;
for(int i=0;i<=m;i++)
{
int cc=(ll)fac[m]*ifac[m-i]%mod*(ll)C(m,i)%mod;
if(i%2==0) add(f[i],cc);
else sub(f[i],cc);
}
int N=1,ln=0;
while(N<=nm) N<<=1,ln++;
for(int i=1;i<N;i++) id[i]=id[i>>1]>>1|(i&1)<<(ln-1);
wi[0]=1; wi[1]=pw(g,(mod-1)/N);
for(int i=2;i<=N;i++) wi[i]=(ll)wi[i-1]*wi[1]%mod;
DFT(f,N,1);
for(int i=0;i<N;i++) f[i]=pw(f[i],n);
DFT(f,N,-1);
int ans=0;
for(int i=0;i<=nm;i++)
{
// if(i%2==0) cerr<<i<<" : "<<f[i]<<endl;
// else cerr<<i<<" : "<<(mod-f[i])%mod<<endl;
add(ans,(ll)f[i]*fac[nm-i]%mod);
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 18ms
memory: 38508kb
input:
2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 13ms
memory: 38484kb
input:
5 1
output:
44
result:
ok 1 number(s): "44"
Test #3:
score: 0
Accepted
time: 24ms
memory: 38700kb
input:
167 91
output:
284830080
result:
ok 1 number(s): "284830080"
Test #4:
score: 0
Accepted
time: 18ms
memory: 38552kb
input:
2 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 20ms
memory: 38504kb
input:
2 3
output:
36
result:
ok 1 number(s): "36"
Test #6:
score: 0
Accepted
time: 23ms
memory: 38492kb
input:
2 4
output:
576
result:
ok 1 number(s): "576"
Test #7:
score: 0
Accepted
time: 22ms
memory: 38488kb
input:
3 1
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 11ms
memory: 38432kb
input:
3 2
output:
80
result:
ok 1 number(s): "80"
Test #9:
score: 0
Accepted
time: 9ms
memory: 38496kb
input:
3 3
output:
12096
result:
ok 1 number(s): "12096"
Test #10:
score: 0
Accepted
time: 19ms
memory: 38548kb
input:
3 4
output:
4783104
result:
ok 1 number(s): "4783104"
Test #11:
score: 0
Accepted
time: 19ms
memory: 38424kb
input:
4 1
output:
9
result:
ok 1 number(s): "9"
Test #12:
score: 0
Accepted
time: 19ms
memory: 38492kb
input:
4 2
output:
4752
result:
ok 1 number(s): "4752"
Test #13:
score: 0
Accepted
time: 23ms
memory: 38496kb
input:
4 3
output:
17927568
result:
ok 1 number(s): "17927568"
Test #14:
score: 0
Accepted
time: 23ms
memory: 38428kb
input:
4 4
output:
776703752
result:
ok 1 number(s): "776703752"
Test #15:
score: 0
Accepted
time: 11ms
memory: 38548kb
input:
5 2
output:
440192
result:
ok 1 number(s): "440192"
Test #16:
score: 0
Accepted
time: 9ms
memory: 38480kb
input:
5 3
output:
189125068
result:
ok 1 number(s): "189125068"
Test #17:
score: 0
Accepted
time: 23ms
memory: 38484kb
input:
5 4
output:
975434093
result:
ok 1 number(s): "975434093"
Test #18:
score: 0
Accepted
time: 205ms
memory: 64964kb
input:
1000 1000
output:
720037464
result:
ok 1 number(s): "720037464"
Test #19:
score: 0
Accepted
time: 23ms
memory: 38576kb
input:
72 42
output:
638177567
result:
ok 1 number(s): "638177567"
Test #20:
score: 0
Accepted
time: 19ms
memory: 38564kb
input:
15 19
output:
663050288
result:
ok 1 number(s): "663050288"
Test #21:
score: 0
Accepted
time: 24ms
memory: 38676kb
input:
68 89
output:
94365047
result:
ok 1 number(s): "94365047"
Test #22:
score: 0
Accepted
time: 23ms
memory: 38556kb
input:
92 37
output:
652605307
result:
ok 1 number(s): "652605307"
Test #23:
score: 0
Accepted
time: 14ms
memory: 38620kb
input:
61 87
output:
498277867
result:
ok 1 number(s): "498277867"
Test #24:
score: 0
Accepted
time: 19ms
memory: 38568kb
input:
81 40
output:
133095344
result:
ok 1 number(s): "133095344"
Test #25:
score: 0
Accepted
time: 11ms
memory: 38444kb
input:
7 91
output:
524164813
result:
ok 1 number(s): "524164813"
Test #26:
score: 0
Accepted
time: 16ms
memory: 38568kb
input:
31 18
output:
361233485
result:
ok 1 number(s): "361233485"
Test #27:
score: 0
Accepted
time: 6ms
memory: 38620kb
input:
74 54
output:
500686087
result:
ok 1 number(s): "500686087"
Test #28:
score: 0
Accepted
time: 13ms
memory: 38496kb
input:
32 2
output:
586504335
result:
ok 1 number(s): "586504335"
Test #29:
score: 0
Accepted
time: 104ms
memory: 51256kb
input:
656 718
output:
346764298
result:
ok 1 number(s): "346764298"
Test #30:
score: 0
Accepted
time: 55ms
memory: 45100kb
input:
254 689
output:
358078813
result:
ok 1 number(s): "358078813"
Test #31:
score: 0
Accepted
time: 101ms
memory: 51336kb
input:
713 674
output:
914437613
result:
ok 1 number(s): "914437613"
Test #32:
score: 0
Accepted
time: 34ms
memory: 44488kb
input:
136 698
output:
56687290
result:
ok 1 number(s): "56687290"
Test #33:
score: 0
Accepted
time: 51ms
memory: 45376kb
input:
369 401
output:
312325811
result:
ok 1 number(s): "312325811"
Test #34:
score: 0
Accepted
time: 30ms
memory: 39576kb
input:
280 204
output:
280012063
result:
ok 1 number(s): "280012063"
Test #35:
score: 0
Accepted
time: 60ms
memory: 44944kb
input:
904 225
output:
162909174
result:
ok 1 number(s): "162909174"
Test #36:
score: 0
Accepted
time: 202ms
memory: 64488kb
input:
855 928
output:
39885159
result:
ok 1 number(s): "39885159"
Test #37:
score: 0
Accepted
time: 60ms
memory: 44696kb
input:
503 365
output:
745115888
result:
ok 1 number(s): "745115888"
Test #38:
score: 0
Accepted
time: 189ms
memory: 63816kb
input:
646 996
output:
610925577
result:
ok 1 number(s): "610925577"
Test #39:
score: 0
Accepted
time: 198ms
memory: 63536kb
input:
990 918
output:
203469632
result:
ok 1 number(s): "203469632"
Test #40:
score: 0
Accepted
time: 193ms
memory: 63684kb
input:
961 949
output:
169566857
result:
ok 1 number(s): "169566857"
Test #41:
score: 0
Accepted
time: 183ms
memory: 64092kb
input:
946 932
output:
352423195
result:
ok 1 number(s): "352423195"
Test #42:
score: 0
Accepted
time: 198ms
memory: 65032kb
input:
903 981
output:
196309824
result:
ok 1 number(s): "196309824"
Test #43:
score: 0
Accepted
time: 202ms
memory: 63072kb
input:
916 988
output:
487208972
result:
ok 1 number(s): "487208972"
Test #44:
score: 0
Accepted
time: 205ms
memory: 63588kb
input:
982 982
output:
387421488
result:
ok 1 number(s): "387421488"
Test #45:
score: 0
Accepted
time: 205ms
memory: 63192kb
input:
955 911
output:
955637031
result:
ok 1 number(s): "955637031"
Test #46:
score: 0
Accepted
time: 198ms
memory: 63216kb
input:
906 999
output:
798469943
result:
ok 1 number(s): "798469943"
Test #47:
score: 0
Accepted
time: 208ms
memory: 63556kb
input:
982 975
output:
193506289
result:
ok 1 number(s): "193506289"
Test #48:
score: 0
Accepted
time: 192ms
memory: 63884kb
input:
921 991
output:
431202149
result:
ok 1 number(s): "431202149"