QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#784270 | #6660. 택시 여행 | guosoun | 0 | 229ms | 66836kb | C++17 | 3.2kb | 2024-11-26 14:22:11 | 2024-11-26 14:22:11 |
Judging History
answer
#include <bits/stdc++.h>
// #include "../cpp-dump/cpp-dump.hpp"
template<class T>
void chkmin(T &x, const T &y) {
if (x > y) x = y;
}
using ll = long long;
struct sgt {
struct line {
ll k, b;
ll eval(ll x) { return k * x + b; }
};
static int const BUF = 2e6;
static line tr[BUF];
static int ls[BUF], rs[BUF], ntot;
int rt;
ll l, r;
void insert(int &i, ll l, ll r, line li) {
if (!i) return tr[i = ++ntot] = li, void();
auto mid = (l + r) >> 1;
if (li.eval(mid) < tr[i].eval(mid)) std::swap(li, tr[i]);
if (li.eval(l) < tr[i].eval(l)) insert(ls[i], l, mid, li);
if (li.eval(r) < tr[i].eval(r)) insert(rs[i], mid + 1, r, li);
}
ll query(int i, ll l, ll r, ll p) {
if (!i) return 1e18;
auto mid = (l + r) >> 1;
if (p <= mid) return std::min(query(ls[i], l, mid, p), tr[i].eval(p));
else return std::min(query(rs[i], mid + 1, r, p), tr[i].eval(p));
}
sgt(ll l, ll r) : rt(0), l(l), r(r) {}
void insert(line li) { insert(rt, l, r, li); }
auto query(ll p) { return query(rt, l, r, p); }
};
sgt::line sgt::tr[sgt::BUF];
int sgt::ls[sgt::BUF], sgt::rs[sgt::BUF], sgt::ntot;
std::vector<ll> travel(std::vector<ll> a, std::vector<int> b,
std::vector<int> u, std::vector<int> v,
std::vector<int> w) {
int n = a.size();
a.insert(a.begin(), 0), b.insert(b.begin(), 0);
std::vector<std::vector<std::pair<int, int>>> g(n + 1);
for (int i = 0; i < n - 1; i++) {
++u[i], ++v[i];
g[u[i]].emplace_back(v[i], w[i]);
g[v[i]].emplace_back(u[i], w[i]);
}
std::vector<std::vector<std::pair<int, ll>>> h(n + 1);
std::vector<int> vis(n + 1);
auto build = [&](auto &self, int u) -> void {
int tot = 0;
auto dfs1 = [&](auto &self, int u, int ff) -> void {
tot += 1;
for (auto [v, w] : g[u])
if (v != ff && !vis[v]) self(self, v, u);
};
int rt = 0;
auto dfs2 = [&](auto &self, int u, int ff) -> int {
int ret = 1;
for (auto [v, w] : g[u])
if (v != ff && !vis[v]) ret += self(self, v, u);
if (ret * 2 >= tot && !rt) rt = u;
return ret;
};
dfs1(dfs1, u, 0), dfs2(dfs2, u, 0);
auto dfs3 = [&](auto &self, int u, int ff, ll d) -> void {
h[u].emplace_back(rt, d);
for (auto [v, w] : g[u])
if (v != ff && !vis[v])
self(self, v, u, d + w);
};
dfs3(dfs3, rt, 0, 0);
vis[rt] = 1;
for (auto [v, w] : g[rt])
if (!vis[v])
self(self, v);
};
build(build, 1);
// cpp_dump(h);
std::vector<sgt> tr(n + 1, sgt(0, 1e11));
auto query = [&](int u) {
ll ret = 1e18;
for (auto [id, dis] : h[u])
chkmin(ret, tr[id].query(dis));
return ret;
};
auto update = [&](int u, ll d) {
for (auto [id, dis] : h[u])
tr[id].insert({b[u], a[u] + d + b[u] * dis});
};
std::vector<int> id(n - 1);
std::iota(id.begin(), id.end(), 2);
std::sort(id.begin(), id.end(), [&](int u, int v) { return b[u] < b[v]; });
update(1, 0);
for (int i : id) {
auto d = query(i);
update(i, d);
}
std::vector<ll> ret;
for (int i = 2; i <= n; i++)
ret.push_back(query(i));
return ret;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 1ms
memory: 6120kb
input:
2 684124582850 713748627948 74361 256955 0 1 661088
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 733283747618 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 3 lines
Test #2:
score: 7
Accepted
time: 0ms
memory: 5836kb
input:
3 251115773325 363097865287 358609487841 826785 213106 914768 0 1 851938 2 0 231697
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 955485332655 442679377470 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 4 lines
Test #3:
score: 7
Accepted
time: 0ms
memory: 5936kb
input:
3 489998888627 318672977903 70353752652 258347 458793 258657 2 1 156120 0 2 524840
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 665922861747 625589728107 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 4 lines
Test #4:
score: 7
Accepted
time: 1ms
memory: 5808kb
input:
3 737471938521 315388610250 818943569900 726908 666797 564862 0 1 460302 0 2 785280
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1072069144737 1308298252761 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 4 lines
Test #5:
score: 7
Accepted
time: 1ms
memory: 5864kb
input:
4 201836820267 208957719162 992553400562 566050337171 243994 65303 590123 936951 1 0 259719 0 3 860376 3 2 513584
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 265206697953 537074816507 411763402011 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 5 lines
Test #6:
score: 7
Accepted
time: 0ms
memory: 5936kb
input:
4 440719935569 160237864481 704297665373 767778991240 451998 371509 46564 828427 1 0 861960 1 3 830699 2 3 185693
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 830324131649 1289731282865 1205798418251 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 5 lines
Test #7:
score: 7
Accepted
time: 1ms
memory: 5860kb
input:
5 148262899914 9382086008 622202345986 443806901161 213829280326 178155 503016 333953 572340 461148 0 3 453941 3 2 84057 4 0 171136 3 1 598794
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 335812903839 244109933604 229134758769 178751633994 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 6 lines
Test #8:
score: 7
Accepted
time: 1ms
memory: 6148kb
input:
5 391440982512 969252165920 333946610796 649830522527 902812044171 522045 996458 225429 545971 667483 0 1 701500 0 4 514779 2 1 435377 3 0 919439
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 757655550012 984941935977 871429515267 660178785567 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 6 lines
Test #9:
score: 7
Accepted
time: 1ms
memory: 5872kb
input:
17 315015458526 65513576283 829720084774 654640079244 561177336848 463903843105 496216524512 837433489064 92734412345 807145138979 250511786518 915329126804 373916658654 78276842047 121976569238 432447179015 519384539551 696133 642473 231377 987220 589587 337763 790202 785083 249580 108311 73808 892...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 430639669161 417840567823 403532946274 499079112962 498466070651 495984520010 499402357184 501387707132 498265325456 501233852966 474661031682 494612046266 411867746683 497598865088 499819422548 496976423075 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 18 lines
Test #10:
score: 7
Accepted
time: 1ms
memory: 5900kb
input:
20 764145449871 794297102632 450082553736 427358261877 587251097098 98567356955 15910789509 321286084089 25839798358 969219436118 975479420690 937908953492 410498404545 180209954689 302999489632 849828117651 171771046425 800442975277 295169929534 146003957886 828538 724406 733109 79844 665172 652593...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1384833390877 871900130923 1446847771547 1245326093057 924349900475 1046486123707 1063981383357 864751505059 1159443240947 824076089025 1448542597977 1486181926466 1488465960086 1424780088987 1478403270966 1303312410681 1485431478966 1135576549657 1412080059777...
result:
ok 21 lines
Test #11:
score: 7
Accepted
time: 0ms
memory: 5944kb
input:
20 286866076510 666296858783 319893290745 436172872006 579306725182 388780143357 429085643976 163864091991 334402956892 573150791451 971047548996 924353133556 82495144441 364862686518 76783079529 74022380610 978776791995 17833817791 637808249822 150520055702 705613 111460 694926 702547 748042 671482...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1345583882860 995125125260 815198043938 1295987956432 1034264067144 888082221934 1247814963646 1225117709350 631676569994 1289347270738 404306893004 1347095564962 373415155864 1441975557454 1167058795516 1091947224281 1373264198836 795244013911 1127743556434 se...
result:
ok 21 lines
Test #12:
score: 7
Accepted
time: 1ms
memory: 6160kb
input:
20 161996998737 15089127085 28063038428 574601167323 736141386895 762192247356 788118187801 956063872362 580983462657 839554694910 471536078792 781164874294 363054673222 809510755913 153755418459 78171544930 969593469579 864779185396 408120998971 610129629325 933618 563940 506188 824442 64614 396381...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1870873819056 1340292002469 2180029603234 1667979150565 2084831816447 1131232525437 1898452835615 1742994070672 2139665843266 1042857179175 2148449164384 1856727805178 2077059488718 1931794896836 1753987714167 1864830429393 1705470391803 1529058594761 197326523...
result:
ok 21 lines
Test #13:
score: 7
Accepted
time: 1ms
memory: 5852kb
input:
20 443174843835 295023765677 175861678382 805210665445 724299682774 889923334441 967560897715 857729286838 7238459275 901083586058 887820756720 681912091803 886476957360 821901344613 222491154905 602669810322 953890359316 822857333786 674877086360 498973934687 505612 0 0 0 913180 49780 0 0 0 0 0 0 0...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 737522649521 561660971139 737522649521 737522649521 737522649521 737522649521 637744453675 737522649521 737522649521 737522649521 737522649521 737522649521 737522649521 737522649521 737522649521 737522649521 608216207263 737522649521 737522649521 secret: XBNN6R...
result:
ok 21 lines
Test #14:
score: 7
Accepted
time: 1ms
memory: 5864kb
input:
20 903941728884 384581140226 453502499061 225752209240 885300062423 504103937164 667092163600 460139456041 109118743857 207444296671 30492319139 345381827436 453966959387 438774451871 860637725773 554202343964 68114298125 781071441103 276250637196 155641220254 635683 100430 56855 0 0 0 0 0 0 142765 ...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1792855089572 1792855089572 1792855089572 1792855089572 1792855089572 1792855089572 1332715633531 1792855089572 1792855089572 1792855089572 1792855089572 1792855089572 1792855089572 1792855089572 1792855089572 1792855089572 1792855089572 1792855089572 179285508...
result:
ok 21 lines
Test #15:
score: 0
Wrong Answer
time: 1ms
memory: 5852kb
input:
20 1000000000000 7 1000000000000 13 1000000000000 1000000000000 13 5 1000000000000 1 1000000000000 1000000000000 12 6 1000000000000 3 16 18 10 7 1000000 999999 1000000 999997 1000000 1000000 999994 999993 1000000 999991 1000000 1000000 999988 999987 1000000 999985 999984 999983 999982 999981 0 1 691...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1691757000000 2096049595714 2464529227234 2563765127998 3034749289350 3885773736269 4460801011182 4641764468290 4842050867429 5574189869481 6059287958875 6615413622101 7286479000014 7388456082212 8143398287671 8628120925128 8760521733510 9298930887784 934428847...
result:
wrong answer 5th lines differ - expected: '2563764929539', found: '2563765127998'
Subtask #2:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 177ms
memory: 66836kb
input:
100000 746699125678 374834842799 250803643493 620187038832 454433387570 406226564003 897157438699 99473514061 734784419618 503968957100 363935477037 277126009840 52078020050 990757079812 847235285349 950784717285 271017141367 861087225700 996035427219 520682200664 282013988419 415183977876 882007771...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1148030742334 1636760433058 2131282232650 2353514637869 2672707119337 2763307672337 3003543484926 3059216601498 3109347572318 3173036690606 3224306800424 3269329387652 3324613979094 3328434230236 3342554792694 3391237344396 3417184791476 3419985316546 343705790...
result:
wrong answer 8th lines differ - expected: '2948215735597', found: '3003543484926'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Wrong Answer
Test #69:
score: 0
Wrong Answer
time: 95ms
memory: 34048kb
input:
100000 15175010 23519365 21177669 27079342 9089 16784452 29693960 23124925 17048604 10179491 12828214 24992902 8483134 2928073 23807522 7332137 17421520 28460746 1607282 13224363 11900728 11794692 11495061 4687109 23460275 7657982 27417256 16978162 7326803 23083826 24942987 16610314 12147303 2828271...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 16817058 ...
result:
wrong answer 2nd lines differ - expected: '16705757', found: '16817058'
Subtask #5:
score: 0
Wrong Answer
Test #94:
score: 29
Accepted
time: 85ms
memory: 33564kb
input:
99281 551670361798 568902251563 418071776626 697635341894 641578820039 117221079324 812766431051 425410617978 663769685693 282144284527 799662290178 749088952784 586626406385 122473825417 459510657357 871705247919 443707710712 735612808044 237919555727 829939639783 122127143240 616906466299 24431898...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 5...
result:
ok 99282 lines
Test #95:
score: 29
Accepted
time: 102ms
memory: 37820kb
input:
100000 762048253398 544847923340 274220772253 709492519024 93107863549 990677171512 878434244170 777350365410 575870270443 928311965336 349432073756 948390047110 470116186153 495432094032 154258868766 719518553291 580490378718 661863092617 453262793865 191963964294 783054160061 953488248260 99347544...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 764692690700 7...
result:
ok 100001 lines
Test #96:
score: 29
Accepted
time: 144ms
memory: 43148kb
input:
94281 131658172659 39811340435 707706551378 488270943344 316094085836 187344969354 859815132521 257455926058 398461451565 636824600504 968337263051 657378201148 381422070176 704193397218 215057852195 143696981366 245020143023 544889243460 19853724068 381481133078 270430609102 661194702920 9327187294...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 513000148750 5...
result:
ok 94282 lines
Test #97:
score: 29
Accepted
time: 188ms
memory: 51148kb
input:
98013 219274952148 967847968840 993514312942 249215975388 377408063086 409277664478 513688960578 870781013811 5313297905 381786485971 932846528432 355907313844 568982393234 615505455703 556586556337 580222086746 513159753737 447726612888 849878699364 872433100635 459323693660 591180592643 9928561494...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 397148182990 3...
result:
ok 98014 lines
Test #98:
score: 29
Accepted
time: 229ms
memory: 50504kb
input:
100000 793084247557 856407004352 124019471672 758580217324 391555277659 748332370727 824874943785 454763878407 172204390651 200693040566 241971294452 420325832639 276303819033 490288760803 518648078771 428578774460 552156115324 270613111346 564717918818 914239531441 363337438048 359070665547 4058804...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 1347236750935 134723675...
result:
ok 100001 lines
Test #99:
score: 29
Accepted
time: 78ms
memory: 33700kb
input:
100000 186878865231 744364257898 407647146449 178229661742 142659258467 867497410431 566102005411 743741769325 966116499644 374901320569 460953729268 166466122244 599772360298 778326103398 923306353276 541041861259 456336739387 460166266166 277100384431 124520154825 91585321170 808947541069 49305171...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 199304498331 1...
result:
ok 100001 lines
Test #100:
score: 29
Accepted
time: 105ms
memory: 39288kb
input:
100000 701868643554 195683029255 191726673386 60711384096 246001015103 235534486089 867356428487 679339700226 266886499198 165357218261 892542762609 49935133853 78861964822 648163497576 458431664651 259806246005 944174571815 556122544299 640157239681 239448194098 270814892412 832337696089 1764039054...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 786865661638 7...
result:
ok 100001 lines
Test #101:
score: 29
Accepted
time: 172ms
memory: 47736kb
input:
100000 438739740535 795928502119 872639081700 294554691174 226473457726 440783927287 150198126950 915922926283 516380773321 487345449103 452763239700 807838622400 226343342171 740475572228 441100842060 488895978441 476807788781 262972018901 384528067019 387913043837 839407743741 462422811237 7784206...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 865668346868 8...
result:
ok 100001 lines
Test #102:
score: 0
Wrong Answer
time: 219ms
memory: 51588kb
input:
100000 694640698205 388240595320 449732757362 105097389837 586358675392 161335658819 425877820487 740670399542 410740826602 978399832816 430048583471 246136844716 701889327015 378563563646 252509017658 388896850779 573768686022 926987324089 60052463883 832676326751 23069584465 214255472478 621178722...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 5905662632079 6940012991589 6049969362753 6563950643703 6706517228565 5979035434197 7049015775447 6787636040961 6982502711625 6169664677551 6350990061459 6110691370983 6640971888417 6164404198737 6600093406053 6778448883309 5652625763967 6539248535817 621628424...
result:
wrong answer 2nd lines differ - expected: '4111303149419', found: '5905662632079'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%