QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#870129 | #9686. 士兵 | hhoppitree | 100 ✓ | 1160ms | 33960kb | C++17 | 2.8kb | 2025-01-25 14:56:48 | 2025-01-25 14:56:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, L = 1e9;
int n, m, a[N], b[N];
long long mx[1 << 20], lz[1 << 20], rm[1 << 20];
vector<int> lsh;
void build(int k, int l, int r) {
mx[k] = -1e18, lz[k] = 0, rm[k] = lsh[r - 1];
if (l == r) return;
int mid = (l + r) >> 1;
build(k << 1, l, mid);
build(k << 1 | 1, mid + 1, r);
}
void pushdown(int k) {
if (!lz[k]) return;
mx[k << 1] += lz[k], mx[k << 1 | 1] += lz[k];
lz[k << 1] += lz[k], lz[k << 1 | 1] += lz[k];
lz[k] = 0;
}
long long query1(int k, int l, int r, int x, int y, long long cur = -1e18) {
if (l > x || mx[k] - 1ll * (y - rm[k]) * m <= cur) return -1e18;
if (l == r) return mx[k] - 1ll * (y - rm[k]) * m;
pushdown(k);
int mid = (l + r) >> 1;
cur = max(cur, query1(k << 1 | 1, mid + 1, r, x, y, cur));
cur = max(cur, query1(k << 1, l, mid, x, y, cur));
return cur;
}
long long query2(int k, int l, int r, int x) {
if (r < x) return -1e18;
if (l >= x) return mx[k];
pushdown(k);
int mid = (l + r) >> 1;
return max(query2(k << 1, l, mid, x), query2(k << 1 | 1, mid + 1, r, x));
}
void modify(int k, int l, int r, int x, long long y) {
if (l == r) {
mx[k] = max(mx[k], y);
return;
}
pushdown(k);
int mid = (l + r) >> 1;
if (x <= mid) modify(k << 1, l, mid, x, y);
else modify(k << 1 | 1, mid + 1, r, x, y);
mx[k] = max(mx[k << 1], mx[k << 1 | 1]);
}
void add(int k, int l, int r, int x, int y) {
if (r < x) return;
if (l >= x) {
mx[k] += y, lz[k] += y;
return;
}
pushdown(k);
int mid = (l + r) >> 1;
add(k << 1, l, mid, x, y), add(k << 1 | 1, mid + 1, r, x, y);
mx[k] = max(mx[k << 1], mx[k << 1 | 1]);
}
int main() {
int T; scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
lsh = {0};
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
if (b[i] > 0) lsh.push_back(a[i]);
else lsh.push_back(a[i] - 1);
}
sort(lsh.begin(), lsh.end());
lsh.erase(unique(lsh.begin(), lsh.end()), lsh.end());
build(1, 1, lsh.size());
auto getId = [&](int x) {
return lower_bound(lsh.begin(), lsh.end(), x) - lsh.begin() + 1;
};
modify(1, 1, lsh.size(), getId(0), 0);
for (int i = 1; i <= n; i++) {
if (b[i] > 0) {
modify(1, 1, lsh.size(), getId(a[i]), query1(1, 1, lsh.size(), getId(a[i]), a[i]));
} else {
modify(1, 1, lsh.size(), getId(a[i] - 1), query2(1, 1, lsh.size(), getId(a[i] - 1)));
}
add(1, 1, lsh.size(), getId(a[i]), b[i]);
}
printf("%lld\n", mx[1]);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 1055ms
memory: 33752kb
input:
12 400000 215331 32634593 161413124 11430130 630188586 215159059 12789246 181156889 228549524 981499941 223418810 352275618 169560913 44477842 463549487 811410089 903359412 824711516 611158435 295107834 85539182 327533322 109743342 641057838 88328676 920713758 477897249 720713041 347272545 372388659...
output:
5515211718 9090141614481 0 1550483803 0 327480502 779880914471 6443215571 1121926320 62933507974 1245745938 25650744251
result:
ok 12 tokens
Test #2:
score: 5
Accepted
time: 1124ms
memory: 33712kb
input:
12 400000 236512 19445969 964666124 128592527 493677654 731682625 312141789 444124895 202865650 567832603 525966138 296232142 274129593 229173862 314026986 578333281 985550145 825851916 437306778 803131266 942975297 442101385 747035060 600869338 790641753 571439079 864926723 891598839 870228695 3897...
output:
673666023 0 406003562 1214495181 578750349292 4411050575 648963089 116767841591 138313459368 169196517 20941944543 19047525803
result:
ok 12 tokens
Test #3:
score: 5
Accepted
time: 1160ms
memory: 33692kb
input:
12 400000 275408 204033824 601569078 766322764 442353353 820859273 905335427 377383977 238191424 942104651 740596681 945101937 134006902 677822792 376165552 992808097 579729381 114912751 202367478 573248049 618058603 522480142 149055519 285473880 51046529 91644803 10304022 908936088 431048873 724215...
output:
690827703 4141403625 1507264345666 61865671046 16716500823 7526035811 22411496839 235379260418 41425419 2276437120 3922344248 0
result:
ok 12 tokens
Test #4:
score: 5
Accepted
time: 786ms
memory: 33780kb
input:
12 400000 50665 343860873 607083195 757792275 544802137 781957224 183913754 635194913 82381885 611613825 997100219 384326816 432123084 932028841 591270174 588255808 709260056 922468635 768188583 550048816 868281755 412874757 676022059 506624408 326434068 814041582 998394571 409404804 509451153 91192...
output:
149179389241524 0 428508046 67482387 1896668839 2919424790 757286776200 205884885476 0 35457273121 545666202 1133819477
result:
ok 12 tokens
Test #5:
score: 5
Accepted
time: 1038ms
memory: 33960kb
input:
12 400000 190428 840421577 510819933 614725164 601350574 74245719 374738592 63426205 679254710 158602567 138564549 658921111 861307285 254745517 450604151 915417620 280076699 475924247 744714033 407954659 852122903 912514776 608226033 805327104 72496157 625614704 302231192 453353479 144738726 360576...
output:
9637434109281 15433145 1952136040 3361400734247 0 782086491316 468806007078 484370590 142253890448 90932744981 2157979752 31069817631
result:
ok 12 tokens
Subtask #2:
score: 15
Accepted
Test #6:
score: 15
Accepted
time: 3ms
memory: 12144kb
input:
6 4000 55 438 -1672 4920 -694 9 -4515 2892 4721 4948 4935 3944 677 2915 -652 890 893 3761 1477 143 4944 3967 -2370 2829 67 2370 1345 3892 3370 4708 -3461 834 4318 2277 -4390 192 -209 3080 2003 3538 3350 1067 -4779 1317 1962 3221 -4535 3009 -3801 4407 1446 2697 4623 2842 3270 1694 2843 1428 -4000 657...
output:
277072 100074 126577 21234 15681 27060
result:
ok 6 tokens
Test #7:
score: 15
Accepted
time: 2ms
memory: 12140kb
input:
6 4000 45 1496 4988 4690 -3135 570 3132 2425 -3411 1934 3759 298 -1058 843 -3975 662 3259 2493 -451 874 -409 2433 1209 1396 -4949 4347 2250 2059 -4006 2036 -4072 4761 333 3336 -2631 143 -3536 1021 -1981 2770 -115 1815 708 84 2739 2347 -2452 1887 -2843 2357 4983 4402 2499 490 3983 1824 -2606 467 -214...
output:
341142 75823 77963 53914 19946 19823
result:
ok 6 tokens
Test #8:
score: 15
Accepted
time: 4ms
memory: 12112kb
input:
6 4000 63 1986 -2331 2018 2603 4354 661 3338 1595 2455 2954 4188 -4013 3569 -592 4751 2485 4852 2258 3612 -2850 1419 4475 1615 4518 4284 2309 1307 1899 1759 4199 4177 4004 1655 4874 4028 -4356 3079 -158 1273 2826 1032 924 4857 -1436 1535 -4224 3915 -969 3946 -1574 2855 -412 4186 1180 266 2745 1894 -...
output:
138048 108650 56271 37317 4463 11900
result:
ok 6 tokens
Test #9:
score: 15
Accepted
time: 6ms
memory: 12144kb
input:
6 4000 40 4952 1810 4655 -1971 4069 446 3512 -3600 1319 -3851 2808 -3371 3820 1713 1078 1733 72 -4315 2108 -4203 2380 -2945 1325 4129 4125 4748 1057 3955 2180 -3911 2671 734 1948 -934 2697 -2427 4365 501 1595 -1732 886 -2888 519 -3258 4304 -1032 1228 3625 2497 -1676 4025 -1853 2696 1566 373 -2756 22...
output:
430801 32421 23680 57371 22065 36379
result:
ok 6 tokens
Test #10:
score: 15
Accepted
time: 6ms
memory: 12144kb
input:
6 4000 50 2547 -597 2268 -3513 832 -1145 1009 -377 3072 4610 4483 542 249 -2463 229 2543 249 390 212 -2545 4321 580 3741 -1709 3825 -3883 4747 3346 2336 1504 4515 -136 2561 1103 1027 -4253 1970 -2425 1771 -3797 3836 650 1903 3833 79 -383 4207 3550 613 -1824 55 4565 423 1616 2123 1024 4780 4451 2494 ...
output:
385250 92380 56861 36903 49759 19760
result:
ok 6 tokens
Subtask #3:
score: 20
Accepted
Test #11:
score: 20
Accepted
time: 4ms
memory: 12140kb
input:
6 4000 40 845657770 -724310339 314790762 -566202228 187061691 -849927809 881904926 159041058 958604341 -584625938 732309461 -496364578 102825909 -280420619 984389141 -643824457 464469583 398420805 531965757 -421979933 986707233 -101542333 589119003 427359050 856508269 493450680 276095634 -802021302 ...
output:
68371553898 33146407999 10153724994 5140220499 8041195769 3484829243
result:
ok 6 tokens
Test #12:
score: 20
Accepted
time: 5ms
memory: 12144kb
input:
6 4000 43 170968047 -340825910 43603324 120161242 135194193 -623243354 193711079 166657620 631572473 -24573674 713823662 -310483578 452760183 -20818013 139878123 -363494387 51983755 -238384467 570519468 -422373200 706187216 387657367 921061759 734895274 466887550 -328372907 945813520 302487995 88865...
output:
68093644425 16492687447 10856250500 2257575947 3299159572 4645058217
result:
ok 6 tokens
Test #13:
score: 20
Accepted
time: 5ms
memory: 12144kb
input:
6 4000 44 370690489 -213059981 706656407 506636031 771171886 -101893630 678621945 625974114 762826497 -11572390 67331595 224915139 141198433 -854348447 753119186 337506162 327285685 -837451831 158247576 -489078583 239054121 -175683286 688555932 -992540928 442594094 -10054201 727557378 -580560987 775...
output:
74477880247 13710850399 9196553155 13830586912 5648868051 616175449
result:
ok 6 tokens
Test #14:
score: 20
Accepted
time: 5ms
memory: 11988kb
input:
6 4000 37 983355894 685529061 492940868 132182630 598179634 -940515992 975040655 -260188059 788098428 -270623718 509638457 446100900 421859378 -961254823 46349255 412158156 648384722 213668563 981145004 -314679723 111569445 -473610506 445553961 -653125615 853375891 482921711 385630972 -759342948 355...
output:
100210439973 20684878455 10655051674 13021598391 4354902999 8952558768
result:
ok 6 tokens
Test #15:
score: 20
Accepted
time: 4ms
memory: 12140kb
input:
6 4000 31 197868336 812828593 882142773 -143556356 264224437 -408133647 401118328 -907654521 948999973 -45971388 528503241 -11713327 893940390 211116184 751593618 322840138 545322938 -816631108 466265615 89071823 521415627 -576372785 547059944 555949045 582705790 -716541923 177928687 807289225 38709...
output:
94801127316 14584729300 13239820835 9237138183 6350307776 5326098375
result:
ok 6 tokens
Subtask #4:
score: 20
Accepted
Test #16:
score: 20
Accepted
time: 125ms
memory: 18764kb
input:
10 80000 278 989724232 684111881 387651979 995302974 935116319 -763307536 357312084 -992764231 691346506 179082856 673738821 -447838734 715542279 963718765 152553078 -96440380 619692385 18180027 538482960 873901814 622934033 -173705491 873338483 177298769 503597801 185822983 282786465 165743421 7701...
output:
346908020404 109352835165 73346977722 64392675077 29627226369 14827870273 17060541872 14047193573 8741406947 8039418362
result:
ok 10 tokens
Test #17:
score: 20
Accepted
time: 124ms
memory: 18612kb
input:
10 80000 142 245955839 -544630102 695589151 -833519261 800716945 766194120 420064961 631879571 116469808 433205497 606833909 -450428722 61316454 -746161718 573774799 314373945 791559344 -315239772 819370046 552602482 448628367 237883099 894055293 555118674 561129508 135947921 284364953 -886129530 88...
output:
573295369151 108262964269 77337646112 39526251502 35871773760 17139571996 16813455195 8778256047 6667569991 5473915019
result:
ok 10 tokens
Test #18:
score: 20
Accepted
time: 124ms
memory: 19596kb
input:
10 80000 162 100633219 902504153 196789571 591034883 661823245 -270598970 742273417 721520614 288572248 51389415 860095578 489606784 326539098 -994282988 790414234 811420727 256897135 167442127 35168541 -16201194 258123501 235358304 105303003 -338520676 299666754 -949728080 406825454 -295688518 1341...
output:
457944364698 131546817840 152466913692 73762629359 23316500130 27090792774 10782390089 7555316755 4866902591 7416255978
result:
ok 10 tokens
Test #19:
score: 20
Accepted
time: 127ms
memory: 18600kb
input:
10 80000 177 861656984 371263637 116216306 327696117 546312811 -68915887 614183337 734810994 358505959 399020843 55301672 471455043 411534658 -11640304 356033618 -210150877 256346291 211101651 76622678 481237773 547837749 -23629266 626512010 -664069110 238733198 381239600 12145415 137843645 50783320...
output:
446155257857 179349170303 79428065140 31842813834 25331580937 23637377471 14503032353 7234354967 4477232171 4073344803
result:
ok 10 tokens
Test #20:
score: 20
Accepted
time: 125ms
memory: 19516kb
input:
10 80000 204 89860955 -489838562 779670045 622304828 532638707 -129104246 248603043 674060975 516569424 881468939 720846195 -49078166 173750628 -483720552 616955937 -157257624 435203319 297169572 585731882 -405452169 714939525 -187491912 347055315 -29200867 919469536 885263779 930333868 -84089898 52...
output:
312015675027 88304723781 52976132354 32598914139 23547329702 25228173789 10306478240 5243057939 6276797086 9561242646
result:
ok 10 tokens
Subtask #5:
score: 25
Accepted
Test #21:
score: 25
Accepted
time: 285ms
memory: 25228kb
input:
11 160000 250 466377051 -617201470 709746153 18809363 499278797 -710523377 15106343 357127850 957417981 815655483 548989540 857011432 342064971 -461130568 679069515 592000112 590334260 324962484 551405428 -659075943 157123277 -193688122 387315357 512108123 852827874 -346582430 412123423 -656604422 3...
output:
494187080784 199889573712 182277529826 91729514752 35480556387 33714424541 26268183732 10975720405 13174083170 14636690573 4386735958
result:
ok 11 tokens
Test #22:
score: 25
Accepted
time: 281ms
memory: 25272kb
input:
11 160000 343 246550585 244061574 758759809 -648340698 451126792 440436141 655420859 227836158 528105220 -753198551 278681891 -690885090 762214904 -539103321 948763453 -14134379 985860729 553478153 427552377 -854544510 687106852 -381981475 3889614 344097677 796078813 -769453717 932885811 -470055490 ...
output:
420873398276 230697950605 201621974520 70394848245 39250248998 51123046891 14193572683 29601230605 15432423414 9108607493 3995867509
result:
ok 11 tokens
Test #23:
score: 25
Accepted
time: 281ms
memory: 26328kb
input:
11 160000 361 828586368 -954717839 650482875 855454458 999617249 296672017 565651927 -397331864 810632736 657504219 228612647 466441678 856706447 184284638 751971151 -614224001 171539067 618386232 698996582 -505797865 51041631 607761665 643910940 -723912718 459285001 620030828 981876088 -801895592 5...
output:
523421587138 130013953443 86178534460 102324334227 43924149415 33036590717 35867168597 20519246403 6343513095 3954384336 8122486983
result:
ok 11 tokens
Test #24:
score: 25
Accepted
time: 277ms
memory: 26060kb
input:
11 160000 290 952958693 -914267738 66648989 163427438 952396151 -500312738 123150414 -943251790 200820130 -662325475 887148583 788517690 492948306 -586039694 536317895 977954151 159394091 -111764982 550040740 -537652509 81757734 510458071 458154900 -856428283 987513337 894224738 556353654 -868739376...
output:
390684009134 251655252608 115056038022 107750127289 69290448718 45483995724 26952828394 7534705405 9377757972 4399844183 2286473009
result:
ok 11 tokens
Test #25:
score: 25
Accepted
time: 275ms
memory: 25200kb
input:
11 160000 359 760637111 -625655306 941438671 157723653 265242134 652215696 781490965 359850547 17429103 -40910729 914485423 883973344 772199179 -548382407 348313522 681630384 893665407 -729617749 546131037 149694059 838998311 313421520 941417973 -506624266 422934387 -395135532 129123312 155001325 65...
output:
385240377346 161506605174 110296644343 131886288649 55675008195 17420131744 19029669988 13951826562 5306807501 1780265273 2421481305
result:
ok 11 tokens
Subtask #6:
score: 15
Accepted
Test #26:
score: 15
Accepted
time: 816ms
memory: 33708kb
input:
12 400000 317 193208489 -270750940 582242598 -29443406 314213399 -242002909 311093779 -328422545 632402493 213048254 811395226 940669675 898004477 320489888 768923060 772646467 409062473 740531861 746345655 -160152674 198610379 579865887 656915491 833962170 146211597 496968125 263883352 836697145 28...
output:
962892827301 476889150832 178405393006 186499328656 114974365758 86716435602 27841016165 27620194034 8532446371 7695548122 4088150585 10497256112
result:
ok 12 tokens
Test #27:
score: 15
Accepted
time: 787ms
memory: 33772kb
input:
12 400000 415 375402040 812615770 125768747 143532372 696413653 418734097 254200554 -441213031 275212416 -857872644 239090520 -26977224 762548586 -871263948 165938194 756695068 955993446 -485939166 759385942 882577186 327128368 615965658 347196232 190667598 887955475 -722820047 385707733 631605090 2...
output:
1043646344847 324560594645 320906177285 66473918069 153295540371 86867989798 32212876389 15709193335 23112542512 6676564778 3881443389 6387473716
result:
ok 12 tokens
Test #28:
score: 15
Accepted
time: 788ms
memory: 33812kb
input:
12 400000 544 666755210 -522526646 769581108 609737069 787606883 19368000 345450650 -130523831 244406113 -15783597 846655124 -286389151 804874599 -677692978 13008116 -770078031 620708994 -524242446 255796790 642630090 120407167 817492037 493633657 -673270931 471178572 35570785 172269178 417488577 50...
output:
933317743009 506679006117 214099755758 139194497186 63120594138 74607826835 70370512392 51200397076 11678879170 12705370829 6953611150 9327436154
result:
ok 12 tokens
Test #29:
score: 15
Accepted
time: 820ms
memory: 33748kb
input:
12 400000 447 852183444 -104227920 509394622 665480952 982763000 231857877 820230857 199804995 85087827 -285400885 361515549 276469851 797123257 773018621 764335542 -417467889 146745314 -582591354 222774502 -550097349 967130252 519896276 402124831 -26986604 71377436 -892722615 949187450 15810807 124...
output:
683744320482 363291957314 286113138375 169623685874 92995409238 92242243064 13665719940 45558460388 13517324642 13953302107 2711038075 6084201950
result:
ok 12 tokens
Test #30:
score: 15
Accepted
time: 792ms
memory: 33736kb
input:
12 400000 352 861980682 499790913 732225544 -527979405 353348262 -133415641 20303136 -970554728 133542721 -159097291 577507967 767782924 434890470 -675739680 907533723 707323835 196725772 -89659960 639908842 -754338410 100685434 -117191173 37792397 518836520 210779077 -769294618 598286757 -670286523...
output:
985178171031 278930697111 218125065186 231666718619 151641167743 63100272690 59551080204 29837201079 15296812889 7144294646 5607701559 3491689179
result:
ok 12 tokens