QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#716066#8972. TournamentlyinmxWA 1003ms19988kbC++171.9kb2024-11-06 14:14:002024-11-06 14:14:01

Judging History

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

  • [2024-11-06 14:14:01]
  • 评测
  • 测评结果:WA
  • 用时:1003ms
  • 内存:19988kb
  • [2024-11-06 14:14:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db;

#define int ll

const int N = 3e5 + 10;

mt19937 mt( (ull)( &N ) );
int Rand ( int l, int r ) { return uniform_int_distribution<int>(l,r)(mt); }

int n, k, m, A[N], S[N]; pair<int,int> F[N];

int Sum ( int l, int r  ) { return S[r] - S[l-1]; }

int Val ( int l, int r )
{
    int mid = l + ( r - l >> 1 );
    if( ( r - l + 1 ) & 1 ) return Sum( mid + 1, r ) - Sum( l, mid - 1 );
    else                    return Sum( mid + 1, r ) - Sum( l, mid     );
}

pair<int,int> Cost ( int p, int i ) {
    return make_pair(  F[p].first + Val( p + 1, i ) - m, F[p].second + 1 );
}

pair<int,int> Check ( int mid )
{
    m = mid;

    static struct Ver { int p, l, r; } V[N];

    int head = 1, tail =  0;
    V[++tail] = { 0, 1, n };
    for( int i = 1; i <= n; ++i )
    {
        while( head < tail && V[head].r < i ) ++head; V[head].l = i;
        F[i] = Cost( V[head].p,  i );
        while( head < tail && Cost( i, V[tail].l ) < Cost( V[tail].p, V[tail].l ) ) --tail;

        int l = V[tail].l, r = V[tail].r + 1;
        while( r - l > 1 )
        {
            int mid = l + r >> 1;
            if( Cost( i, mid ) < Cost( V[tail].p, mid ) ) r = mid; else l = mid;
        }
        if( r <= n ) V[tail].r = r - 1, V[++tail] = { i, r, n };
    }
    return F[n];
}

void Solve ()
{
    cin >> n >> k;
    for( int i = 1; i <= n; ++i ) cin >> A[i], S[i] = S[i-1] + A[i];

    int l = - (ll)INT_MAX * 2000, r = 0, res = 0;
    while( r - l > 1 )
    {
        int mid = l + ( r - l >> 1 );
        if( Check( mid ).second <= k ) l = mid, res = mid; else r = mid;
    }
    pair<int,int> ans = Check( res );
    cout << ans.first + k * res << "\n";
}

signed main() 
{
    ios::sync_with_stdio( false ), cin.tie(0), cout.tie(0); Solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7744kb

input:

5 2
0 4 7 9 10

output:

7

result:

ok single line: '7'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7672kb

input:

9 3
0 1 10 11 20 21 22 30 32

output:

23

result:

ok single line: '23'

Test #3:

score: 0
Accepted
time: 0ms
memory: 7708kb

input:

100 22
0 4720 5107 5132 5699 13241 14762 16597 19296 19911 21425 40971 44851 45434 52537 54791 54935 54964 55002 56298 58373 59652 60883 67849 69458 70038 77690 78927 81409 84826 92438 92967 94567 97884 109020 109761 117376 120199 120865 121089 121832 123424 125733 130851 131080 131323 135726 140037...

output:

199291

result:

ok single line: '199291'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7744kb

input:

299 1
0 145 674 745 751 1343 1503 1948 2064 2149 2181 2289 2376 2507 2754 2983 3005 3299 3436 3730 4058 4068 4093 4313 4522 4531 4857 5158 5412 5750 5790 6142 6285 6335 6375 6544 6972 7168 7274 7384 7412 7768 7829 8102 8223 8608 8640 8875 8886 9239 9704 9708 10236 10291 10629 10696 10725 10792 10978...

output:

129632275

result:

ok single line: '129632275'

Test #5:

score: 0
Accepted
time: 0ms
memory: 7812kb

input:

997 28
0 86929 86971 87032 87326 87393 87463 87522 87673 87684 87772 87938 87982 88257 88640 88709 88773 88842 89017 89097 89190 89308 89410 89820 90022 90311 90644 90703 90777 90853 91007 91142 91166 91346 91461 91569 91577 91917 92031 92525 93168 93433 93464 93938 94239 94267 94568 94592 95653 964...

output:

2105627

result:

ok single line: '2105627'

Test #6:

score: 0
Accepted
time: 9ms
memory: 7788kb

input:

3000 54
0 1447 6254 9705 12369 13400 13582 14358 15782 21801 23584 25887 27547 28443 33228 33769 37172 37579 46275 47693 49104 50050 54807 55990 60974 61181 69406 70648 71445 78411 79772 85335 89894 92777 94846 96485 97177 97542 107630 108180 114286 117679 124117 131373 142728 147706 150112 158586 1...

output:

116366557

result:

ok single line: '116366557'

Test #7:

score: 0
Accepted
time: 30ms
memory: 7948kb

input:

9979 87
0 277042 277440 277744 277960 278359 278413 278450 279362 279597 279638 279762 279810 279989 280059 280371 280686 280840 280874 280956 280980 281116 281134 281137 281511 283070 283112 283558 283804 284179 284315 284412 284795 284932 284977 285009 285561 285568 285667 285842 286178 286205 286...

output:

70681163

result:

ok single line: '70681163'

Test #8:

score: 0
Accepted
time: 115ms
memory: 8420kb

input:

29999 1
0 1625 7063 14960 17577 18583 22159 22161 25893 27407 32379 32624 36118 38632 47112 50668 51407 54234 56020 56972 67690 68916 74573 74773 75662 76009 76911 78612 78780 80755 81988 86281 88453 91474 94528 97073 104675 104715 105100 106947 108551 114255 114845 115146 116457 117434 119722 12012...

output:

677130701281

result:

ok single line: '677130701281'

Test #9:

score: 0
Accepted
time: 302ms
memory: 13168kb

input:

99982 71228
0 1124 6095 8322 9122 9885 9917 10855 15082 16902 31578 31710 34672 36069 37036 42089 48288 57723 58639 62428 65325 70433 72797 74102 74702 76757 76980 78351 79244 84635 90812 94283 95321 95601 106998 117236 118908 121457 123724 124255 125378 125891 126214 134112 134827 136513 140218 143...

output:

14300156

result:

ok single line: '14300156'

Test #10:

score: 0
Accepted
time: 902ms
memory: 16400kb

input:

299945 57761
0 2193 7496 10008 13141 13176 15480 17342 21391 26317 27549 34308 35394 36350 42547 42576 46948 53264 55440 57966 59062 60635 68936 69244 72231 72887 73476 73608 76101 81781 82039 84108 90913 99863 100371 104678 106552 109170 110335 110929 113825 115364 118982 120717 125812 128320 12866...

output:

771648663

result:

ok single line: '771648663'

Test #11:

score: 0
Accepted
time: 892ms
memory: 15904kb

input:

299950 71010
0 3400 3435 4585 5263 16163 19868 21101 22890 28374 33932 37343 38126 41181 41912 42100 46900 47858 56455 57479 60100 64469 65914 68865 72175 76578 77568 88269 91344 91816 96213 102964 105389 105720 119929 121125 126085 130151 131261 134331 134403 136612 136936 138974 144733 146404 1467...

output:

580647052

result:

ok single line: '580647052'

Test #12:

score: 0
Accepted
time: 904ms
memory: 18896kb

input:

299949 146735
0 161 4169 4599 14567 16009 16638 18098 22394 28860 32487 33521 36381 37165 37848 40514 47429 49001 49153 51723 55106 55996 56471 63263 64559 69496 74097 76865 80101 83418 83973 84657 86685 87054 90092 90659 91762 92084 96252 100088 101184 101226 102023 102035 102202 104683 105477 1088...

output:

162377316

result:

ok single line: '162377316'

Test #13:

score: 0
Accepted
time: 958ms
memory: 19324kb

input:

299946 222059
0 1115 1997 3594 9389 10008 11373 12864 13701 28005 29367 46766 47561 49125 51725 60135 61078 73688 80302 82791 84837 89140 90280 93890 94471 95507 100223 103376 106748 108965 112214 112827 113499 115862 116607 116616 120094 123241 125149 125505 128648 135938 141308 142592 144262 14945...

output:

34138878

result:

ok single line: '34138878'

Test #14:

score: 0
Accepted
time: 1003ms
memory: 19852kb

input:

299942 280807
0 550 632 2948 7024 9204 10619 11172 16293 18503 22045 26172 30644 34130 38414 41088 41295 43423 46089 53230 56222 59163 61565 61713 66143 66607 72931 77184 77198 78825 81203 86237 88794 90039 90194 90952 93720 101084 111137 113778 114521 119120 120034 121826 129003 129745 140492 14215...

output:

1886201

result:

ok single line: '1886201'

Test #15:

score: -100
Wrong Answer
time: 909ms
memory: 19988kb

input:

299953 1
0 4059 4821 9187 11645 17109 19452 19601 22834 23125 24468 25128 26439 28971 29394 35586 40650 41839 43929 45313 46980 50512 51144 51870 54014 54089 55948 57914 59657 67705 70894 71173 77871 78879 82632 87141 89968 90318 90730 93684 94043 97782 102640 102770 105097 108053 111317 114019 1153...

output:

0

result:

wrong answer 1st lines differ - expected: '67502518668195', found: '0'