QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#370217 | #6671. Zadatak | lukap_ | 25 | 305ms | 440856kb | C++14 | 3.6kb | 2024-03-28 23:10:20 | 2024-03-28 23:10:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 1e5 + 500;
const int OFF = (1 << 18);
ll n;
ll niz[MAXN], sazet[MAXN];
vector<ll> v, bizut;
set<ll> vek[2 * MAXN];
ll roots[2 * MAXN],l[MAXN * 200], r[MAXN * 200], lazy[MAXN * 200], vel[2 * MAXN];
ll val[200 * MAXN], pravi[MAXN];
ll cnt;
void novi () {
l[cnt] = -1;
r[cnt] = -1;
cnt++;
}
void prop (ll x, ll lo, ll hi) {
if (lazy[x] == 0) return;
// cout << "BLOOOOOOOOOOOOOOOOOOB " << x << ' ' << uk << ' ' << val[x] << "\n";
val[x] = (pravi[hi] - pravi[lo]) - val[x];
if (hi - lo > 1) {
if (l[x] == -1) {
l[x] = cnt;
novi ();
}
if (r[x] == -1) {
r[x] = cnt;
novi ();
}
// cout << "BIIIIIIIIIIIIRB " << l[x] << ' ' << r[x] << "\n";
lazy[l[x]] = (lazy[l[x]] ^ 1);
lazy[r[x]] = (lazy[r[x]] ^ 1);
}
lazy[x] = 0;
}
void update (ll a, ll b, ll x, ll lo = 0, ll hi = OFF) {
prop (x, lo, hi);
if (hi <= a || lo >= b) return;
if (lo >= a && hi <= b) {
// cout << a << ' ' << b << ' ' << x << ' ' << lo << ' ' << hi << "\n";
lazy[x] = 1;
prop (x, lo, hi);
return;
}
ll mid = (lo + hi) / 2;
if (l[x] == -1) {
l[x] = cnt;
novi ();
}
if (r[x] == -1) {
r[x] = cnt;
novi ();
}
update (a, b, l[x], lo, mid);
update (a, b, r[x], mid, hi);
val[x] = val[l[x]] + val[r[x]];
}
ll query (ll a, ll b, ll x, ll lo = 0, ll hi = OFF) {
// cout << a << ' ' << b << ' ' << x << ' ' << lo << ' ' << hi << " " << val[x] << "\n";
if (hi <= a || lo >= b) return 0;
prop (x, lo, hi);
if (lo >= a && hi <= b) {
// cout << "AAAAAAA " << val[x] << "\n";
return val[x];
}
ll mid = (lo + hi) / 2;
if (l[x] == -1) {
l[x] = cnt;
novi ();
}
if (r[x] == -1) {
r[x] = cnt;
novi ();
}
return query (a, b, l[x], lo, mid) + query (a, b, r[x], mid, hi);
}
ll spoji (ll x, ll y) {
ll cijena = 0;
bizut.clear ();
for (auto it: vek[y]) bizut.push_back(it);
for (int i = (ll) bizut.size () - 1; i >= 0; i-=2) {
ll iduc = 0;
if (i > 0) iduc = bizut[i - 1];
if (iduc == bizut[i]) continue;
cijena += query (iduc, bizut[i], roots[x]);
update (iduc, bizut[i], roots[x]);
}
for (auto it: vek[y]) vek[x].insert (it);
vek[y].clear ();
return cijena;
}
int main () {
ios_base::sync_with_stdio (false);
cin.tie (0);
cout.tie (0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> niz[i];
niz[i] /= 2;
}
for (int i = 0; i < n; i++) v.push_back (niz[i]);
sort (v.begin (), v.end ());
v.resize (unique (v.begin (), v.end ()) - v.begin ());
for (auto it: v) {
int ind = lower_bound (v.begin (), v.end (), it) - v.begin () + 1;
pravi[ind] = 4 * it * it;
}
for (int i = 0; i < n; i++) {
sazet[i] = lower_bound (v.begin (), v.end (), niz[i]) - v.begin () + 1;
roots[i] = cnt;
vel[i] = 1;
novi ();
update (0, sazet[i], roots[i]);
vek[i].insert (sazet[i]);
}
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;b--;
if (vel[b] > vel[a]) swap (a, b);
cout << spoji (a, b) << "\n";
roots[n + i] = roots[a];
swap (vek[n + i], vek[a]);
vel[n + i] = vel[a] + vel[b];
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 16ms
memory: 27340kb
input:
5000 217378 945562 533764 323494 69148 240722 205370 463122 552700 31800 616898 678076 893816 258468 34822 905360 967562 731346 340940 584418 684926 785402 107584 995542 363278 255302 196912 870994 329464 338390 154870 977540 65120 130388 350020 239660 553428 710306 385138 633274 841672 740778 17929...
output:
359872811236 632705703184 113223620400 251229507984 470237900880 0 142492660324 492745033764 0 89244392644 551725099524 278399748496 311560446976 233709556800 476939443200 0 172741415748 92640103936 28418613120 60443205904 0 341931572900 73529592508 193225675856 248612109488 393354817264 21576167436...
result:
wrong answer 4941st lines differ - expected: '238513341228', found: '259607487540'
Subtask #2:
score: 25
Accepted
Test #27:
score: 25
Accepted
time: 189ms
memory: 185616kb
input:
100000 590812 862538 815196 397712 773198 172122 270600 609324 841858 4868 597128 216378 982576 385590 842010 55844 671758 885088 577804 194248 229770 859754 274744 678176 607974 791062 607192 210234 863164 619708 804538 430978 237704 10512 840374 843732 875326 255462 970338 898540 925508 661464 413...
output:
349058819344 315485699072 158174834944 190883984400 29625982884 43598377116 136793375460 505222145492 23697424 122055789444 17217153424 363561360060 92672441524 343745206436 23697424 301341472004 256291624008 271426226484 26531127972 17175971548 316411631620 19435877084 392412501116 57202957148 3506...
result:
ok 99999 lines
Test #28:
score: 0
Accepted
time: 185ms
memory: 185572kb
input:
100000 913682 117898 890276 810502 347306 22864 538414 826942 143310 127564 337302 506318 558582 209656 237462 513864 499810 675334 447848 10990 411390 84222 40766 279716 722086 994224 919524 192682 535352 695818 590360 665246 696722 918458 912368 122190 666212 809412 404714 287478 32068 841084 6417...
output:
13899938404 778691417772 13899938404 106721519232 522762496 182645353668 474268138336 13377175908 2895398188 17642357912 231866740780 58022894616 26313280424 30074921020 219434177672 36923739452 242708805348 36923739452 120780100 132197212548 6691362888 401982396 24764222592 268095202256 32245600944...
result:
ok 99999 lines
Test #29:
score: 0
Accepted
time: 198ms
memory: 185532kb
input:
100000 507122 90654 242520 73476 418742 622326 964126 598470 412334 407164 721486 266314 513046 822986 697796 336946 830820 540476 608754 693100 533912 630638 666914 87756 76234 379552 540464 539728 315224 555708 189024 995492 976558 908034 649638 342698 680534 469620 470852 348752 260296 534244 612...
output:
8218147716 50597802684 5398722576 119348337304 137824385580 249465264696 137824385580 114022802296 55996525260 349357548580 55996525260 100991286316 348112129176 295571036440 98605985580 154247563716 213568759020 144597581880 319081810360 78545547556 289276728272 108427558772 5398722576 412900180 10...
result:
ok 99999 lines
Test #30:
score: 0
Accepted
time: 179ms
memory: 185816kb
input:
100000 718644 544512 122886 8580 497230 333548 159910 500088 936068 710620 14248 545846 153516 19984 602874 720458 875784 173378 426646 877028 686206 317528 16418 15098 783558 248614 247768 573564 103726 845160 803848 683560 141314 519442 610520 668780 852228 396916 440266 840342 749726 992990 42437...
output:
296493318144 0 73616400 15027352596 96226915708 15027352596 146527260100 323516628236 192932570500 129389104 104959512512 8595582364 269971152 264732962844 242858352584 524139262072 13224887196 98029381108 234617054304 275154759252 13224887196 129389104 98560500 376511596632 13183286076 48205695748 ...
result:
ok 99999 lines
Test #31:
score: 0
Accepted
time: 187ms
memory: 185592kb
input:
100000 361496 902432 831032 425268 794678 763240 768850 540792 45902 758564 665288 265052 621098 720810 929344 931166 487360 919890 591972 532922 618490 706178 138296 62060 573414 582282 999636 77724 436984 258482 475488 803006 789246 848650 984428 115276 921484 519482 560806 348758 305488 535564 57...
output:
130679358016 559934827008 130679358016 50173513808 532361783792 58768538708 242282473456 0 335243862244 240175479852 2106993604 211625821248 230982301696 459852840692 403827429644 118319082908 460734444476 173255300572 119200686692 222780032912 216595244528 17018790012 2106993604 185878459508 153173...
result:
ok 99999 lines
Test #32:
score: 0
Accepted
time: 155ms
memory: 185728kb
input:
100000 458016 143770 439276 923266 596052 416814 651478 134766 522454 607972 998784 76152 621572 256700 412836 785722 850812 310430 689956 420360 169490 260706 366350 795482 440358 45394 409266 132240 753674 985316 479516 6092 95264 611604 555084 930522 663744 428096 245744 364686 974444 139864 4688...
output:
20669812900 172293591276 37485064980 317792921724 20669812900 239024947556 18161874756 84916957584 270361029120 527265445936 5799127104 281283700416 8307065248 57587824752 247678556964 369680504320 38778960148 266487421568 42079307848 20419794852 45475095148 60338060888 295969224572 79899283164 2060...
result:
ok 99999 lines
Test #33:
score: 0
Accepted
time: 205ms
memory: 185684kb
input:
100000 533666 696320 262670 284338 690592 333812 393056 40968 814424 139758 306688 57362 219200 525864 570124 29738 564422 994742 207428 280450 226788 639786 757060 192880 622690 886726 54116 83392 15100 141996 666406 545516 915040 563728 378356 106888 91502 554120 947382 133964 527088 243770 627356...
output:
284799399556 0 68995528900 203970480252 99577882000 54915137136 1678377024 236150117332 1678377024 29706490884 1678377024 30128363456 95139164336 221635757980 884348644 102521268752 546351769796 17035927900 46937336184 22058192716 110038911072 307231446660 20166766500 106908072472 559700796796 79402...
result:
ok 99999 lines
Test #34:
score: 0
Accepted
time: 190ms
memory: 185616kb
input:
100000 167378 28694 202000 478774 796490 207126 153224 221646 230436 443470 130314 637844 885244 268340 38058 723802 902786 547190 970560 154532 591652 938406 38668 901198 224062 366966 529694 271874 524566 205478 14684 300050 236778 988774 839334 363992 428038 331408 584242 151980 865240 432536 966...
output:
823345636 27192049248 13611950752 215612592324 13611950752 22654248540 7458326220 41668623096 11432127000 16158392960 347518891836 286877428264 45239181276 625065728 329245164792 343904789848 221817092556 326900482936 16759217716 212178796148 469761538300 625065728 408224638712 35528509504 335808758...
result:
ok 99999 lines
Test #35:
score: 0
Accepted
time: 186ms
memory: 185588kb
input:
100000 298902 476220 894534 252224 422758 27040 992342 547792 757486 326634 311428 469720 893396 542262 195244 377402 110598 110498 499402 631008 423784 376594 936466 148350 616148 233430 864034 687488 933072 681050 187362 592738 83316 16360 738982 629774 88892 754812 957978 931254 226082 481478 352...
output:
89342405604 137443082796 63616946176 25725459428 731161600 725673294292 74517782864 225558292400 26456621028 70530778156 78071543636 422422909696 145334131880 37389057936 69615381468 11500756004 731161600 115235445496 140194910728 109086835496 69028262300 524310773856 753271200 195510366928 16865768...
result:
ok 99999 lines
Test #36:
score: 0
Accepted
time: 183ms
memory: 185636kb
input:
100000 498430 58252 342546 736144 5384 916206 275612 487494 685580 555870 618832 352168 530374 446456 994456 569060 477758 518302 603680 167082 526468 462788 962300 941694 325192 254888 61564 499870 682288 639356 240734 567550 147572 166662 252242 985022 6332 46826 441202 9626 57138 919176 694290 36...
output:
3393295504 113944466612 134487998288 0 407448977904 3364308048 192910304416 55522160484 253469296416 129483747808 79282204604 191232310408 79282204604 543110035096 165311586380 120040755332 118994016096 217938082932 24552086676 106337829288 141228533960 298511652036 627509637964 51409887868 24552086...
result:
ok 99999 lines
Test #37:
score: 0
Accepted
time: 193ms
memory: 185612kb
input:
100000 574414 564886 944758 449184 94972 744526 822772 181910 400468 105932 64654 750164 10896 539366 677904 826510 690752 751660 558650 215130 525930 460524 247008 20280 352116 8340 816242 609536 853234 504966 306440 469008 734736 259764 15342 210702 962988 969898 246370 44006 57566 529686 292944 7...
output:
319096192996 10855250400 201766265856 0 350717129204 326236634780 9019680784 24071567316 9019680784 0 475362866900 0 68219570192 233551362164 240594549388 251135854452 305429838928 222696111764 26827923360 60844640372 151237714204 19452993540 118722816 41733791292 69555600 347393180136 151410756632 ...
result:
ok 99999 lines
Test #38:
score: 0
Accepted
time: 220ms
memory: 185788kb
input:
100000 262888 339376 359222 731440 809850 578820 222738 431780 226708 970502 608320 600178 337696 796886 44286 787138 236840 656292 656112 975654 898764 280176 846280 932670 835558 491102 514240 807466 540508 682718 260126 794640 16302 694468 474220 393902 844498 382636 398806 426296 366804 148194 4...
output:
69110100544 46065968832 82974476452 452029997148 82974476452 0 153071708592 1784300620 350641348732 140264422568 229788799832 46712788492 315989094484 0 305558386356 52347635184 161140475584 269578713680 566647702656 375226429348 16762465360 385937069308 421839658388 367904402272 120914044712 143528...
result:
ok 99999 lines
Test #39:
score: 0
Accepted
time: 178ms
memory: 185668kb
input:
100000 576860 910562 647862 258690 525388 67780 350424 458472 158406 123700 292750 209434 123000 400682 317368 570896 606614 257944 346238 639198 816402 18506 927480 537272 311746 778586 858350 614590 393332 682058 947772 254110 461166 452666 199752 843984 274294 598160 93492 471878 355446 872330 82...
output:
332767459600 86957711444 66920516100 209112034444 4594128400 62326387700 60470592076 20498332436 4594128400 52535616864 14384899236 10534871600 80068089668 58403443104 163933738604 168833720996 23536957920 80938500836 176611766268 478749371496 342472036 350031312312 184866033980 35062900864 36476467...
result:
ok 99999 lines
Subtask #3:
score: 0
Wrong Answer
Test #40:
score: 0
Wrong Answer
time: 305ms
memory: 440856kb
input:
65536 131908 883754 813278 197778 704074 981802 297078 903698 485360 496064 726120 251990 462786 129558 704500 920556 903884 454552 949354 328526 921462 975888 780002 276668 675308 49774 83014 136308 679916 42174 151084 358830 284218 259680 65684 526980 516764 200170 265060 294150 128046 658864 2984...
output:
17399720464 39116137284 495720197476 88255338084 235574329600 63498960100 16785275364 496320250000 206617520704 107929332676 849092217444 76545182224 2477451076 6891324196 1778646276 22826375056 67433702400 4314387856 40068028900 70256803600 16395778116 89086728676 242284466176 8531108496 4721146752...
result:
wrong answer 64914th lines differ - expected: '233053340912', found: '226775682032'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%