QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#719577 | #2179. Dungeon 3 | makrav | 11 | 2684ms | 5460kb | C++20 | 1.9kb | 2024-11-07 04:02:56 | 2024-11-07 04:02:56 |
Judging History
answer
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
#define int ll
mt19937 rnd(time(NULL));
template<typename T>
void shuf(vector<T>& a) {
for (int i = 1; i < sz(a); i++) swap(a[i], a[rnd() % (i + 1)]);
}
void solve() {
int n, q; cin >> n >> q;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i =0; i < n; i++) cin >> b[i];
vector<int> pref(n + 1);
for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i - 1];
vector<int> nxt(n + 1, -1);
stack<int> st;
for (int i = n - 1; i >= 0; i--) {
while (!st.empty() && b[st.top()] >= b[i]) st.pop();
nxt[i] = (st.empty() ? -1 : st.top());
st.push(i);
}
while (q--) {
int s, t, u; cin >> s >> t >> u;
s--; t--;
int cango = s, benz = 0, ans = 0;
for (int i = s; i <= t; i++) {
int vr1 = u - benz;
int vr2 = max(0ll, (nxt[i] == -1 || nxt[i] > t ? pref[t] : pref[nxt[i]]) - pref[i] - benz);
if (vr1 < vr2) {
ans += b[i] * (u - benz);
benz = u;
if (i < t) benz -= a[i];
} else {
ans += b[i] * vr2;
benz += vr2;
if (i < t) benz -= a[i];
}
if (benz < 0) ans = -1e18;
}
cout << (ans < 0 ? -1 : ans) << '\n';
}
}
signed main() {
int tt = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
//cin >> tt;
#else
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#endif
while (tt--) {
solve();
}
return 0;
}
詳細信息
Subtask #1:
score: 11
Accepted
Test #1:
score: 11
Accepted
time: 11ms
memory: 3916kb
input:
2968 3000 195694 114761 84601 149164 83572 166860 83871 71067 14931 22597 45549 26862 29127 9421 126511 19869 175633 47521 181323 38646 178807 186054 31799 173648 106553 94698 98918 149462 95647 145666 121002 178141 154888 183449 176438 194661 97265 28777 98620 113016 49316 125390 35010 31772 159928...
output:
646758143905 -1 691191572558 192301106829 503691788062 136375921869 789174277209 1878434150794 -1 76495643279 234719906270 278581826840 178422836927 761213865348 596973476366 -1 3649891101352 -1 1768936832497 1864726938342 1646411424142 805188342798 2480719218365 1540142237698 2100449734488 48678149...
result:
ok 3000 lines
Test #2:
score: 11
Accepted
time: 7ms
memory: 3760kb
input:
2985 3000 1643 2564 495 3814 1776 1110 747 4868 4459 115 2805 4101 773 4986 1423 56 1523 2920 3424 2007 4907 1616 3545 4757 2672 4060 1370 3243 3132 2454 1601 2925 3970 2545 1192 500 2475 3645 471 456 4436 1227 4527 1822 1153 890 169 1515 266 2742 4487 1361 624 75 1538 2679 1168 2815 419 4157 111 37...
output:
560517127956 406753449461 75037798350 120444434460 820920461777 289077908562 313941880061 99111155571 21161706811 143920185130 120935068604 518676363859 222724626637 510101403980 418036351278 234670223667 813839591942 367028205096 1463392378045 770311965507 506381827742 581571715085 181734818384 121...
result:
ok 3000 lines
Test #3:
score: 11
Accepted
time: 8ms
memory: 3788kb
input:
2923 3000 2139 1783 1177 4588 140 912 1362 2972 1759 1299 3009 3360 1457 2124 1127 142 2037 3528 4730 1732 3612 275 534 4641 4231 1943 2411 2014 61 1480 3158 200 3396 3241 4672 1857 2644 168 2269 403 2235 3969 3149 4760 2282 197 3106 2417 2294 4225 1202 3730 368 4507 4699 3276 4925 3597 2177 3292 29...
output:
563980715891 501430478252 941332848420 512580729965 787463681822 284110214411 192981880433 384141395148 382346359714 748919812915 1302164217727 509358707211 187692623430 625636298562 110661992579 647687432857 93693778870 -1 735959536032 1300625099534 484349981955 -1 7010460165 175456461027 678959512...
result:
ok 3000 lines
Test #4:
score: 11
Accepted
time: 9ms
memory: 4012kb
input:
2939 3000 93 181 257 335 342 391 471 481 517 628 650 687 740 743 864 1116 1164 1186 1203 1244 1250 1348 1350 1374 1406 1480 1495 1521 1566 1592 1708 1792 2000 2017 2066 2196 2305 2428 2445 2496 2499 2560 2660 2858 2954 2981 3027 3064 3077 3171 3183 3326 3326 3367 3392 3538 3578 3645 3701 3722 3726 4...
output:
105216784828 101245407760 103973901719 52333571394 6157452678708 86767499186 929093750829 1821129730615 2257220493299 284989615473 85439987657 3510061683059 4266492672046 562464218307 443085988895 3473531512024 788570327425 367473181972 8917048030871 1089507461430 1890460761377 1680844227764 1474103...
result:
ok 3000 lines
Test #5:
score: 11
Accepted
time: 10ms
memory: 3980kb
input:
2954 3000 1 3 6 6 7 10 15 21 24 26 27 30 33 33 35 39 40 43 44 45 47 50 50 52 52 54 55 57 59 63 64 65 66 66 69 71 73 73 73 75 79 82 83 85 87 88 93 93 94 96 97 100 100 101 102 107 112 114 117 119 119 119 122 125 128 128 131 132 135 135 138 142 142 143 146 147 147 147 148 152 152 156 159 160 166 168 16...
output:
77627558386 212664247792 522082675374 745562910173 1396908830934 927230685782 303053691829 489233803748 752620661988 1022169810030 689370604 154160326004 1101129851925 136788139717 376564329540 276244602765 1422180120919 145349770104 76746046306 1067608739607 1375259978425 18276134052 1414325105455 ...
result:
ok 3000 lines
Test #6:
score: 11
Accepted
time: 7ms
memory: 4036kb
input:
2990 3000 11 40 214 258 263 336 362 370 548 594 715 740 748 753 785 793 880 910 913 1185 1232 1363 1436 1486 1499 1570 1580 1644 1690 1720 1729 1734 1851 1952 2011 2148 2187 2216 2241 2307 2355 2370 2461 2487 2708 2732 2781 2817 2848 3021 3025 3052 3067 3138 3144 3171 3186 3292 3364 3470 3524 3547 3...
output:
-1 31442869613547 16996310339973 15648913415475 7628516252824 596569474932 2434019470382 27328059116378 40197155081755 54238451709287 13851466779851 735352574467 7382067891002 57982678827722 2901800189059 8483243067350 -1 4025413567610 57309167508036 57083175118448 50783409409579 2826549552931 29602...
result:
ok 3000 lines
Test #7:
score: 11
Accepted
time: 9ms
memory: 3756kb
input:
2981 3000 5000 4999 4995 4992 4992 4985 4983 4981 4981 4979 4978 4977 4976 4976 4974 4971 4970 4969 4966 4965 4964 4964 4963 4963 4960 4958 4958 4958 4954 4953 4952 4952 4951 4951 4947 4946 4945 4944 4940 4940 4938 4938 4937 4937 4936 4935 4933 4933 4931 4930 4924 4921 4919 4917 4915 4915 4913 4912 ...
output:
219390367326 23804471459 11372969082 46054893539 -1 1613644575 5405571197 9781879593 2234284138 3329941785 327426166374 185039169050 1990018583 2262510958 68351978236 1974163710 1784204426 4197284649 1829879761 176325180794 1732480004 8595686614 7303494667 26753370796 3829666783 27909550065 27675250...
result:
ok 3000 lines
Test #8:
score: 11
Accepted
time: 7ms
memory: 3752kb
input:
2975 3000 4998 4997 4996 4991 4988 4988 4987 4984 4984 4984 4983 4982 4980 4978 4976 4972 4970 4969 4968 4965 4963 4962 4960 4959 4958 4957 4956 4956 4953 4953 4950 4950 4949 4948 4947 4945 4945 4945 4945 4943 4943 4941 4938 4937 4936 4935 4935 4934 4933 4933 4930 4930 4928 4927 4926 4922 4918 4917 ...
output:
278550667744 1463104267886 1481664572758 646951609524 169264326416 859274886451 226776077948 -1 1041823967396 1342483136298 50645684250 31675811127 726263439888 3511854247 358454950551 115927088948 154178256141 218637852669 417938451122 376093223343 514719589685 4582912222 517948056140 17696119922 4...
result:
ok 3000 lines
Test #9:
score: 11
Accepted
time: 7ms
memory: 4016kb
input:
2942 3000 5000 4998 4997 4995 4995 4994 4992 4989 4989 4989 4987 4986 4985 4984 4983 4981 4980 4976 4974 4974 4973 4971 4971 4970 4964 4962 4961 4958 4958 4954 4950 4947 4947 4947 4946 4945 4940 4937 4936 4935 4933 4931 4929 4929 4926 4924 4923 4921 4920 4920 4918 4917 4916 4914 4913 4911 4910 4905 ...
output:
167333439318 634446640660 473775216224 27351213345 -1 358921329822 703716614812 373963740090 463485564664 140405701607 235711418840 596472506714 3540235648 39175666139 1149586227761 237333053920 281592736581 1060648920141 100652431852 87930126434 639145247549 1472933567908 107967530734 -1 6619923995...
result:
ok 3000 lines
Test #10:
score: 11
Accepted
time: 10ms
memory: 3764kb
input:
2948 3000 21087 141349 10206 199320 58267 117049 57796 174521 75036 133853 46187 123531 54956 163630 94350 189073 30943 173449 2951 157107 52178 187478 47534 115697 5145 193693 80490 173598 12135 121201 88925 184882 29984 114393 98065 189293 79767 121803 81271 116733 10585 140967 79442 143509 92184 ...
output:
4752959077051 -1 290393714551 -1 1957250444830 317002502575 4990415597665 2974663654838 113139894114 77971978286 335949293588 227799655638 200392492594 630650522375 -1 4093650913408 -1 912303739748 4476535430711 175598374472 276742968881 43049178236 1076442816529 630300470935 1493207136228 123946001...
result:
ok 3000 lines
Test #11:
score: 11
Accepted
time: 3ms
memory: 3752kb
input:
2955 3000 36292 142401 30036 101698 36219 122536 75244 138118 46438 107597 15215 164288 30983 194250 19031 152036 86220 165421 80796 185393 18082 140558 24827 124350 51934 106720 11335 177503 78835 107409 77272 125775 44168 156011 51457 198952 66084 160887 59053 177594 49844 149670 19121 105949 6975...
output:
-1 46423527481172 45142641848005 24466449935901 32993634707655 4392489200205 57832539090968 -1 11759473675096 28822393321952 13130850483879 55910172854461 29308246748826 -1 25774263140878 35495441779018 -1 18981067120531 57475643202762 25010164724881 3496112089334 30250447717801 16133785794962 50134...
result:
ok 3000 lines
Test #12:
score: 11
Accepted
time: 8ms
memory: 4036kb
input:
2984 3000 84952 196644 51085 154237 61940 147864 76484 106401 1196 180396 51564 169097 44131 129117 23929 125441 34770 186103 42077 168214 56135 152587 81773 98513 14606 120797 71396 145443 4847 104202 42064 116654 84131 147524 73138 148203 92276 147672 42745 176221 49291 155856 24657 170718 38014 1...
output:
17480579202548 33366998393702 18436506708207 57069663287374 13865442626545 3406520042529 49417117021122 9345356256398 56596672810903 21374684578570 56211970912079 31619329001202 4530756479763 30962871759147 37196047380981 34114416199955 40129946563309 -1 32685167094592 18138711863636 2758333925931 4...
result:
ok 3000 lines
Test #13:
score: 11
Accepted
time: 10ms
memory: 3712kb
input:
2985 3000 173126 197279 34624 80913 53828 41410 151811 120640 163979 112773 160662 37601 114506 108654 104239 142170 169276 43287 13385 106984 177073 69299 66728 30577 46328 102953 122467 158941 167209 92839 97072 115193 168277 40073 38952 175771 134554 68966 111835 4713 172003 146197 110326 61622 1...
output:
10413524339717 22532275201453 1278743643958 43909362033755 10575516116617 22250537718897 44949591649569 -1 25703314524884 25282462654793 9429176371418 845829978780 39200891300 16935877182560 23411821731405 -1 12473598525163 -1 -1 21599945856034 1181480291239 30486294371852 21400209992869 75424491325...
result:
ok 3000 lines
Test #14:
score: 11
Accepted
time: 8ms
memory: 3784kb
input:
2960 3000 3406 1954 4691 11 2932 768 63 478 2875 1829 3784 755 4913 2715 2038 4005 1448 4500 783 590 2524 4427 42 4782 502 239 4448 1785 4585 1659 2560 4221 3090 4126 280 1637 3253 707 4947 2676 625 2353 2160 212 2426 557 956 3515 1162 3791 4176 3377 4034 1864 1217 4238 3360 3782 1006 2830 563 4667 ...
output:
541153468159 235155324757 109271043095 1450956091548 804151589038 1440364986044 857150578172 1160729908013 6302448300 793725189059 466472689704 115481107390 16718216248 76113783513 50173881412 307214985542 207242512452 349200117803 934954331713 706693751199 202600142317 1315290838 182225754981 19650...
result:
ok 3000 lines
Test #15:
score: 11
Accepted
time: 3ms
memory: 3736kb
input:
2937 3000 92 95 96 99 101 102 103 103 104 104 105 108 110 114 115 115 116 122 123 123 126 127 129 132 138 141 142 145 150 152 156 157 159 160 160 165 166 172 172 173 173 174 175 178 180 181 181 184 185 187 187 187 188 194 199 199 202 203 203 206 208 208 211 217 218 220 220 220 224 225 226 228 230 23...
output:
1093245608311 685023209468 1469454706537 22752560833 54069588849 410868259048 451801507669 387392463241 767008445569 113876071959 690352912281 346615911616 428346456975 216335776165 343030756822 79393106487 147187294578 8246019065 36643940843 1469363786349 1114795791058 599683378782 130110480253 930...
result:
ok 3000 lines
Test #16:
score: 11
Accepted
time: 8ms
memory: 3820kb
input:
2989 3000 23 22 21 20 19 18 18 16 14 14 11 10 10 6 4999 4999 4998 4998 4996 4995 4994 4992 4992 4990 4989 4988 4985 4983 4983 4976 4975 4973 4971 4970 4969 4967 4963 4963 4963 4961 4961 4959 4957 4957 4956 4956 4955 4955 4954 4953 4950 4949 4948 4946 4944 4944 4941 4941 4936 4934 4933 4933 4932 4932...
output:
776975949190 -1 1024550787964 229436173785 89714295902 768375842319 1449631589782 1270553915309 237708074516 110892754622 149246154285 963115755119 84017836036 724043208210 862181838 89985458607 1476022447511 1337306668535 1473552872227 848194182156 776585037311 604617330703 14843284500 23028643162 ...
result:
ok 3000 lines
Test #17:
score: 11
Accepted
time: 5ms
memory: 3820kb
input:
2976 3000 199966 3 90 199989 199996 18 199978 4 199914 199901 60 62 54 25 68 199965 199912 42 86 199981 41 199956 199964 6 199993 199940 199975 20 199925 85 199975 199942 199913 19 27 22 199903 199940 199955 35 3 199971 73 199998 96 96 41 22 60 199904 199954 27 199945 2 12 199948 91 90 44 199987 57 ...
output:
532804397196 191107847494 96687740649 -1 12373612653069 4261444311411 237750674859 -1 -1 -1 -1 238722584089 148457317750 330541281252 -1 1206981756172 3456407589884 420250998357 61345423881 105979091942 159769741594 132414606655 515028093539 4539549703269 394659644987 1114661533145 -1 1306986881207 ...
result:
ok 3000 lines
Test #18:
score: 11
Accepted
time: 6ms
memory: 3704kb
input:
2942 3000 199921 32 199978 199956 199912 199903 199951 42 63 78 98 84 199966 49 199948 83 199936 199943 57 83 199982 12 8 199937 199949 199917 200000 36 42 23 199982 199940 23 41 199915 66 35 199964 199961 6 27 64 200000 199968 11 86 199932 199916 10 14 34 199924 47 199963 199920 80 67 86 199938 92 ...
output:
4905171511324 -1 -1 4075528204774 13301382268435 43724335674803 2690148942204 14838025524014 3454709649210 -1 -1 -1 1616950518503 -1 -1 -1 34037970748268 -1 -1 9773917101806 7880201934751 28587305148263 27606380690524 -1 15769354874529 21435430490628 -1 -1 17576854467826 25654032243766 -1 9106873271...
result:
ok 3000 lines
Test #19:
score: 11
Accepted
time: 3ms
memory: 4004kb
input:
2988 3000 91 100 199912 9 47 199924 83 199937 96 199931 1 76 26 33 83 199927 199973 199940 9 199902 199995 199997 43 67 200000 24 199984 199976 199986 199981 58 199968 199902 75 199921 77 44 89 46 57 199949 199981 199900 25 67 199987 100 2 199928 199936 199957 2 36 62 85 199958 56 81 66 199970 19990...
output:
-1 7254352521094 -1 10503453880390 29736685505042 36512902384182 3527330997160 18942430102204 30931520706797 -1 43808006703132 4071442653662 24617431303055 30009534588630 10247178531352 -1 28574416358976 -1 -1 12513463824695 37536629612965 10277835054027 8961814045160 9314557715164 4923427697020 244...
result:
ok 3000 lines
Test #20:
score: 11
Accepted
time: 16ms
memory: 3996kb
input:
3000 3000 500 495 500 499 495 497 492 499 494 498 495 499 495 494 495 494 496 495 500 497 499 500 491 491 500 499 491 500 498 494 500 497 496 495 490 493 490 498 493 498 492 494 497 495 499 492 491 495 492 495 492 499 494 495 494 497 498 493 491 494 499 493 493 493 497 500 490 497 496 494 493 500 49...
output:
285677254516 288109687104 288687782288 290630018781 286531863652 290539410637 288198297314 291827650142 287338534404 290045409287 284305860602 285754488319 288995878400 286241791751 287542474710 290827031649 285580929230 287444895577 287708240012 288112565607 289475449182 287250707421 291321798185 2...
result:
ok 3000 lines
Subtask #2:
score: 0
Time Limit Exceeded
Test #21:
score: 14
Accepted
time: 1642ms
memory: 5276kb
input:
49414 50000 1 2 3 4 17 22 23 24 29 30 35 42 47 48 55 57 63 65 67 68 72 74 78 94 99 105 106 107 113 115 115 115 121 122 123 124 128 132 133 139 148 154 160 160 166 167 169 172 172 176 180 185 185 186 191 192 201 202 206 208 213 214 229 230 233 239 240 244 251 252 255 258 263 267 269 270 273 273 274 2...
output:
229351781114038 691585722607106 212249616022073 436679871997312 47649154641794 152704801333623 162265699885646 12770601806238 203195986279961 824969157587126 824819070962027 825150008439340 200947987555379 301235704785556 44273973887492 532874836353182 681913863278118 315446799789453 148010020319595...
result:
ok 50000 lines
Test #22:
score: 14
Accepted
time: 2684ms
memory: 4700kb
input:
49783 50000 199999 199998 199997 199987 199970 199959 199954 199950 199948 199947 199946 199944 199937 199934 199933 199930 199929 199923 199919 199919 199911 199909 199907 199905 199904 199900 199900 199899 199896 199891 199888 199882 199881 199881 199880 199876 199870 199869 199864 199860 199836 1...
output:
497466286743600 527630073716750 279083639630009 315531758376292 79434438300864 24053542782821 440526099777571 575739757470698 366164927517175 107971687459384 611789286123468 665431936694383 615073472257053 228032817148668 518462984735324 359531014475570 373554277409827 156864655092511 24083138387395...
result:
ok 50000 lines
Test #23:
score: 14
Accepted
time: 1509ms
memory: 4800kb
input:
49981 50000 23009 170341 195209 81423 76571 154255 140917 29859 27022 136449 171933 156782 62643 166647 7745 140744 106258 20454 84289 185834 159594 37704 27083 77442 69085 52489 104300 166232 135720 176735 104219 127536 142459 32265 91722 102195 143779 77514 144966 80550 41236 130315 119950 95721 8...
output:
370887039568282 62020637794395 162750214931549 54381550483527 480834223167746 72794199913594 727209877286758 123459520952044 271031459507229 77733473425608 234040065889437 14394866413596 361737806721862 873764912666217 874411497468422 78248388914543 873385679061354 670138937416955 874316755548235 24...
result:
ok 50000 lines
Test #24:
score: 14
Accepted
time: 1713ms
memory: 5460kb
input:
49038 50000 133535 184751 162691 29924 94710 72776 63045 35454 93424 105220 114542 6282 111684 117424 149309 158678 8052 72166 191811 69703 53637 108018 3627 58906 88782 158504 52854 121454 78301 86117 74876 74578 183002 92283 6966 192661 71336 56364 134743 122290 181125 55279 144368 194925 28224 89...
output:
556520480774469 223989451511714 323447742719248 89544730535979 486819714373318 45031971978409 858249383981266 164126750263605 372516941144433 91368458170586 857187068542539 492550376928735 101284238464345 255459305170655 307798606893581 200221637718571 314636885356329 424560810873733 765927785592747...
result:
ok 50000 lines
Test #25:
score: 14
Accepted
time: 1899ms
memory: 4740kb
input:
49941 50000 131322 47352 154983 120298 40153 37053 97781 139625 66248 154670 133089 151710 158445 138843 143925 3764 82900 55303 94620 154723 135544 85996 53980 13099 103904 87846 23200 191282 144500 56684 162447 138643 170805 171243 16691 16606 28326 67218 126821 62220 185520 188093 137845 118277 4...
output:
11692126876441 6934215982040 15250734392300 10766067597410 15336156571547 17741511205060 4895556346222 29355581409472 10519477251440 15201990529012 11037104257302 13725080841290 10085765588385 19180646252495 10976234584834 29374002175560 345205928853 10981855215161 14115800851885 22169069579432 1230...
result:
ok 50000 lines
Test #26:
score: 0
Time Limit Exceeded
input:
193753 200000 200000 199999 199998 199998 199997 199996 199995 199995 199995 199992 199990 199987 199985 199981 199980 199976 199976 199976 199975 199973 199973 199973 199972 199971 199970 199970 199970 199970 199970 199966 199965 199964 199962 199961 199961 199961 199959 199957 199957 199956 199955...
output:
1973409677491495 946870681672896 589874837778694 2410478717696133 313027804112285 1146937496440672 1957641832124075 130552215453650 25507298948148 1243545541588866 2183698242841216 998729244969895 113583142033587 1000977351402115 511742884863546 650383267686477 396484726244 2027492020505327 11032653...
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #36:
score: 0
Time Limit Exceeded
input:
200000 200000 28646 30154 5388 22119 32077 11843 22185 20457 4284 19797 14537 18426 21420 13034 28504 15056 17391 26651 4316 44669 34999 17336 14427 42183 25112 29907 16908 32904 23781 27635 44514 36024 12435 14555 40422 25692 43414 12346 3329 31641 29115 14449 12127 40639 1576 37164 13309 31976 113...
output:
7450981853127 27293062194659 110364549999546 7125556246842 116279620730 19109542894069 -1 2272372077636 68246604637944 23503319546799 811993199574 -1 525547926571 1654302033014 213109416873758 -1 1951754477279 60240802359572 2318612470778 6347007399747 427696556322 -1 42455737680576 155367200626716 ...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%