QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210822#5478. Quiz ContestGalexTL 2657ms66896kbC++143.4kb2023-10-11 20:27:562023-10-11 20:27:56

Judging History

你现在查看的是最新测评结果

  • [2023-10-11 20:27:56]
  • 评测
  • 测评结果:TL
  • 用时:2657ms
  • 内存:66896kb
  • [2023-10-11 20:27:56]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;

int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9')
		s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return s * f;
}

const int mod = 998244353;

int qpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod, b >>= 1;
	}
	return res;
}

#define poly vector<int>

namespace Poly {
	const int g = 3, invg = 332748118;
	vector<int> rev;
	void NTT(vector<int> &a, int tp) {
		int n = a.size();
		for (int i = 0; i < n; i++)
			if (i < rev[i])
				swap(a[i], a[rev[i]]);
		for (int j = 2; j <= n; j <<= 1) {
			int ur = qpow(tp == 1 ? g : invg, (mod - 1) / j);
			for (int i = 0; i < n; i += j)
				for (int k = 0, w = 1; k < (j >> 1); k++, w = w * ur % mod) {
					int x = a[i + k], y = a[i + k + (j >> 1)];
					a[i + k] = (x + w * y) % mod, a[i + k + (j >> 1)] = (x - w * y % mod + mod) % mod;
				}
		}
		if (tp == -1) {
			int invn = qpow(n, mod - 2);
			for (int i = 0; i < n; i++)
				a[i] = a[i] * invn % mod;
		}
	}
	void init(vector<int> &a, vector<int> &b) {
		int n = a.size(), m = b.size(), N = 1, pw = 0;
		while (N < n + m)
			N <<= 1, pw++;
		a.resize(N), b.resize(N), rev.resize(N);
		for (int i = 0; i < N; i++)
			rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (pw - 1));
	}
	vector<int> mul(vector<int> a, vector<int> b) {
		int n = a.size(), m = b.size();
		init(a, b), NTT(a, 1), NTT(b, 1);
		int len = a.size();
		for (int i = 0; i < len; i++)
			a[i] = a[i] * b[i] % mod;
		NTT(a, -1), a.resize(n + m - 1);
		return a;
	}
	vector<int> minusmul(vector<int> a, vector<int> b) {
		int n = a.size(), m = b.size();
		reverse(b.begin(), b.end());
		a = mul(a, b);
		for (int i = 0; i < n; i++)
			a[i] = a[i + m - 1];
		a.resize(n);
		return a;
	}
}

#define N 200005

int n, m;
int a[N], b[N];

int fac[N], inv[N];

void init(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = fac[i - 1] * i % mod;
	inv[n] = qpow(fac[n], mod - 2);
	for (int i = n; i; i--)
		inv[i - 1] = inv[i] * i % mod; 
}

int ans[N];

#define ls (p << 1)
#define rs (p << 1 | 1)
#define mid ((l + r) >> 1)

poly f[N], g[N << 2];

void init(int l, int r, int p) {
	if (l == r) {
		g[p] = f[l];
		return ;
	}
	init(l, mid, ls), init(mid + 1, r, rs);
	g[p] = Poly::mul(g[ls], g[rs]);
}

poly calc(poly x, poly y) {
	poly res = Poly::minusmul(x, y);
	res.resize((int)x.size() - (int)y.size() + 1);
	return res;
}

void solve(int l, int r, int p, poly sum) {
	if (l == r) {
		ans[l] = sum[b[l]] * inv[b[l] - 1] % mod * inv[a[l] - b[l]] % mod;
		return ;
	}
	solve(l, mid, ls, calc(sum, g[rs]));
	solve(mid + 1, r, rs, calc(sum, g[ls]));
}

signed main() {
	n = read(), m = read();
	for (int i = 1; i <= n; i++)
		a[i] = read();
	for (int i = 1; i <= n; i++)
		b[i] = read();
	init(200000);
	for (int i = 1; i <= n; i++) {
		f[i].resize(b[i]);
		for (int j = 0; j < b[i]; j++)
			f[i][j] = inv[j] * inv[a[i] - j] % mod;
	}
	init(1, n, 1);
	poly st(m - n + 2);
	for (int i = 1; i <= m - n + 1; i++)
		st[i] = fac[i - 1] * fac[m - i] % mod;
	solve(1, n, 1, st);
	int val = 1;
	for (int i = 1; i <= n; i++)
		val = val * fac[a[i]] % mod;
	for (int i = 1; i <= n; i++)
		printf("%lld\n", ans[i] * val % mod);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 33696kb

input:

2 4
2 2
1 2

output:

20
4

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 4ms
memory: 34172kb

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: 3ms
memory: 33868kb

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: 4ms
memory: 34664kb

input:

2 2
1 1
1 1

output:

1
1

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 34240kb

input:

1 1
1
1

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 34548kb

input:

1 2
2
1

output:

2

result:

ok single line: '2'

Test #7:

score: 0
Accepted
time: 7ms
memory: 34340kb

input:

2 5
2 3
2 1

output:

12
108

result:

ok 2 lines

Test #8:

score: 0
Accepted
time: 4ms
memory: 34716kb

input:

3 6
3 1 2
3 1 2

output:

108
420
192

result:

ok 3 lines

Test #9:

score: 0
Accepted
time: 0ms
memory: 33832kb

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: 4ms
memory: 33256kb

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: 0ms
memory: 33436kb

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: 9ms
memory: 33172kb

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: 4ms
memory: 34940kb

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: 880ms
memory: 40884kb

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: 403ms
memory: 55032kb

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: 1415ms
memory: 66252kb

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: 2657ms
memory: 66896kb

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: 233ms
memory: 42740kb

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...

output:


result: