QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#180678#1218. 冒泡排序Sorting100 ✓134ms26572kbC++202.3kb2023-09-16 08:20:112023-09-16 08:20:11

Judging History

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

  • [2023-09-16 08:20:11]
  • 评测
  • 测评结果:100
  • 用时:134ms
  • 内存:26572kb
  • [2023-09-16 08:20:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector<int> vi;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

const int MAXN = 1.2e6 + 7 ;
const int MOD = 998244353 ;

int n ;
int a[ MAXN ] ;

ll fac[ MAXN ] , inv[ MAXN ] ;

ll fastpow ( ll x , ll pw ) {
    ll ret = 1 ;
    while ( pw > 0 ) {
        if ( ( pw % 2 ) == 0 ) {
            x = ( x * x ) % MOD ;
            pw /= 2 ;
        }
        else {
            ret = ( ret * x ) % MOD ;
            -- pw ;
        }
    }
    return ret ;
}

void init ( ) {
    fac[ 0 ] = 1 ;
    for ( int i = 1 ; i < MAXN ; ++ i ) {
        fac[ i ] = ( fac[ i - 1 ] * i ) % MOD ;
    }
    inv[ MAXN - 1 ] = fastpow ( fac[ MAXN - 1 ] , MOD - 2 ) ;
    for ( int i = MAXN - 2 ; i >= 0 ; -- i ) {
        inv[ i ] = ( inv[ i + 1 ] * ( i + 1 ) ) % MOD ;
    }
}

ll comb ( int up , int down ) {
    if ( up < down || down < 0 ) { return 0 ; }
    ll ret = fac[ up ] ;
    ret = ( ret * inv[ down ] ) % MOD ;
    ret = ( ret * inv[ up - down ] ) % MOD ;
    return ret ;
}

ll calc_paths ( int ups , int moves ) {
    ll ret = comb ( moves + ups , ups ) ;
    ret = ( ret + MOD - comb ( moves + ups , ups - 1 ) ) % MOD ;
    return ret ;
}

bool used[ MAXN ] ;

void solve ( ) {
    cin >> n ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ] ;
        used[ i ] = false ;
    }
    int mx = 0 , pos = 1 ;
    ll ans = 0 ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        if ( a[ i ] > mx ) {
            mx = a[ i ] ;
            ans = ( ans + calc_paths ( n - mx - 1 , n - i + 1 ) ) % MOD ;
            used[ a[ i ] ] = true ;
        }
        else {
            ans = ( ans + calc_paths ( n - mx - 1 , n - i + 1 ) ) % MOD ;
            if ( a[ i ] != pos ) { break ; }
            used[ pos ] = true ;
        }
        while ( used[ pos ] == true ) { ++ pos ; }
    }
    cout << ans << "\n" ;
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    init ( ) ;
    int t = 1 ; cin >> t ;
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}

詳細信息

Test #1:

score: 4
Accepted
time: 14ms
memory: 22464kb

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

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

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

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

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

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

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

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

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

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

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

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

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

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: 23932kb

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

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

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

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

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

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

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

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

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

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

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