QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#388434#1218. 冒泡排序Xun_xiaoyao100 ✓65ms16148kbC++141.1kb2024-04-13 15:39:052024-04-13 15:39:05

Judging History

This is the latest submission verdict.

  • [2024-04-13 15:39:05]
  • Judged
  • Verdict: 100
  • Time: 65ms
  • Memory: 16148kb
  • [2024-04-13 15:39:05]
  • Submitted

answer

#include <bits/stdc++.h>
#define Mod 998244353
using namespace std;
int Qread()
{
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	return x;
}
int qpow(int a,int p)
{
	int ret=1;
	for(;p;p>>=1,a=1ll*a*a%Mod)
		if(p&1) ret=1ll*ret*a%Mod;
	return ret;
}
int fac[1200010],inv[1200010],n;
int C(int n,int m){return (m<0||m>n)?0:1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;}
int chk(int a){return a<0?a+Mod:a;}
void add(int &a,int b){a+=b;if(a>=Mod) a-=Mod;}
int f(int i,int j){return (i>j||j>n)?0:chk(C(2*n-i-j-1,n-i-1)-C(2*n-i-j-1,n-j-2));}
int q[600010],mx,mn,ans;
bool vis[600010];
void solve()
{
	ans=0;
	n=Qread();mx=0,mn=1;
	memset(vis+1,0,n);
	for(int i=1;i<=n;i++)
		q[i]=Qread();
	for(int i=1;i<=n;i++)
	{
		add(ans,f(i-1,max(mx,q[i])+1));
		if(mx>q[i]&&q[i]>mn) break;
		mx=max(mx,q[i]);
		vis[q[i]]=true;
		while(vis[mn]) mn++;
	}
	printf("%d\n",ans);
}
int main()
{
	fac[0]=inv[0]=1;
	for(int i=1;i<=1200000;i++) fac[i]=1ll*fac[i-1]*i%Mod;
	inv[1200000]=qpow(fac[1200000],Mod-2);
	for(int i=1199999;i;i--) inv[i]=1ll*inv[i+1]*(i+1)%Mod;
	int T=Qread();
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4
Accepted
time: 9ms
memory: 13612kb

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: 14ms
memory: 14424kb

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

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

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: 10ms
memory: 14812kb

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

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: 14ms
memory: 13684kb

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: 10ms
memory: 13956kb

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: 10ms
memory: 14776kb

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: 13ms
memory: 13992kb

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: 14ms
memory: 13808kb

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: 13ms
memory: 13852kb

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

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: 10ms
memory: 14416kb

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: 14ms
memory: 15084kb

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

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

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: 10ms
memory: 14284kb

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

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: 10ms
memory: 13376kb

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: 39ms
memory: 15180kb

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: 55ms
memory: 15548kb

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: 59ms
memory: 16048kb

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: 65ms
memory: 16032kb

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: 62ms
memory: 16148kb

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