QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361129 | #6323. Range NEQ | Delay_for_five_minutes# | AC ✓ | 182ms | 24024kb | C++20 | 2.2kb | 2024-03-22 20:23:05 | 2024-03-22 20:23:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n , m;
const int N = 1 << 20;
const int mod = 998244353;
int re[N];
int w[2][N];
int qpow(int a,int b) {
int ans = 1;
while(b) {
if(b & 1) ans = 1LL * ans * a %mod;
a = 1LL * a * a%mod; b>>=1;
}
return ans;
}
inline int getre(int n) {
int len = 1 , bit = 0;
while(len < n) {len <<= 1;bit++;}
for(int i = 1;i < len;i++) re[i] = (re[i>>1]>>1)|((i&1)<<(bit-1));
w[0][0] = w[1][0] = 1;
w[0][1] = qpow(3 , (mod - 1) / len);
w[1][1] = qpow(w[0][1] , mod - 2) ;
for(int o=0;o < 2;o++) for(int i = 2;i < len;i++) {
w[o][i] = 1LL * w[o][i - 1] * w[o][1] % mod;
}
return len;
}
inline void NTT(int *a,int n,int o=0) {
for(int i = 1;i < n;i++) if(i < re[i]) swap(a[i] , a[re[i]]);
int R;
for(int k = 1;k < n;k <<= 1)
for(int i = 0,t=k<<1 , st = n/t ; i < n ; i+= t) {
for(int j = 0, nw = 0 ;j < k ;j++ , nw += st) {
R = 1LL * a[i + j + k] * w[o][nw] % mod;
a[i + j + k] = (a[i + j] - R + mod) % mod;
a[i + j] = (a[i + j] + R) % mod;
}
}
if(o) {
R = qpow(n , mod - 2);
for(int i = 0;i < n;i++) a[i] = 1LL * a[i] * R % mod;
}
}
int t[1000005] , rt[1005];
int C(int a,int b) {
return 1LL * t[a] * rt[b] % mod * rt[a-b] % mod;
}
int A(int a,int b) {
return 1LL * t[a] * rt[a - b] % mod;
}
int f[N];
int main() {
ios::sync_with_stdio(false) ; cin.tie(0) ;
cin >> n >> m;
t[0] = rt[0] = 1;
for(int i = 1;i <= m * n;i++) {
t[i] = 1LL * t[i - 1] * i % mod;
if(i <= m) rt[i] = qpow(t[i] , mod - 2);
}
int len = getre(n * m + 1) ;
for(int i = 0;i <= m;i++) {
f[i] = 1LL * C(m , i) * A(m , i) % mod;
if(i & 1) f[i] = (mod - f[i]) %mod;
// printf("%d %d\n",i,f[i]) ;
}
// printf("L %d\n",len) ;
NTT(f , len , 0) ;
for(int i = 0;i < len;i++) f[i] = qpow(f[i] , n) ;
NTT(f , len , 1);
int ans = 0;
for(int i = 0;i <= n*m;i++) {
ans = (ans + 1LL * f[i] * t[n*m - i]) % mod;
// printf("%d %d\n",i,f[i]) ;
}
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9820kb
input:
2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9760kb
input:
5 1
output:
44
result:
ok 1 number(s): "44"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9892kb
input:
167 91
output:
284830080
result:
ok 1 number(s): "284830080"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9820kb
input:
2 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 9768kb
input:
2 3
output:
36
result:
ok 1 number(s): "36"
Test #6:
score: 0
Accepted
time: 1ms
memory: 9836kb
input:
2 4
output:
576
result:
ok 1 number(s): "576"
Test #7:
score: 0
Accepted
time: 1ms
memory: 9708kb
input:
3 1
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 1ms
memory: 9828kb
input:
3 2
output:
80
result:
ok 1 number(s): "80"
Test #9:
score: 0
Accepted
time: 1ms
memory: 9768kb
input:
3 3
output:
12096
result:
ok 1 number(s): "12096"
Test #10:
score: 0
Accepted
time: 1ms
memory: 9756kb
input:
3 4
output:
4783104
result:
ok 1 number(s): "4783104"
Test #11:
score: 0
Accepted
time: 1ms
memory: 9856kb
input:
4 1
output:
9
result:
ok 1 number(s): "9"
Test #12:
score: 0
Accepted
time: 1ms
memory: 9884kb
input:
4 2
output:
4752
result:
ok 1 number(s): "4752"
Test #13:
score: 0
Accepted
time: 1ms
memory: 9884kb
input:
4 3
output:
17927568
result:
ok 1 number(s): "17927568"
Test #14:
score: 0
Accepted
time: 1ms
memory: 9820kb
input:
4 4
output:
776703752
result:
ok 1 number(s): "776703752"
Test #15:
score: 0
Accepted
time: 1ms
memory: 9764kb
input:
5 2
output:
440192
result:
ok 1 number(s): "440192"
Test #16:
score: 0
Accepted
time: 1ms
memory: 9820kb
input:
5 3
output:
189125068
result:
ok 1 number(s): "189125068"
Test #17:
score: 0
Accepted
time: 1ms
memory: 9840kb
input:
5 4
output:
975434093
result:
ok 1 number(s): "975434093"
Test #18:
score: 0
Accepted
time: 168ms
memory: 23876kb
input:
1000 1000
output:
720037464
result:
ok 1 number(s): "720037464"
Test #19:
score: 0
Accepted
time: 2ms
memory: 9856kb
input:
72 42
output:
638177567
result:
ok 1 number(s): "638177567"
Test #20:
score: 0
Accepted
time: 0ms
memory: 9840kb
input:
15 19
output:
663050288
result:
ok 1 number(s): "663050288"
Test #21:
score: 0
Accepted
time: 2ms
memory: 9884kb
input:
68 89
output:
94365047
result:
ok 1 number(s): "94365047"
Test #22:
score: 0
Accepted
time: 2ms
memory: 18032kb
input:
92 37
output:
652605307
result:
ok 1 number(s): "652605307"
Test #23:
score: 0
Accepted
time: 0ms
memory: 9832kb
input:
61 87
output:
498277867
result:
ok 1 number(s): "498277867"
Test #24:
score: 0
Accepted
time: 1ms
memory: 9852kb
input:
81 40
output:
133095344
result:
ok 1 number(s): "133095344"
Test #25:
score: 0
Accepted
time: 1ms
memory: 9764kb
input:
7 91
output:
524164813
result:
ok 1 number(s): "524164813"
Test #26:
score: 0
Accepted
time: 1ms
memory: 9828kb
input:
31 18
output:
361233485
result:
ok 1 number(s): "361233485"
Test #27:
score: 0
Accepted
time: 1ms
memory: 9820kb
input:
74 54
output:
500686087
result:
ok 1 number(s): "500686087"
Test #28:
score: 0
Accepted
time: 1ms
memory: 9764kb
input:
32 2
output:
586504335
result:
ok 1 number(s): "586504335"
Test #29:
score: 0
Accepted
time: 51ms
memory: 21376kb
input:
656 718
output:
346764298
result:
ok 1 number(s): "346764298"
Test #30:
score: 0
Accepted
time: 29ms
memory: 11872kb
input:
254 689
output:
358078813
result:
ok 1 number(s): "358078813"
Test #31:
score: 0
Accepted
time: 59ms
memory: 18112kb
input:
713 674
output:
914437613
result:
ok 1 number(s): "914437613"
Test #32:
score: 0
Accepted
time: 10ms
memory: 10780kb
input:
136 698
output:
56687290
result:
ok 1 number(s): "56687290"
Test #33:
score: 0
Accepted
time: 30ms
memory: 19192kb
input:
369 401
output:
312325811
result:
ok 1 number(s): "312325811"
Test #34:
score: 0
Accepted
time: 8ms
memory: 10336kb
input:
280 204
output:
280012063
result:
ok 1 number(s): "280012063"
Test #35:
score: 0
Accepted
time: 26ms
memory: 11928kb
input:
904 225
output:
162909174
result:
ok 1 number(s): "162909174"
Test #36:
score: 0
Accepted
time: 179ms
memory: 23980kb
input:
855 928
output:
39885159
result:
ok 1 number(s): "39885159"
Test #37:
score: 0
Accepted
time: 23ms
memory: 17168kb
input:
503 365
output:
745115888
result:
ok 1 number(s): "745115888"
Test #38:
score: 0
Accepted
time: 172ms
memory: 23924kb
input:
646 996
output:
610925577
result:
ok 1 number(s): "610925577"
Test #39:
score: 0
Accepted
time: 182ms
memory: 23980kb
input:
990 918
output:
203469632
result:
ok 1 number(s): "203469632"
Test #40:
score: 0
Accepted
time: 168ms
memory: 23952kb
input:
961 949
output:
169566857
result:
ok 1 number(s): "169566857"
Test #41:
score: 0
Accepted
time: 166ms
memory: 24024kb
input:
946 932
output:
352423195
result:
ok 1 number(s): "352423195"
Test #42:
score: 0
Accepted
time: 173ms
memory: 23904kb
input:
903 981
output:
196309824
result:
ok 1 number(s): "196309824"
Test #43:
score: 0
Accepted
time: 173ms
memory: 23980kb
input:
916 988
output:
487208972
result:
ok 1 number(s): "487208972"
Test #44:
score: 0
Accepted
time: 166ms
memory: 23964kb
input:
982 982
output:
387421488
result:
ok 1 number(s): "387421488"
Test #45:
score: 0
Accepted
time: 178ms
memory: 23960kb
input:
955 911
output:
955637031
result:
ok 1 number(s): "955637031"
Test #46:
score: 0
Accepted
time: 179ms
memory: 24016kb
input:
906 999
output:
798469943
result:
ok 1 number(s): "798469943"
Test #47:
score: 0
Accepted
time: 166ms
memory: 23980kb
input:
982 975
output:
193506289
result:
ok 1 number(s): "193506289"
Test #48:
score: 0
Accepted
time: 173ms
memory: 23976kb
input:
921 991
output:
431202149
result:
ok 1 number(s): "431202149"