QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#297071#5826. 错排FISHER_11 293ms10904kbC++202.1kb2024-01-03 22:18:132024-01-03 22:18:14

Judging History

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

  • [2024-01-03 22:18:14]
  • 评测
  • 测评结果:11
  • 用时:293ms
  • 内存:10904kb
  • [2024-01-03 22:18:13]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int mod = 998244353;
inline int Mod(int x) { return x + ((x >> 31) & mod); }
inline int add(int x, int y) { return Mod(x + y - mod); }
inline int sub(int x, int y) { return Mod(x - y); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
int qpow(int a, int b) {
	if (!b) return 1;
	int t = qpow(a, b >> 1);
	t = mul(t, t);
	if (b & 1) return mul(t, a);
	return t;
}
const int maxT = 200000, V = 200000, B = 500;
int bl[V + 5];
struct query {
	int l, r, id;
	bool operator<(const query& b) const {
		if (bl[l] != bl[b.l]) return l < b.l;
		return bl[l] & 1 ? r > b.r : r < b.r;
	}
} q[maxT + 5];
int qc;
int D[V + 5];
int fac[V + 5], ifac[V + 5];
int inv[V + 5];
void init() {
	D[2] = 1;
	for (int i = 3; i <= V; i++) D[i] = mul(add(D[i - 1], D[i - 2]), i - 1);
	fac[0] = 1;
	for (int i = 1; i <= V; i++) fac[i] = mul(fac[i - 1], i);
	ifac[V] = qpow(fac[V], mod - 2);
	for (int i = V - 1; ~i; i--) ifac[i] = mul(ifac[i + 1], i + 1);
	for (int i = 1; i <= V; i++) inv[i] = mul(ifac[i], fac[i - 1]);
}
int ans[maxT + 5];
int main() {
	int T;
	scanf("%d", &T);
	init();
	for (int t = 1; t <= T; t++) {
		int n, m;
		scanf("%d%d", &n, &m);
		if (!m) ans[t] = D[n];
		else if (n == 2 * m) ans[t] = mul(fac[m], fac[m]);
		else if (n > 2 * m) {
			ans[t] = mul(fac[n - m], ifac[n - 2 * m]);
			q[++qc] = {n - 2 * m, m, t};
		}
	}
	for (int i = 0; i <= V; i++) bl[i] = i / B;
	sort(q + 1, q + qc + 1);
	int x = 1, y = 1, v1 = 1, v2 = 3;
	for (int i = 1; i <= qc; i++) {
		while (q[i].l < x) {
			v2 = mul(sub(v2, mul(v1, x + y + 1)), inv[x]);
			swap(v1, v2);
			x--;
		}
		while (y < q[i].r) {
			int t = add(v1, v2);
			v2 = add(mul(v1, x + 1), mul(v2, x + y + 2)), v1 = t;
			y++;
		}
		while (x < q[i].l) {
			v1 = add(mul(v1, x + 1), mul(v2, x + y + 1));
			swap(v1, v2);
			x++;
		}
		while (q[i].r < y) {
			int t = mul(sub(v2, mul(v1, x + 1)), inv[y]);
			v1 = sub(v1, t), v2 = t;
			y--;
		}
		ans[q[i].id] = mul(ans[q[i].id], v1);
	}
	for (int t = 1; t <= T; t++) printf("%d\n", ans[t]);
} 

詳細信息

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 4ms
memory: 9680kb

input:

0

output:


result:

ok 0 number(s): ""

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 2ms
memory: 9180kb

input:

10
8 6
5 1
4 2
6 3
8 1
3 1
6 2
3 1
4 1
6 2

output:

0
44
4
36
14833
435339137
299464432
435339137
440895439
299464432

result:

wrong answer 6th numbers differ - expected: '2', found: '435339137'

Subtask #3:

score: 10
Accepted

Test #7:

score: 10
Accepted
time: 27ms
memory: 10420kb

input:

200000
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0
25 0
26 0
27 0
28 0
29 0
30 0
31 0
32 0
33 0
34 0
35 0
36 0
37 0
38 0
39 0
40 0
41 0
42 0
43 0
44 0
45 0
46 0
47 0
48 0
49 0
50 0
51 0
52 0
53 0
54 0
55 0
56 0
57 0
58 0
59 0
60 0
61...

output:

0
1
2
9
44
265
1854
14833
133496
1334961
14684570
176214841
294304226
127281753
910981941
600290115
222488424
11814221
224470198
496426549
442513998
751108780
305347938
340640042
530046225
804025262
745550660
910531421
451058030
554564312
221339670
95158970
145512950
954462889
464137465
737039093
31...

result:

ok 200000 numbers

Subtask #4:

score: 0
Wrong Answer

Test #8:

score: 0
Wrong Answer
time: 293ms
memory: 10904kb

input:

200000
4303 1473
1276 72
967 234
3619 984
1316 384
2679 50
4426 1744
3782 1179
4919 4
805 63
3933 158
1574 528
1277 435
3826 915
2739 68
2286 349
3017 527
3036 476
4280 1764
1504 686
4584 917
1379 145
4764 2178
1881 45
4808 1565
3663 165
4730 2209
2258 103
4181 1687
1636 770
4339 1173
2355 777
3201 ...

output:

233893266
629644311
378835757
180607579
588056684
519394026
902816290
492721354
304889586
350582110
800908179
359450980
936515107
599514090
763780200
363041563
167326143
799275448
628805183
52464030
418421336
138771065
445767531
150318850
28019420
426063570
752901313
489020863
375626928
141723204
83...

result:

wrong answer 1st numbers differ - expected: '855518783', found: '233893266'

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%