QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#94088 | #5478. Quiz Contest | whatever# | TL | 1415ms | 50516kb | C++23 | 3.4kb | 2023-04-05 11:53:02 | 2023-04-05 11:53:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 998244353, G = 3;
using poly = vector<int>;
constexpr int maxn = 1 << 18, N = maxn + 10;
int w[N], inv[N], lg[N], rev[N], invfac[N], fac[N];
int val;
inline int add(int a, int b) {return (a += b - mod), a += a >> 31 & mod;}
inline int sub(int a, int b) {return (a -= b), a += a >> 31 & mod;}
inline int fpw(int a, int b) {
int ans = 1;
for(; b; b >>= 1, a = 1ll * a * a % mod) if(b & 1) ans = 1ll * ans * a % mod;
return ans;
}
void init() {
inv[1] = 1;
for(int i = 2; i < N; i ++) lg[i] = lg[i + 1 >> 1] + 1;
for(int i = 2; i < N; i ++) inv[i] = 1ll * inv[mod % i] * (mod - mod / i) % mod;
invfac[0] = fac[0] = 1;
for(int i = 1; i < N; i ++) fac[i] = 1ll * fac[i - 1] * i % mod;
for(int i = 1; i < N; i ++) invfac[i] = 1ll * invfac[i - 1] * inv[i] % mod;
int wn = fpw(G, (mod - 1) / maxn); w[0] = 1;
for(int i = 1; i < N; i ++) w[i] = 1ll * wn * w[i - 1] % mod;
}
void dft(poly &a, int len) {
for(int i = len >> 1; i >= 1; i >>= 1) {
int s = maxn / (i << 1);
for(int j = 0; j < len; j += i << 1) {
for(int k = 0, *p = w; k < i; k ++, p += s) {
int x = a[j + k], y = a[i + j + k];
a[j + k] = add(x, y);
a[i + j + k] = 1ll * *p * sub(x, y) % mod;
}
}
}
}
void idft(poly &a, int len) {
for(int i = 1; i < len; i <<= 1) {
int s = maxn / (i << 1);
for(int j = 0; j < len; j += i << 1) {
for(int k = 0, *p = w; k < i; k ++, p += s) {
int x = a[j + k], y = 1ll * *p * a[i + j + k] % mod;
a[j + k] = add(x, y);
a[i + j + k] = sub(x, y);
}
}
}
reverse(a.begin() + 1, a.end());
for(int &x : a) x = 1ll * x * inv[len] % mod;
}
poly polymul(poly a, poly b) {
int len = a.size() + b.size() - 1, mxlen = 1 << lg[len];
a.resize(mxlen), b.resize(mxlen);
dft(a, mxlen), dft(b, mxlen);
for(int i = 0; i < mxlen; i ++) a[i] = 1ll * a[i] * b[i] % mod;
idft(a, mxlen), a.resize(len);
return a;
}
poly polymulT(poly a, poly b) {
int n = a.size(), m = b.size();
reverse(b.begin(), b.end());
int mxlen = 1 << lg[n];
a.resize(mxlen), b.resize(mxlen);
dft(a, mxlen), dft(b, mxlen);
for(int i = 0; i < mxlen; i ++) a[i] = 1ll * a[i] * b[i] % mod;
idft(a, mxlen);
poly c(n - m + 1);
for(int i = 0; i < n - m + 1; i ++) c[i] = a[i + m - 1];
return c;
}
int n, m;
int a[N], b[N];
poly sum[N << 2];
#define ls u << 1
#define rs u << 1 | 1
void dfs1(int u, int l, int r) {
if(l == r) {
sum[u].resize(b[l]);
for(int i = 0; i < b[l]; i ++) {
sum[u][i] = 1ll * invfac[i] * invfac[a[l] - i] % mod;
}
return ;
}
int mid = l + r >> 1;
dfs1(ls, l, mid), dfs1(rs, mid + 1, r);
sum[u] = polymul(sum[ls], sum[rs]);
}
void dfs2(int u, int l, int r, poly f) {
if(l == r) {
cout << 1ll * val * f[b[l] - 1] % mod * invfac[b[l] - 1] % mod * invfac[a[l] - b[l]] % mod << '\n';
} else {
int mid = l + r >> 1;
dfs2(ls, l, mid, polymulT(f, sum[rs]));
dfs2(rs, mid + 1, r, polymulT(f, sum[ls]));
}
}
#undef ls
#undef rs
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0);
init();
cin >> n >> m;
val = 1;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
val = 1ll * val * fac[a[i]] % mod;
}
for(int i = 1; i <= n; i ++) {
cin >> b[i];
}
dfs1(1, 1, n);
poly f(m);
for(int i = 0; i < m; i ++) {
f[i] = 1ll * fac[i] * fac[m - i - 1] % mod;
}
dfs2(1, 1, n, f);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 16ms
memory: 33192kb
input:
2 4 2 2 1 2
output:
20 4
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 8ms
memory: 33096kb
input:
4 6 1 1 2 2 1 1 1 2
output:
168 168 336 48
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 6ms
memory: 33124kb
input:
4 82 20 22 12 28 20 22 7 8
output:
746371221 528486621 148054814 913602744
result:
ok 4 lines
Test #4:
score: 0
Accepted
time: 12ms
memory: 33176kb
input:
2 2 1 1 1 1
output:
1 1
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 7ms
memory: 33180kb
input:
1 1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 11ms
memory: 33188kb
input:
1 2 2 1
output:
2
result:
ok single line: '2'
Test #7:
score: 0
Accepted
time: 4ms
memory: 33184kb
input:
2 5 2 3 2 1
output:
12 108
result:
ok 2 lines
Test #8:
score: 0
Accepted
time: 10ms
memory: 33076kb
input:
3 6 3 1 2 3 1 2
output:
108 420 192
result:
ok 3 lines
Test #9:
score: 0
Accepted
time: 17ms
memory: 33196kb
input:
10 181 21 11 1 38 33 31 2 25 17 2 13 9 1 37 26 16 2 4 13 2
output:
933670175 947389273 127286706 932736158 827765819 807282126 45553639 228256557 350039760 45553639
result:
ok 10 lines
Test #10:
score: 0
Accepted
time: 8ms
memory: 33124kb
input:
9 141 47 11 1 53 2 3 1 1 22 30 1 1 40 1 2 1 1 4
output:
959854830 649008360 59000760 9143465 118001520 42136705 59000760 59000760 221770152
result:
ok 9 lines
Test #11:
score: 0
Accepted
time: 7ms
memory: 33100kb
input:
6 167 40 2 1 54 43 27 31 2 1 14 37 18
output:
21684914 968181716 594826171 452099065 231748717 716046725
result:
ok 6 lines
Test #12:
score: 0
Accepted
time: 7ms
memory: 33164kb
input:
18 166 5 1 14 6 12 12 1 5 12 9 1 16 12 7 13 17 5 18 5 1 2 5 1 2 1 1 8 9 1 14 9 1 13 9 5 17
output:
424073779 982729592 570450467 984062217 812067221 258146602 982729592 920670548 515287508 879372936 982729592 802466756 124165180 889641026 888797216 227029638 424073779 310377834
result:
ok 18 lines
Test #13:
score: 0
Accepted
time: 13ms
memory: 33188kb
input:
8 152 50 16 54 13 1 6 11 1 19 4 24 13 1 2 2 1
output:
877632556 241460682 91908033 969346444 96488448 124488250 658149142 96488448
result:
ok 8 lines
Test #14:
score: 0
Accepted
time: 479ms
memory: 36756kb
input:
146 32696 368 65 173 10 276 370 47 358 412 456 4 78 196 420 311 52 268 30 299 442 350 381 129 256 165 368 178 23 374 197 375 16 85 292 243 252 119 365 229 139 149 4 6 131 357 160 73 457 314 157 47 240 451 103 72 216 225 2 348 75 122 120 215 431 324 390 290 201 152 397 41 456 160 59 95 222 427 366 12...
output:
467990629 463000266 943072509 432089030 49032918 611725131 153142050 344818177 77750674 577573890 168930682 784177123 289251676 359922539 792694167 6087427 525005617 82895478 85438974 681066466 186956527 334880899 244523308 287659908 691939081 470665184 582502913 222544676 12306392 202576806 6796758...
result:
ok 146 lines
Test #15:
score: 0
Accepted
time: 204ms
memory: 42140kb
input:
12 135502 445 7 74 7828 3973 88981 2 3 34020 6 14 149 296 1 44 2077 1410 58906 2 2 20274 5 8 97
output:
247771824 547131421 646713541 586476213 655944584 292156217 450970619 631309320 381265997 891057017 213293851 155903656
result:
ok 12 lines
Test #16:
score: 0
Accepted
time: 713ms
memory: 49236kb
input:
34 191157 12849 385 7417 5645 3650 14937 5263 14239 6748 8 5559 7584 6916 7862 10048 7 4440 12669 14879 6 1578 1 11033 64 1013 832 4689 14222 85 55 9369 4830 2220 55 4207 162 5105 4482 3092 12838 4290 1343 1237 8 538 3464 4374 1541 6650 3 2080 10969 5545 2 954 1 5674 32 224 35 4297 12964 23 46 1233 ...
output:
255119209 521376107 197752736 442383424 832357744 455431749 949816103 213054433 580939700 62100482 889645036 129669655 386246248 79884619 472922214 913181203 438817794 983088203 944477001 334844558 742360339 456376198 73581656 572167147 590992793 24664993 595551147 589468590 415150968 757752443 5798...
result:
ok 34 lines
Test #17:
score: 0
Accepted
time: 1415ms
memory: 50516kb
input:
70 182517 2435 152 2917 21 5364 4056 4106 5062 2452 4938 1581 5477 1575 5258 422 5017 1811 1668 44 5138 4822 1548 1555 1471 1001 3030 2262 3634 2448 2756 5574 3013 73 403 1760 23 2761 5568 958 816 3233 529 1771 290 1668 3227 2 3198 3489 5689 733 354 5524 5196 413 1298 1691 887 5305 1514 3315 2556 55...
output:
713670549 493984929 786459236 608057522 777911712 678950818 645324064 464695978 588897470 704643687 1308082 951095374 545178848 759655092 867183769 314404297 655634891 311057797 687724076 165666906 408580851 249765524 147179956 908049799 624378594 724558870 249141772 899676450 694659492 215347473 90...
result:
ok 70 lines
Test #18:
score: 0
Accepted
time: 109ms
memory: 37128kb
input:
15 55966 18 15004 226 815 2 19930 8 11437 1 144 11 722 7050 346 252 8 4263 219 763 1 15689 2 1379 1 96 9 595 5354 195 24
output:
791239607 202491784 333152928 35656281 54347292 560275242 570958010 418598684 27173646 343462640 566313512 813564902 257035400 163734689 302743685
result:
ok 15 lines
Test #19:
score: -100
Time Limit Exceeded
input:
22255 200000 11 17 12 16 15 16 7 8 14 1 14 2 4 9 4 10 8 2 12 11 4 3 7 11 17 3 6 11 6 1 8 15 10 4 12 10 4 15 4 1 13 17 11 8 17 6 13 17 13 8 11 6 8 6 14 6 9 10 5 6 13 17 1 12 9 9 10 5 6 9 13 5 15 13 9 7 5 15 13 15 4 14 7 15 13 15 8 12 2 8 15 7 3 5 2 1 12 10 10 5 3 10 13 7 3 15 10 10 14 12 17 11 2 11 7...