QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#715953#8972. TournamentlyinmxWA 69ms10392kbC++171.9kb2024-11-06 13:53:552024-11-06 13:53:55

Judging History

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

  • [2024-11-06 13:53:55]
  • 评测
  • 测评结果:WA
  • 用时:69ms
  • 内存:10392kb
  • [2024-11-06 13:53:55]
  • 提交

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*100, r = 2, 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 + res * ans.second << "\n";
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7648kb

input:

5 2
0 4 7 9 10

output:

7

result:

ok single line: '7'

Test #2:

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

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

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

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

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

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: -100
Wrong Answer
time: 69ms
memory: 10392kb

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:

0

result:

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