QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#247265 | #7622. Yet Another Coffee | ucup-team055# | TL | 1495ms | 71672kb | C++23 | 2.0kb | 2023-11-11 13:51:05 | 2023-11-11 13:51:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LLONG_MAX / 4;
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define all(a) begin(a), end(a)
template<class T> bool chmin(T& a, T b) { if(a <= b) return 0; a = b; return 1; }
template<class T> bool chmax(T& a, T b) { if(a >= b) return 0; a = b; return 1; }
ll N, M;
vector<ll> A;
vector<ll> B;
struct Window {
ll first, cost;
priority_queue<ll> lo;
priority_queue<ll, vector<ll>, greater<>> hi;
Window() {
first = N - 1;
cost = 0;
}
ll operator()(ll i, ll j) {
assert(i >= lo.size());
assert(j <= first);
while (j < first) hi.push(A[first--]);
if(lo.size() + hi.size() < i) return INF;
while(lo.size() < i) {
const ll x = hi.top();
hi.pop();
cost += x;
lo.push(x);
}
while(lo.size() && hi.size() && lo.top() > hi.top()) {
const ll x = lo.top(), y = hi.top();
lo.pop(); hi.pop();
lo.push(y); hi.push(x);
cost += y - x;
}
return cost + B[first];
}
};
void solve() {
cin >> N >> M;
A.resize(N);
B.assign(N, 0);
for(ll& a : A) cin >> a;
while(M--) {
ll r, w;
cin >> r >> w;
B[--r] += w;
}
for(ll i = N; --i; ) B[i - 1] += B[i];
rep(i, 0, N) B[i] = A[i] - B[i];
vector<ll> ans(N, INF);
vector<Window> windows(30);
auto mm = [&](ll x1, ll x2, ll y1, ll y2, ll d, auto mm) -> void {
if(x1 > x2) return;
auto& w = windows[d];
const ll x3 = (x1 + x2) / 2;
ll y3 = y1;
for(ll y = y1; y >= y2; y--) if(chmin(ans[x3], w(x3, y))) y3 = y;
mm(x1, x3 - 1, y1, y3, d + 1, mm);
mm(x3 + 1, x2, y3, y2, d + 1, mm);
};
mm(0, N - 1, N - 1, 0, 0, mm);
rep(i, 0, N) cout << ans[i] << " \n"[i + 1 == N];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
ll T;
cin >> T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3440kb
input:
5 10 14 17 37 59 65 53 73 68 177 160 111 10 177 5 193 2 30 3 63 2 339 3 263 5 178 2 190 9 23 10 328 10 200 9 8 3 391 6 230 12 9 152 306 86 88 324 59 18 14 42 260 304 55 3 50 2 170 1 252 7 811 1 713 7 215 10 201 4 926 8 319 19 20 182 74 180 201 326 243 195 31 170 263 284 233 48 166 272 281 179 116 31...
output:
-2596 -2559 -2506 -2447 -2382 -2314 -2241 -2130 -1970 -1793 -3505 -3491 -3473 -3431 -3376 -3317 -3231 -3143 -2883 -2579 -2273 -1949 -6527 -6496 -6448 -6374 -6258 -6092 -5922 -5743 -5563 -5368 -5167 -4934 -4691 -4428 -4156 -3875 -3591 -3272 -2946 -3219 -2987 -2572 -2140 -1707 -1238 -768 -274 243 1046...
result:
ok 70 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3408kb
input:
2 5 2 1 2 3 4 5 3 1 4 2 7 3 4 3 1 10 3 8 6 4 9 3 8 4 5
output:
-2 0 3 7 12 -21 -18 -15 -11 -5 3 13
result:
ok 12 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3436kb
input:
8 1 0 72916 9 11 130289 240521 653024 625847 679075 529899 486802 540872 353600 2 5400 2 257841 6 48161 3 71484 9 156788 3 181910 4 45589 6 210869 5 70426 9 87059 5 115764 8 7 634608 412120 360938 425426 825551 138578 678304 747502 2 235317 4 281859 5 553042 8 295615 8 32014 8 755313 4 439284 19 10 ...
output:
72916 -1121002 -880481 -526881 -40079 489820 1030692 1656539 2309563 2988638 -2180324 -2041746 -1680808 -1255382 -620774 57530 805032 1630583 -1025384 -1022941 -1018403 -1013731 -1006580 -998875 -987675 -970496 -953098 -932654 -909692 -886331 -862054 -835158 -807901 -779123 -747157 -713222 -679281 -...
result:
ok 85 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
5 18 24 561699155 345484852 420718917 108291879 553918474 392861085 299874093 28528146 248352314 398850144 248444258 89834833 251398697 101739017 240342391 320200928 481962939 343719433 5 354704 6 9355942 7 7098134 16 38746862 15 35848885 14 42058214 15 18411581 9 23207206 18 19518309 14 20707458 13...
output:
-416165974 -387637828 -297802995 -196063978 44278413 292630727 541074985 792473682 1079767658 1379641751 1699842679 2043562112 2436423197 2835273341 3255992258 3737955197 4291873671 4853572826 335919368 705602908 146524143 438492672 -3870833640 -3817930784 -3749728771 -3627446160 -3471700060 -322921...
result:
ok 39 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
9 30 20 150 250 278 8 74 295 357 116 543 287 37 345 14 173 153 407 136 269 121 109 318 401 280 500 267 257 238 312 225 477 10 293 13 162 29 145 13 120 2 17 3 192 21 70 7 102 1 286 18 50 1 296 3 308 21 24 13 118 8 22 9 52 21 156 11 258 9 263 23 234 13 20 145 133 51 146 103 103 44 154 173 68 171 13 6 ...
output:
-3018 -3010 -2996 -2959 -2885 -2776 -2660 -2539 -2403 -2250 -2077 -1852 -1614 -1364 -1107 -840 -571 -293 -13 274 569 881 1199 1544 1901 2302 2709 3186 3686 4229 -3232 -3226 -3213 -3169 -3118 -3050 -2947 -2844 -2699 -2553 -2399 -2228 -2055 -23341 -23339 -23319 -23279 -23197 -23103 -22992 -22875 -2275...
result:
ok 694 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
9 87 116 40104 112075 7416 91610 15866 12407 44611 15506 71100 14593 94026 42334 100025 20930 80680 11015 98242 109216 13019 67252 116919 68275 107504 52576 17004 40039 3037 3881 44570 1353 94585 79675 7339 45331 22404 97901 9724 80802 83388 2473 85549 94423 10967 43969 113695 20677 109374 20004 580...
output:
-38209921 -38209327 -38207974 -38205501 -38202766 -38199729 -38195848 -38188509 -38181002 -38171278 -38160931 -38149964 -38138949 -38126542 -38113990 -38100971 -38086378 -38071673 -38056167 -38040301 -38023297 -38005459 -37987197 -37967845 -37947841 -37927709 -37907032 -37886102 -37863698 -37839904 ...
result:
ok 983 numbers
Test #7:
score: 0
Accepted
time: 1ms
memory: 3496kb
input:
9 86 142 92213517 9496672 49452489 24822910 83754542 16205794 51389688 428375 1002851 48157164 52117680 59497763 17633347 58906367 68451067 79249434 54433105 31464502 7839830 61662667 51765587 76375691 4573781 56984987 44487325 2241633 52805129 47978257 15910569 100187672 23178562 42273363 79351960 ...
output:
-10124197529 -10124108337 -10123679962 -10122830890 -10121828039 -10120652318 -10118781420 -10116539787 -10113419124 -10108845343 -10102599494 -10095899018 -10088059188 -10076939018 -10063282872 -10049105892 -10033195323 -10016989529 -9999756298 -9982122951 -9963976050 -9945199830 -9923352279 -99010...
result:
ok 692 numbers
Test #8:
score: 0
Accepted
time: 6ms
memory: 3840kb
input:
6 1067 1710 10 126 165 174 30 63 80 3 27 92 236 228 111 23 149 204 136 88 112 209 215 97 174 33 191 119 132 119 75 148 217 100 44 228 219 242 192 135 199 192 116 60 101 183 201 7 110 98 29 160 46 17 202 62 140 33 155 7 95 4 64 31 203 171 126 160 153 245 230 53 172 200 63 46 238 145 224 72 40 89 13 9...
output:
-165754 -165753 -165752 -165751 -165750 -165749 -165748 -165746 -165744 -165742 -165740 -165737 -165734 -165731 -165727 -165723 -165719 -165715 -165711 -165707 -165702 -165697 -165692 -165687 -165682 -165677 -165672 -165666 -165660 -165654 -165648 -165642 -165636 -165630 -165624 -165618 -165611 -165...
result:
ok 7123 numbers
Test #9:
score: 0
Accepted
time: 10ms
memory: 3652kb
input:
10 91 60 121067 735043 657233 241687 762162 115139 571678 88967 287738 448211 122872 352608 564952 661168 284979 451332 533 423562 498017 727569 159355 138992 555614 14313 782085 93040 452229 478253 432717 529858 607759 84262 444015 85191 649296 465891 474353 301611 156490 683860 173773 337140 29060...
output:
-24499779 -24499246 -24492385 -24478072 -24437183 -24395244 -24339629 -24282938 -24216256 -24146644 -24062382 -23977191 -23891367 -23804635 -23715668 -23622628 -23507489 -23384617 -23255319 -23116327 -22959837 -22800482 -22628671 -22454898 -22269412 -22072264 -21830577 -21579729 -21323958 -21057640 ...
result:
ok 10787 numbers
Test #10:
score: 0
Accepted
time: 11ms
memory: 3840kb
input:
9 1216 716 157204975 195516644 282736891 144203909 389181163 124406996 48370860 15779707 258191873 424060854 216137375 362762758 255186885 62027462 127691552 307876772 32370909 165899011 265000287 213375339 305320675 12924365 193231703 244714450 149078313 174025044 73221562 224992083 206784534 11730...
output:
-24483429239 -24482693638 -24481572401 -24480434657 -24479296574 -24477908592 -24476425384 -24474880801 -24472417201 -24469943927 -24467377821 -24464568924 -24461519318 -24458455089 -24455196742 -24450363915 -24444363241 -24437812570 -24430644713 -24421737487 -24412522121 -24403223791 -24393082366 -...
result:
ok 10594 numbers
Test #11:
score: 0
Accepted
time: 214ms
memory: 9372kb
input:
8 11577 16477 228 100 299 369 11 376 87 141 179 287 609 128 172 354 85 423 115 246 312 439 258 203 583 127 8 435 631 557 202 247 228 308 376 490 640 15 213 76 163 634 50 2 408 467 571 157 213 261 164 118 523 532 528 586 396 307 259 372 39 372 322 301 445 206 60 77 351 347 150 193 257 626 111 418 546...
output:
-6288301 -6288300 -6288299 -6288298 -6288297 -6288296 -6288295 -6288294 -6288293 -6288292 -6288291 -6288290 -6288289 -6288288 -6288287 -6288286 -6288284 -6288282 -6288280 -6288278 -6288276 -6288274 -6288272 -6288270 -6288268 -6288266 -6288264 -6288262 -6288260 -6288258 -6288256 -6288253 -6288250 -62...
result:
ok 118048 numbers
Test #12:
score: 0
Accepted
time: 147ms
memory: 9200kb
input:
8 2170 1934 535263 726298 642479 218399 641782 854221 851733 174217 100075 706854 744111 40844 407229 735348 96977 431442 24001 835272 428435 286111 844410 397533 439877 445702 658631 150596 237445 323197 171130 177732 354629 618465 545837 260182 584719 108433 471186 423718 479470 890590 163725 6675...
output:
-172567265 -172566570 -172565524 -172564295 -172562209 -172559987 -172557543 -172554892 -172551242 -172547479 -172543694 -172539420 -172535093 -172530353 -172525450 -172520296 -172512330 -172504172 -172495755 -172487183 -172478602 -172469786 -172460922 -172452038 -172442964 -172433675 -172424140 -17...
result:
ok 89656 numbers
Test #13:
score: 0
Accepted
time: 158ms
memory: 9504kb
input:
9 17593 25702 383135191 2982885 579395998 27346375 549689611 171615873 459123924 590161106 513175283 299272610 386910229 335756449 493040798 472420555 114781943 260078547 592860852 609665441 142572193 570055541 168039635 211184400 495353178 420485670 419216517 193790110 460242138 308510752 271442416...
output:
-8758707761149 -8758707731246 -8758707672737 -8758707611486 -8758707514595 -8758707415987 -8758707300983 -8758707154905 -8758706987132 -8758706810997 -8758706454330 -8758706093315 -8758705701392 -8758705297835 -8758704870341 -8758704437699 -8758703987633 -8758703484731 -8758702944760 -8758702365444 ...
result:
ok 86646 numbers
Test #14:
score: 0
Accepted
time: 1495ms
memory: 71672kb
input:
7 6800 5978 60 69 23 86 75 48 43 100 26 15 24 66 74 3 53 16 100 35 63 17 31 85 61 80 74 74 11 26 14 88 44 68 10 1 90 77 42 36 14 59 32 18 8 81 10 16 73 75 7 100 30 68 49 51 64 6 51 102 81 79 42 9 26 18 11 44 22 62 7 83 74 80 101 26 25 90 3 65 77 89 60 35 4 101 29 14 54 96 1 74 41 54 46 61 46 52 28 5...
output:
-1997112 -1997111 -1997110 -1997109 -1997108 -1997107 -1997106 -1997105 -1997104 -1997103 -1997102 -1997101 -1997100 -1997099 -1997098 -1997097 -1997096 -1997095 -1997094 -1997093 -1997092 -1997091 -1997090 -1997089 -1997088 -1997087 -1997086 -1997085 -1997084 -1997083 -1997082 -1997081 -1997080 -19...
result:
ok 559540 numbers
Test #15:
score: -100
Time Limit Exceeded
input:
8 129290 81841 135817 410713 330691 320112 132181 174498 299216 378961 85314 167742 340352 360495 59228 507118 222893 229624 97537 115998 504070 55221 192317 196386 74392 244698 358490 82189 61703 327262 431237 18466 336492 166829 470561 5179 2577 510428 374447 415257 534494 444489 121441 190385 945...
output:
-30963809525 -30963809523 -30963809518 -30963809510 -30963809489 -30963809464 -30963809438 -30963809410 -30963809378 -30963809339 -30963809299 -30963809257 -30963809201 -30963809143 -30963809081 -30963809017 -30963808942 -30963808867 -30963808790 -30963808712 -30963808623 -30963808519 -30963808410 -...