답안 #932075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932075 2024-02-22T22:39:17 Z mdn2002 Candies (JOI18_candies) C++14
100 / 100
417 ms 26088 KB
/*
    Mayoeba Yabureru
*/
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>

using namespace std;

long long n , a [200005] , sum [200005][3] , l [200005] , r [200005];
set < pair < long long , pair < int , int > > > ss;

long long cost ( int l , int r )
{
    long long ans = sum [r][ r % 2 ] - sum [ l - 1 ][ r % 2 ];
    ans -= sum [ r - 1 ][ ( r - 1 ) % 2 ] - sum [l][ ( r - 1 ) % 2 ];
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;
    a [0] = a [ n + 1 ] = -1e15;
    sum [0][0] = a [0];
    for ( int i = 0 ; i <= n + 1 ; i ++ )
    {
        if ( 1 <= i && i <= n ) cin >> a [i];
        sum [i][0] = sum [ i - 1 ][0];
        sum [i][1] = sum [ i - 1 ][1];
        sum [i][ i % 2 ] += a [i];
        l [i] = r [i] = i;
        ss . insert ( { a [i] , { i , i } } );
    }

    long long num = ( n + 1 ) / 2 , sum = 0;
    for ( int i = 1 ; i <= num ; i ++ )
    {
        auto x = * -- ss . end ();
        ss . erase ( -- ss . end () );
        sum += x . first;
        int lx = x . second . first - 1 , rx = x . second . second + 1;
        //cout << ' ' << l [lx] << ' ' << lx << "   " << rx << ' ' << r [rx] << ' ' << x . second . first << ' ' << x . second . second << ' ' << x . first << ' ' << sum << endl;
        ss . erase ( ss . lower_bound ( { cost ( rx , r [rx] ) , { rx , r [rx] } } ) );
        ss . erase ( ss . lower_bound ( { cost ( l [lx] , lx ) , { l [lx] , lx } } ) );

        lx = l [lx] , rx = r [rx];
        r [lx] = rx , l [rx] = lx;
        ss . insert ( { cost ( lx , rx ) , { lx , rx } } );

        cout << sum << endl;
    }
}
/*
5
3 5 1 7 6

10
5383 5238 56 6356 64359 6235 23487 6693 3552 23443
64359
87846
111289
116672
116728
*/




# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6748 KB Output is correct
2 Correct 4 ms 7024 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
4 Correct 3 ms 6748 KB Output is correct
5 Correct 3 ms 6744 KB Output is correct
6 Correct 4 ms 6748 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 3 ms 6744 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 3 ms 6756 KB Output is correct
12 Correct 4 ms 6788 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 3 ms 7000 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 3 ms 6768 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 3 ms 6784 KB Output is correct
20 Correct 3 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6748 KB Output is correct
2 Correct 4 ms 7024 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
4 Correct 3 ms 6748 KB Output is correct
5 Correct 3 ms 6744 KB Output is correct
6 Correct 4 ms 6748 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 3 ms 6744 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 3 ms 6756 KB Output is correct
12 Correct 4 ms 6788 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 3 ms 7000 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 3 ms 6768 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 3 ms 6784 KB Output is correct
20 Correct 3 ms 6748 KB Output is correct
21 Correct 374 ms 25692 KB Output is correct
22 Correct 368 ms 25684 KB Output is correct
23 Correct 382 ms 25596 KB Output is correct
24 Correct 213 ms 25552 KB Output is correct
25 Correct 225 ms 25580 KB Output is correct
26 Correct 223 ms 25428 KB Output is correct
27 Correct 299 ms 25640 KB Output is correct
28 Correct 228 ms 25680 KB Output is correct
29 Correct 230 ms 25640 KB Output is correct
30 Correct 257 ms 25812 KB Output is correct
31 Correct 233 ms 25680 KB Output is correct
32 Correct 237 ms 25684 KB Output is correct
33 Correct 330 ms 25508 KB Output is correct
34 Correct 297 ms 25500 KB Output is correct
35 Correct 290 ms 25548 KB Output is correct
36 Correct 360 ms 26088 KB Output is correct
37 Correct 346 ms 25680 KB Output is correct
38 Correct 417 ms 25588 KB Output is correct
39 Correct 218 ms 25388 KB Output is correct
40 Correct 214 ms 25376 KB Output is correct
41 Correct 226 ms 25424 KB Output is correct
42 Correct 228 ms 25608 KB Output is correct
43 Correct 261 ms 25708 KB Output is correct
44 Correct 231 ms 25684 KB Output is correct
45 Correct 235 ms 25616 KB Output is correct
46 Correct 232 ms 25668 KB Output is correct
47 Correct 231 ms 25676 KB Output is correct
48 Correct 293 ms 25504 KB Output is correct
49 Correct 298 ms 25424 KB Output is correct
50 Correct 320 ms 25740 KB Output is correct