QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#207547 | #71. Cake 3 | james1BadCreeper | 0 | 2ms | 7616kb | C++14 | 1.9kb | 2023-10-08 16:50:47 | 2023-10-08 16:50:49 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 200005;
int n, m, nn;
struct Cake {
int v, c;
bool operator< (const Cake &a) const { return c < a.c; }
} a[N];
int b[N];
struct Node {
int ls, rs;
int siz; i64 sum;
} T[N * 40];
int rt[N], tot;
int update(int pre, int l, int r, int x, int v) {
int o = ++tot; T[o] = T[pre]; ++T[o].siz; T[o].sum += v;
if (l == r) return o;
int mid = l + r >> 1;
if (x <= mid) T[o].ls = update(T[pre].ls, l, mid, x, v);
else T[o].rs = update(T[pre].rs, mid + 1, r, x, v);
return o;
}
i64 query(int p, int q, int l, int r, int k) { // 值域在 [l, r] 中的 V 最大 k 个的答案
if (l == r) return 1ll * k * b[l];
int mid = l + r >> 1, res = T[T[q].rs].siz - T[T[p].rs].siz;
if (res >= k) return query(T[p].rs, T[q].rs, mid + 1, r, k);
return query(T[p].ls, T[q].ls, l, mid, k - res) + T[T[q].rs].sum - T[T[p].rs].sum;
}
i64 ans;
inline i64 calc(int l, int r) { return query(rt[l - 1], rt[r], 1, nn, m) - 2 * (a[r].c - a[l].c); }
void solve(int l, int r, int L, int R) { // 决策区间 [L, R]
if (l > r) return;
int mid = l + r >> 1, p = 0, RR = min(R, mid - m + 1);
i64 mx = -1e18;
for (int i = L; i <= RR; ++i) {
i64 w = calc(i, mid);
if (w > mx) mx = w, p = i;
} ans = max(ans, mx);
solve(l, mid - 1, L, p); solve(mid + 1, r, p, R);
}
int main(void) {
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i].v >> a[i].c, b[i] = a[i].v;
sort(b + 1, b + n + 1); sort(a + 1, a + n + 1);
nn = unique(b + 1, b + n + 1) - (b + 1);
for (int i = 1; i <= n; ++i) rt[i] = update(rt[i - 1], 1, nn, lower_bound(b + 1, b + nn + 1, a[i].v) - b, a[i].v);
solve(m, n, 1, n);
cout << ans << "\n";
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 1ms
memory: 5516kb
input:
100 32 671208774 266481733 115497791 342597239 326245300 76223942 528973483 754205900 437996819 995535247 100582194 42402057 771100621 351934207 89058009 81951602 768935397 186435060 842907845 376386254 187943947 59424920 997369107 493642356 455078419 68850493 542835555 938351581 970171972 611243076...
output:
25580474644
result:
ok single line: '25580474644'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5532kb
input:
96 26 654901552 458347153 165510759 938829925 195217130 507375330 505924632 413472221 654752848 711653336 843934470 721570198 773665886 401710037 234904469 980379861 955790468 908963841 767941919 649831102 551860594 482287589 445315312 465411688 121261567 38031091 85608696 831434175 898543690 533481...
output:
20912597347
result:
ok single line: '20912597347'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5528kb
input:
97 50 601727246 586947184 629061466 495053188 908476392 789027930 127214423 866336725 518731382 132785533 113489768 827723755 985313205 850125600 651615014 585565934 7844301 974793551 821451342 503266415 191392244 172018292 811053096 980886405 414007158 116164410 749815864 858185057 809840877 654635...
output:
35572528711
result:
ok single line: '35572528711'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5464kb
input:
95 53 149550762 262774006 70645562 988470529 951317142 587455395 640797744 881023050 152099375 109591790 42073955 240106850 787394186 32306392 690229700 154829125 612427906 799230609 529294971 846139787 399369072 840851479 258683206 624167919 933584741 989196725 928112368 809131208 742906726 7228213...
output:
38104623964
result:
ok single line: '38104623964'
Test #5:
score: 0
Accepted
time: 0ms
memory: 5420kb
input:
95 67 219655106 209971230 684228500 55963835 376681839 957451928 44063570 464399636 244459351 255445846 926539875 699539831 624720901 149661354 268068448 124041530 391618918 196971593 259894666 522352998 72651673 750483217 418558834 288939175 987660441 756241680 290013706 540390088 672554190 1595528...
output:
42726885227
result:
ok single line: '42726885227'
Test #6:
score: 0
Accepted
time: 0ms
memory: 7572kb
input:
98 83 144189007 599184430 955720138 430137031 46813950 337012077 284624496 923370172 585878255 277696686 458874123 25220195 65996741 918738892 536999214 420249860 124871436 785740035 524616035 321557657 377122912 363899088 800060966 799482628 704695498 739563311 385588901 543586072 594428502 6483895...
output:
47720376527
result:
ok single line: '47720376527'
Test #7:
score: 0
Accepted
time: 1ms
memory: 7504kb
input:
96 38 37921502 265183642 30462271 269145614 51895518 29824956 44764507 681512686 47724467 815499441 6427327 591731270 46504734 436644698 2223048 132007665 40380520 511674250 43917077 653531209 17511337 975498424 1931641 115779401 16884852 128795730 14731353 429591965 5850509 790146440 15255306 77070...
output:
399264493
result:
ok single line: '399264493'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5476kb
input:
96 25 57401007 493943697 29527957 714663679 29545307 647011203 41025179 566266756 58441740 117870293 27412280 422916085 33052858 310233747 9411800 715114198 15661682 773129023 49930623 903197292 4733526 653650922 36089642 500031319 1389486 444206729 19886177 397683562 2903725 764846753 84795 2145521...
output:
719815801
result:
ok single line: '719815801'
Test #9:
score: 0
Accepted
time: 1ms
memory: 5528kb
input:
99 21 59657805 652963568 80731103 249217474 67765017 136600735 30669693 235796790 38336275 333697289 9339946 754166690 69051138 182211402 93041255 259466527 71372493 445676674 67165121 840321934 33766102 430254036 18248715 148433501 38354832 282537749 64069877 131281615 39361263 592884334 18160924 9...
output:
888797889
result:
ok single line: '888797889'
Test #10:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
93 28 19252348 834865987 35189109 821648351 47848765 934801179 33900007 907328375 45481720 478428955 4292036 880931858 36991135 956842947 49181931 583677473 36889879 714660270 20737289 866325358 65602596 635999283 70856516 855441876 54559432 319956854 47217522 132918942 55127890 62037126 53412038 84...
output:
597761343
result:
ok single line: '597761343'
Test #11:
score: 0
Accepted
time: 0ms
memory: 5520kb
input:
92 18 17034692 311412535 75067760 700238328 85371763 32662981 90417142 594066624 34625146 420051930 46026136 298353430 71930456 679253686 94901612 553915166 10855990 339449028 10327620 444733804 51133091 802733614 95838938 276886845 22327317 53898064 29910663 881733161 74599342 280465633 8898777 221...
output:
963264484
result:
ok single line: '963264484'
Test #12:
score: 0
Accepted
time: 1ms
memory: 5416kb
input:
96 46 3613091 48226953 17333738 315657491 33499557 905024 21585984 973060800 42148202 275277748 25892629 489251559 31604703 888333915 13970358 799610574 33246317 54304803 7114447 61375639 5669373 697687696 1575366 350398758 16667098 747366614 7839377 799378407 18868553 430864652 41883674 476142622 1...
output:
217389025
result:
ok single line: '217389025'
Test #13:
score: 0
Accepted
time: 0ms
memory: 5516kb
input:
100 45 43924230 212784715 43573365 390630448 36356410 302155896 8834549 369231487 23914662 209393152 8961292 339488011 11770598 98213199 41391432 553642288 33929359 654885451 15834215 243511760 32889505 785116193 40157572 806063390 41729010 657312356 24502770 98898149 33168308 379445567 25788178 737...
output:
284124804
result:
ok single line: '284124804'
Test #14:
score: 0
Accepted
time: 1ms
memory: 5572kb
input:
94 44 18278964 59117371 1121774 674793869 44776633 866596597 3672456 43798662 18327992 258671822 26820827 436747027 10741961 269663794 4454544 235521073 2959148 111403543 17994812 431349737 44808537 631076314 1072950 366206930 37219572 987766907 33824148 367550034 18542970 307178475 1386716 33940913...
output:
308368925
result:
ok single line: '308368925'
Test #15:
score: 0
Accepted
time: 2ms
memory: 7616kb
input:
96 41 36332583 8569405 20284590 704164692 26169208 400229170 32850340 485895095 44691003 149746532 5684161 537586304 3545889 108210000 26693523 480026681 38944140 61394964 34125662 576589094 10604727 179814783 12192083 364751818 37385170 791694556 20134304 90024835 19149660 168146967 11032310 183184...
output:
344295172
result:
ok single line: '344295172'
Test #16:
score: 0
Accepted
time: 0ms
memory: 7504kb
input:
90 38 8869730 76738045 32276119 757676479 5091410 369590827 35491028 689930909 20025995 127998287 49111097 975894312 16776797 690236150 14603906 430533164 6638017 768678637 583367 277491929 43583227 197845857 19225748 735413656 39437324 641580882 43275662 785441666 50322818 734853329 35990613 997504...
output:
418654054
result:
ok single line: '418654054'
Test #17:
score: -5
Wrong Answer
time: 1ms
memory: 5520kb
input:
97 63 17888788 608002691 16142900 885752870 1364666 365868015 4878248 624150124 18576418 704242346 17020617 375882628 21749764 987510302 23736619 444353886 19722113 954714013 9275566 579405076 31641382 557924314 28779133 996785377 24059182 892591765 26116965 249236656 15958669 36018002 12783153 4066...
output:
0
result:
wrong answer 1st lines differ - expected: '-324021706', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%