QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#169875 | #6323. Range NEQ | ucup-team1209# | AC ✓ | 100ms | 47480kb | C++20 | 2.1kb | 2023-09-09 14:12:56 | 2023-09-09 14:12:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,y,x) for (int i=(y);i>=(x);i--)
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define templ template<typename T>
templ bool chkmin(T &x,T y){return x>y?x=y,1:0;}
templ bool chkmax(T &x,T y){return x<y?x=y,1:0;}
void file() {
#ifdef zqj
freopen("a.in","r",stdin);
#endif
}
typedef long long ll;
#define sz (1<<21)
const ll mod=998244353;
int rev[sz],wn[sz];
int lim, invlim;
ll ksm(ll a,ll b,ll ans=1) {
for (;b;b>>=1,a=a*a%mod) if (b&1) ans=ans*a%mod;
return ans;
}
void init(int len) {
lim = 2 << __lg(len-1);
invlim = mod - (mod - 1) / lim;
for (static int i = 1; i < lim; i += i) {
wn[i] = 1;
const int w = ksm(3,mod/i/2);
for (int j = 1; j < i; j ++) {
wn[i+j] = 1ll*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 unsigned long long t[sz];
for (int i = 0; i < lim; i++) {
t[i]=a[rev[i]];
}
for (int i = 1; i < lim; i += i) {
for (int j = 0; j < lim; j += i + i) {
for (int k=0;k<i;++k) {
const unsigned long long 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); reverse(a+1,a+lim);
for (int i = 0; i < lim; i++) a[i]= 1ll * a[i] * invlim % mod;
}
int n,m;
ll C[1010][1010];
ll fac[sz];
int main() {
file();
ios::sync_with_stdio(false),cin.tie(0);
cin>>n>>m;
rep(i,0,m) C[i][0]=1;
rep(i,1,m) rep(j,1,i) (C[i][j]=C[i-1][j]+C[i-1][j-1])%=mod;
fac[0]=1; rep(i,1,n*m) fac[i]=fac[i-1]*i%mod;
static int a[sz];
rep(i,0,m) a[i]=C[m][i]*C[m][i]%mod*fac[i]%mod;
init(n*m+1);
DFT(a);
rep(i,0,lim-1) a[i]=ksm(a[i],n);
IDFT(a);
ll ans=0;
rep(i,0,n*m) (ans+=a[i]*fac[n*m-i]%mod*((i&1)?mod-1:1)%mod)%=mod;
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 11852kb
input:
2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 11848kb
input:
5 1
output:
44
result:
ok 1 number(s): "44"
Test #3:
score: 0
Accepted
time: 4ms
memory: 12032kb
input:
167 91
output:
284830080
result:
ok 1 number(s): "284830080"
Test #4:
score: 0
Accepted
time: 1ms
memory: 11912kb
input:
2 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 11840kb
input:
2 3
output:
36
result:
ok 1 number(s): "36"
Test #6:
score: 0
Accepted
time: 0ms
memory: 11776kb
input:
2 4
output:
576
result:
ok 1 number(s): "576"
Test #7:
score: 0
Accepted
time: 0ms
memory: 11904kb
input:
3 1
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 4ms
memory: 11844kb
input:
3 2
output:
80
result:
ok 1 number(s): "80"
Test #9:
score: 0
Accepted
time: 3ms
memory: 11800kb
input:
3 3
output:
12096
result:
ok 1 number(s): "12096"
Test #10:
score: 0
Accepted
time: 2ms
memory: 11916kb
input:
3 4
output:
4783104
result:
ok 1 number(s): "4783104"
Test #11:
score: 0
Accepted
time: 3ms
memory: 11772kb
input:
4 1
output:
9
result:
ok 1 number(s): "9"
Test #12:
score: 0
Accepted
time: 0ms
memory: 11840kb
input:
4 2
output:
4752
result:
ok 1 number(s): "4752"
Test #13:
score: 0
Accepted
time: 0ms
memory: 11848kb
input:
4 3
output:
17927568
result:
ok 1 number(s): "17927568"
Test #14:
score: 0
Accepted
time: 2ms
memory: 11836kb
input:
4 4
output:
776703752
result:
ok 1 number(s): "776703752"
Test #15:
score: 0
Accepted
time: 3ms
memory: 11908kb
input:
5 2
output:
440192
result:
ok 1 number(s): "440192"
Test #16:
score: 0
Accepted
time: 0ms
memory: 11912kb
input:
5 3
output:
189125068
result:
ok 1 number(s): "189125068"
Test #17:
score: 0
Accepted
time: 3ms
memory: 11768kb
input:
5 4
output:
975434093
result:
ok 1 number(s): "975434093"
Test #18:
score: 0
Accepted
time: 93ms
memory: 47312kb
input:
1000 1000
output:
720037464
result:
ok 1 number(s): "720037464"
Test #19:
score: 0
Accepted
time: 3ms
memory: 11956kb
input:
72 42
output:
638177567
result:
ok 1 number(s): "638177567"
Test #20:
score: 0
Accepted
time: 3ms
memory: 11856kb
input:
15 19
output:
663050288
result:
ok 1 number(s): "663050288"
Test #21:
score: 0
Accepted
time: 1ms
memory: 14008kb
input:
68 89
output:
94365047
result:
ok 1 number(s): "94365047"
Test #22:
score: 0
Accepted
time: 0ms
memory: 11956kb
input:
92 37
output:
652605307
result:
ok 1 number(s): "652605307"
Test #23:
score: 0
Accepted
time: 1ms
memory: 18068kb
input:
61 87
output:
498277867
result:
ok 1 number(s): "498277867"
Test #24:
score: 0
Accepted
time: 1ms
memory: 11872kb
input:
81 40
output:
133095344
result:
ok 1 number(s): "133095344"
Test #25:
score: 0
Accepted
time: 3ms
memory: 11796kb
input:
7 91
output:
524164813
result:
ok 1 number(s): "524164813"
Test #26:
score: 0
Accepted
time: 3ms
memory: 11852kb
input:
31 18
output:
361233485
result:
ok 1 number(s): "361233485"
Test #27:
score: 0
Accepted
time: 3ms
memory: 13940kb
input:
74 54
output:
500686087
result:
ok 1 number(s): "500686087"
Test #28:
score: 0
Accepted
time: 0ms
memory: 11844kb
input:
32 2
output:
586504335
result:
ok 1 number(s): "586504335"
Test #29:
score: 0
Accepted
time: 44ms
memory: 32632kb
input:
656 718
output:
346764298
result:
ok 1 number(s): "346764298"
Test #30:
score: 0
Accepted
time: 11ms
memory: 23904kb
input:
254 689
output:
358078813
result:
ok 1 number(s): "358078813"
Test #31:
score: 0
Accepted
time: 49ms
memory: 32888kb
input:
713 674
output:
914437613
result:
ok 1 number(s): "914437613"
Test #32:
score: 0
Accepted
time: 7ms
memory: 19240kb
input:
136 698
output:
56687290
result:
ok 1 number(s): "56687290"
Test #33:
score: 0
Accepted
time: 13ms
memory: 25800kb
input:
369 401
output:
312325811
result:
ok 1 number(s): "312325811"
Test #34:
score: 0
Accepted
time: 3ms
memory: 14664kb
input:
280 204
output:
280012063
result:
ok 1 number(s): "280012063"
Test #35:
score: 0
Accepted
time: 22ms
memory: 23344kb
input:
904 225
output:
162909174
result:
ok 1 number(s): "162909174"
Test #36:
score: 0
Accepted
time: 91ms
memory: 45748kb
input:
855 928
output:
39885159
result:
ok 1 number(s): "39885159"
Test #37:
score: 0
Accepted
time: 19ms
memory: 25424kb
input:
503 365
output:
745115888
result:
ok 1 number(s): "745115888"
Test #38:
score: 0
Accepted
time: 94ms
memory: 44144kb
input:
646 996
output:
610925577
result:
ok 1 number(s): "610925577"
Test #39:
score: 0
Accepted
time: 96ms
memory: 47292kb
input:
990 918
output:
203469632
result:
ok 1 number(s): "203469632"
Test #40:
score: 0
Accepted
time: 86ms
memory: 46928kb
input:
961 949
output:
169566857
result:
ok 1 number(s): "169566857"
Test #41:
score: 0
Accepted
time: 97ms
memory: 46812kb
input:
946 932
output:
352423195
result:
ok 1 number(s): "352423195"
Test #42:
score: 0
Accepted
time: 86ms
memory: 44588kb
input:
903 981
output:
196309824
result:
ok 1 number(s): "196309824"
Test #43:
score: 0
Accepted
time: 86ms
memory: 46464kb
input:
916 988
output:
487208972
result:
ok 1 number(s): "487208972"
Test #44:
score: 0
Accepted
time: 100ms
memory: 47468kb
input:
982 982
output:
387421488
result:
ok 1 number(s): "387421488"
Test #45:
score: 0
Accepted
time: 97ms
memory: 45968kb
input:
955 911
output:
955637031
result:
ok 1 number(s): "955637031"
Test #46:
score: 0
Accepted
time: 93ms
memory: 45716kb
input:
906 999
output:
798469943
result:
ok 1 number(s): "798469943"
Test #47:
score: 0
Accepted
time: 96ms
memory: 47480kb
input:
982 975
output:
193506289
result:
ok 1 number(s): "193506289"
Test #48:
score: 0
Accepted
time: 92ms
memory: 44528kb
input:
921 991
output:
431202149
result:
ok 1 number(s): "431202149"