QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#390149#1218. 冒泡排序zhaohaikun100 ✓177ms149644kbC++231.8kb2024-04-15 08:51:072024-04-15 08:51:08

Judging History

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

  • [2024-04-15 08:51:08]
  • 评测
  • 测评结果:100
  • 用时:177ms
  • 内存:149644kb
  • [2024-04-15 08:51:07]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\033[33m[" << __LINE__ << "]\033[0m "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T &x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T &x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 1.2e7 + 10, MOD = 998244353;
inline void add(int &x, ll y) {x = (x + y) % MOD;}
int n, a[N];
int fac[N], ifac[N], inv[N];
inline void binom(int x) {
	fac[0] = ifac[0] = inv[1] = 1;
	F(i, 2, x) inv[i] = (ll) (MOD - MOD / i) * inv[MOD % i] % MOD;
	F(i, 1, x) fac[i] = (ll) fac[i - 1] * i % MOD, ifac[i] = (ll) ifac[i - 1] * inv[i] % MOD;
}
inline int C(int x, int y) {return x < y || y < 0 ? 0 : (ll) fac[x] * ifac[y] % MOD * ifac[x - y] % MOD;}
bool vis[N];
int path(int a, int b, int c, int d) {
	return C(c + d - a - b, c - a);
}
int calc(int x, int y) { // -> (n, n)
	return ((ll) path(x, y, n, n) - path(x, y, n + 1, n - 1) + MOD) % MOD;
}
void zhk() {
	read(n);
	F(i, 1, n) vis[i] = false;
	F(i, 1, n) read(a[i]);
	int ans = 0, mx = 0, pos = 1;
	F(i, 1, n) {
		add(ans, calc(i - 1, max(a[i], mx) + 1));
		// debug << i << " " << ans << endl;
		while (vis[pos]) pos++;
		if (a[i] < mx && a[i] != pos) break;
		if (a[i] > mx) mx = a[i];
		vis[a[i]] = true;
	}
	cout << ans << '\n';
}
signed main() {
	binom(1.2e7 + 5);
	int _ = 1;
	cin >> _;
	while (_--) zhk();
	return 0;
}
/* why?
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4
Accepted
time: 119ms
memory: 147016kb

input:

5
8
1 3 4 5 6 2 7 8
8
1 2 4 3 5 6 7 8
8
3 4 5 1 6 7 8 2
8
4 7 1 8 2 6 5 3
8
8 7 2 3 1 4 5 6

output:

1236
1387
389
112
0

result:

ok 5 lines

Test #2:

score: 4
Accepted
time: 90ms
memory: 147016kb

input:

5
9
3 4 5 6 1 2 7 8 9
9
1 2 3 4 5 6 7 8 9
9
7 1 2 3 4 5 6 8 9
9
6 1 3 8 7 9 2 5 4
9
6 3 5 7 2 4 8 9 1

output:

1398
4861
43
106
79

result:

ok 5 lines

Test #3:

score: 4
Accepted
time: 91ms
memory: 146960kb

input:

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

output:

5039
11
14271
98
10

result:

ok 5 lines

Test #4:

score: 4
Accepted
time: 107ms
memory: 147096kb

input:

5
12
3 4 5 1 6 2 10 11 7 8 9 12
12
7 8 9 1 10 11 12 2 3 4 5 6
12
2 3 8 1 10 12 4 5 6 7 9 11
12
1 10 5 9 2 4 11 7 12 3 8 6
12
5 7 2 4 3 1 6 12 8 9 10 11

output:

68231
1640
116004
149247
11543

result:

ok 5 lines

Test #5:

score: 4
Accepted
time: 126ms
memory: 144976kb

input:

5
13
3 4 1 5 2 6 10 11 7 8 9 12 13
13
6 1 7 8 9 10 11 13 2 3 4 5 12
13
5 7 9 10 11 1 2 3 4 6 8 12 13
13
10 5 9 12 4 2 11 6 1 7 3 8 13
13
3 11 7 13 9 10 1 5 12 6 2 4 8

output:

262845
28881
42938
167
177673

result:

ok 5 lines

Test #6:

score: 4
Accepted
time: 97ms
memory: 147012kb

input:

5
14
3 1 4 2 5 6 10 11 14 7 8 9 12 13
14
4 5 6 7 8 1 9 11 12 14 2 3 10 13
14
2 4 5 6 1 10 3 7 8 9 11 12 13 14
14
5 7 8 4 6 3 13 12 14 1 10 2 9 11
14
4 6 14 8 10 5 1 9 3 12 11 2 7 13

output:

1128561
446477
1435500
171086
365636

result:

ok 5 lines

Test #7:

score: 4
Accepted
time: 111ms
memory: 144968kb

input:

5
16
3 1 4 5 6 10 11 14 2 15 7 8 9 12 13 16
16
7 1 2 3 4 5 6 10 8 9 11 13 12 15 16 14
16
7 11 12 15 1 2 3 4 5 6 8 9 10 13 14 16
16
6 3 7 8 9 5 15 2 1 10 12 13 14 16 11 4
16
2 9 5 4 3 16 6 1 15 11 13 10 12 8 7 14

output:

14902704
958522
392830
1533433
16025151

result:

ok 5 lines

Test #8:

score: 4
Accepted
time: 118ms
memory: 146984kb

input:

5
16
3 1 4 5 6 10 11 14 2 15 7 8 9 12 13 16
16
7 1 2 3 4 5 6 10 8 9 11 13 12 15 16 14
16
7 11 12 15 1 2 3 4 5 6 8 9 10 13 14 16
16
6 3 7 8 9 5 15 2 1 10 12 13 14 16 11 4
16
2 9 5 4 3 16 6 1 15 11 13 10 12 8 7 14

output:

14902704
958522
392830
1533433
16025151

result:

ok 5 lines

Test #9:

score: 4
Accepted
time: 112ms
memory: 146964kb

input:

5
17
1 3 4 5 6 10 11 2 14 15 17 7 8 9 12 13 16
17
1 2 3 4 5 6 7 9 11 8 13 14 10 12 15 16 17
17
7 11 12 15 17 1 2 3 4 5 6 8 9 10 13 14 16
17
13 8 16 2 7 6 10 5 15 1 12 9 3 14 11 17 4
17
16 9 11 2 5 12 3 15 6 14 10 17 13 4 7 1 8

output:

116130815
129636761
1579560
1748
2

result:

ok 5 lines

Test #10:

score: 4
Accepted
time: 115ms
memory: 144956kb

input:

5
18
3 4 5 6 10 11 1 14 15 17 2 7 8 9 12 13 16 18
18
1 2 3 5 4 6 7 9 8 11 13 14 10 12 15 16 17 18
18
6 10 11 14 16 18 1 2 3 4 5 7 8 9 12 13 15 17
18
2 18 15 13 8 14 6 9 5 17 1 3 4 16 12 7 11 10
18
12 8 6 10 11 7 13 5 4 17 14 16 18 15 9 1 3 2

output:

168778476
474945043
14827744
218349120
43813

result:

ok 5 lines

Test #11:

score: 4
Accepted
time: 102ms
memory: 146960kb

input:

5
18
1 3 2 5 6 9 10 14 18 4 7 8 11 12 13 15 16 17
18
3 1 2 4 6 5 7 8 9 12 16 10 11 13 14 15 17 18
18
1 3 4 5 6 8 10 11 12 14 18 2 7 9 13 15 16 17
18
5 1 10 17 15 8 11 4 14 6 16 3 9 18 2 7 13 12
18
3 8 9 7 2 16 10 12 18 15 14 17 6 5 4 11 13 1

output:

438231529
217602393
428634831
49308782
126258799

result:

ok 5 lines

Test #12:

score: 4
Accepted
time: 119ms
memory: 147004kb

input:

5
122
1 3 5 6 9 10 14 18 23 25 26 28 29 2 31 4 33 34 35 36 39 43 47 48 49 55 57 59 60 61 62 64 66 67 7 68 70 8 74 75 11 78 81 83 12 85 86 87 88 90 13 94 96 97 98 99 100 15 101 104 110 111 115 116 119 16 17 19 20 21 22 24 27 30 32 37 38 40 41 42 44 45 46 50 51 52 53 54 56 58 63 65 69 71 72 73 76 77 7...

output:

35355138
175759964
419892161
27040549
12209267

result:

ok 5 lines

Test #13:

score: 4
Accepted
time: 92ms
memory: 144900kb

input:

5
144
1 3 5 6 9 10 14 18 23 25 26 28 2 29 31 4 33 34 7 35 36 39 8 43 47 48 49 55 11 57 59 60 61 62 64 12 66 67 68 70 74 75 78 81 83 85 86 87 88 13 90 94 96 97 98 99 100 15 101 104 110 111 115 116 119 123 124 125 126 16 127 17 128 129 130 131 19 132 133 135 137 139 140 141 20 21 22 24 27 30 32 37 38 ...

output:

284258776
737764392
599190106
20201051
836330738

result:

ok 5 lines

Test #14:

score: 4
Accepted
time: 112ms
memory: 147020kb

input:

5
166
2 1 3 5 6 9 4 10 14 18 23 25 26 7 28 29 31 33 34 35 36 39 43 47 48 49 55 8 57 59 60 61 62 64 66 11 67 68 70 74 75 78 81 83 85 86 87 12 88 13 90 94 96 97 15 98 99 100 101 104 110 111 16 115 116 119 123 124 125 126 127 128 129 130 131 132 133 135 137 139 140 141 145 146 150 151 152 159 161 162 1...

output:

709675111
536615365
700393894
617113170
559238079

result:

ok 5 lines

Test #15:

score: 4
Accepted
time: 101ms
memory: 144904kb

input:

5
200
1 2 3 5 6 9 10 14 18 23 25 26 28 4 29 7 31 33 34 35 8 36 39 43 47 48 49 55 11 57 59 60 61 62 64 66 67 68 70 74 75 78 81 83 85 86 87 88 90 94 96 97 98 99 100 101 104 110 111 115 116 119 123 124 125 126 127 128 129 130 131 132 133 135 137 12 139 140 13 141 145 146 150 151 152 159 161 162 164 15 ...

output:

466871660
718610841
778662713
67331810
461531510

result:

ok 5 lines

Test #16:

score: 4
Accepted
time: 99ms
memory: 147036kb

input:

5
233
1 3 5 6 9 10 14 18 23 25 26 28 29 31 33 34 35 36 39 43 47 48 49 55 57 59 60 61 62 64 66 67 68 70 74 75 78 81 83 85 86 87 2 88 90 4 94 96 97 98 99 100 101 104 110 111 7 115 116 8 119 123 124 125 126 11 127 128 12 129 13 130 131 132 15 133 135 16 137 17 139 140 141 145 146 150 151 152 159 161 19...

output:

218305798
576628922
669515847
0
0

result:

ok 5 lines

Test #17:

score: 4
Accepted
time: 116ms
memory: 147016kb

input:

5
777
1 2 3 5 6 9 10 4 14 18 23 25 26 28 29 31 33 34 35 7 36 39 43 47 48 49 55 57 59 60 61 62 64 8 66 67 11 68 70 74 75 78 81 83 85 86 12 87 88 90 94 96 97 98 99 100 101 104 110 111 13 115 116 119 15 123 16 124 125 126 127 128 129 130 131 132 133 135 137 139 140 141 145 146 17 150 151 152 159 161 16...

output:

144385204
244809397
814755904
942413462
327451724

result:

ok 5 lines

Test #18:

score: 4
Accepted
time: 106ms
memory: 146960kb

input:

5
888
1 3 5 6 9 10 14 18 23 25 2 26 28 29 31 33 34 35 36 39 43 47 48 49 55 57 4 59 60 7 61 8 62 64 11 12 66 67 13 68 70 74 75 78 81 83 85 86 87 88 90 94 96 97 98 99 100 101 104 110 111 115 116 119 123 124 125 126 127 128 129 130 131 132 133 135 137 139 140 141 145 15 146 150 151 16 152 159 161 162 1...

output:

856453359
301119113
985206552
128530630
912614516

result:

ok 5 lines

Test #19:

score: 4
Accepted
time: 120ms
memory: 147032kb

input:

5
933
1 3 5 6 9 10 14 18 23 25 26 28 29 31 33 34 35 36 39 43 47 48 49 55 57 59 60 61 62 64 66 67 68 70 74 75 2 78 81 83 4 85 86 87 88 7 90 94 96 97 98 8 99 100 11 101 104 110 111 115 116 119 123 124 125 126 127 128 129 130 12 131 132 133 135 137 139 140 141 13 145 146 150 151 152 159 161 162 164 165...

output:

68614424
623073630
445012999
310993118
371274667

result:

ok 5 lines

Test #20:

score: 4
Accepted
time: 116ms
memory: 146952kb

input:

5
1000
1 3 5 2 6 9 10 14 18 23 25 26 4 28 29 31 33 34 35 36 39 43 47 48 49 55 57 59 60 61 62 7 64 66 67 68 70 74 75 8 78 81 83 85 86 87 11 88 90 94 96 97 98 99 100 101 12 104 110 111 13 115 116 119 123 124 125 126 127 128 129 130 131 132 133 135 137 139 140 141 145 146 150 151 152 159 161 162 15 164...

output:

129998140
394133518
743284764
360811028
891200946

result:

ok 5 lines

Test #21:

score: 4
Accepted
time: 152ms
memory: 149384kb

input:

5
266666
1 3 2 5 4 6 9 10 14 18 23 25 26 28 29 31 33 34 35 36 39 43 47 48 49 55 57 59 60 61 62 64 66 67 68 70 74 75 78 81 83 85 86 7 87 88 90 94 96 97 98 99 100 101 8 104 110 111 11 115 116 119 123 124 125 126 127 128 129 130 131 132 133 135 137 139 140 141 145 146 12 13 150 151 152 159 161 162 15 1...

output:

114791526
667162396
527298953
342335619
695906871

result:

ok 5 lines

Test #22:

score: 4
Accepted
time: 145ms
memory: 147420kb

input:

5
333333
1 3 5 6 9 10 14 18 2 23 25 26 28 4 29 31 33 34 7 35 36 39 43 47 48 49 55 57 59 60 61 62 64 8 66 67 68 70 74 75 78 81 83 85 86 87 88 90 94 96 97 98 99 100 101 104 110 111 115 116 119 123 124 125 11 126 127 128 129 130 131 132 133 135 137 139 140 141 145 146 150 151 152 159 161 162 164 12 165...

output:

760431479
228475833
621539626
877046354
283330354

result:

ok 5 lines

Test #23:

score: 4
Accepted
time: 169ms
memory: 149436kb

input:

5
444444
2 1 3 5 6 9 10 4 14 18 23 25 26 28 7 29 31 33 34 35 8 36 11 39 43 47 48 49 55 57 59 60 61 62 64 66 67 68 70 74 75 78 12 81 83 85 86 87 88 90 94 13 96 97 98 99 100 15 16 101 104 110 111 115 116 119 123 124 125 126 127 128 129 130 131 132 133 135 137 139 140 141 17 145 146 150 151 152 159 161...

output:

325943715
420523077
579184968
656726730
305289823

result:

ok 5 lines

Test #24:

score: 4
Accepted
time: 175ms
memory: 147496kb

input:

5
555555
3 6 9 11 14 16 17 19 20 25 26 27 32 33 36 37 40 41 46 47 48 50 51 1 52 57 58 62 2 64 65 67 68 69 71 72 73 76 79 82 87 91 92 93 94 95 4 96 98 99 5 102 104 106 107 108 109 110 113 115 117 121 124 126 127 128 129 130 7 132 133 134 135 138 139 141 143 144 145 148 149 150 152 153 159 161 164 8 1...

output:

936010956
566799490
148032830
936844754
218458291

result:

ok 5 lines

Test #25:

score: 4
Accepted
time: 177ms
memory: 149644kb

input:

5
600000
3 6 9 11 14 16 17 1 19 20 25 26 27 32 33 36 37 40 41 46 2 4 47 48 5 50 51 52 57 58 62 64 7 65 67 68 69 71 72 73 76 79 82 87 91 92 93 94 95 8 96 98 99 102 104 106 107 108 109 110 113 115 117 121 124 126 10 12 127 128 129 130 132 13 133 134 135 138 139 141 143 144 145 148 149 150 152 15 153 1...

output:

389970330
551398245
159170051
785844594
322873802

result:

ok 5 lines

Extra Test:

score: 0
Extra Test Passed