QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#406915 | #6969. 幻想乡战略游戏 | oyzr | 5 | 266ms | 46624kb | C++20 | 3.9kb | 2024-05-07 19:49:07 | 2024-05-07 19:49:23 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1e5 + 5, MAXM = 2e5 + 5, MAXLOGN = 20;
class graph{
public:
struct Edge{
int v, c, next;
}t[MAXM];
int h[MAXN], tot;
/**
* @brief 清空图
*/
void init(){
memset(h, 0, sizeof(h));
tot = 0;
}
/**
* @brief 建边
* @param u 边的起点
* @param v 边的终点
* @param c 边的权值
*/
void addEdge(int u, int v, int c){
++tot;
t[tot].v = v;
t[tot].c = c;
t[tot].next = h[u];
h[u] = tot;
}
};
class point_split_tree{
private:
const static int MAXNODE = MAXN, MAXDEP = MAXLOGN;
//原树
int size[MAXNODE];
int dis[MAXNODE][MAXDEP];
//新树
int f[MAXNODE][2];
int sum[MAXNODE];
int point[MAXNODE];
bool del[MAXNODE];
int fa[MAXNODE];
int depth[MAXNODE];
int getSize(int u, int fa){
size[u] = 1;
for (int i = G.h[u]; i; i = G.t[i].next){
int v = G.t[i].v, c = G.t[i].c;
if (v == fa || del[v])
continue;
size[u] += getSize(v, u);
}
return size[u];
}
int getRoot(int u, int fa, int rtSize){
for (int i = G.h[u]; i; i = G.t[i].next){
int v = G.t[i].v;
if (v == fa || del[v])
continue;
if (size[v] * 2 > rtSize)
return getRoot(v, u, rtSize);
}
return u;
}
void getDis(int u, int fa, int d, int rtDep, int &a, int &b, int &c, int &e){
a += d * val[u];
b += d * val[u];
c += val[u];
e += val[u];
dis[u][rtDep] = d;
for (int i = G.h[u]; i; i = G.t[i].next){
int v = G.t[i].v, c = G.t[i].c;
if (v == fa || del[v])
continue;
getDis(v, u, d + c, rtDep, a, b, c, e);
}
}
void buildTree(int u, int dep){
depth[u] = dep;
del[u] = true;
getSize(u, 0);
sum[u] += val[u];
for (int i = G.h[u]; i; i = G.t[i].next){
int v = G.t[i].v, c = G.t[i].c;
if (del[v])
continue;
int rt = getRoot(v, u, getSize(v, u));
Gnew.addEdge(u, rt, 0);
fa[rt] = u;
point[rt] = v;
getDis(v, u, c, dep, f[u][0], f[rt][1], sum[rt], sum[u]);
buildTree(rt, dep + 1);
}
}
public:
//原树
int val[MAXNODE];
graph G;
graph Gnew;
void init(){
buildTree(1, 1);
}
void change(int pos, int val){
for (int i = pos; i; i = fa[i]){
f[i][0] += dis[pos][depth[i]] * val;
sum[i] += val;
if (depth[i] != 1)
f[i][1] += dis[pos][depth[i] - 1] * val;
}
}
int query(int pos){
int res = f[pos][0];
for (int i = pos; fa[i]; i = fa[i]){
res += f[fa[i]][0] + sum[fa[i]] * dis[pos][depth[i] - 1];
res -= f[i][1] + sum[i] * dis[pos][depth[i] - 1];
}
return res;
}
int solve(int u, int ans){
for (int i = Gnew.h[u]; i; i = Gnew.t[i].next){
int v = Gnew.t[i].v;
int res = query(point[v]);
if (res < ans)
return solve(v, res);
}
return ans;
}
};
graph G;
point_split_tree PST;
signed main(){
int n, m;
cin >> n >> m;
for (int i = 1; i <= n - 1; i++){
int u, v, c;
cin >> u >> v >> c;
G.addEdge(u, v, c);
G.addEdge(v, u, c);
}
PST.G = G;
PST.init();
int ans = 0;
while (m--){
int pos, val;
cin >> pos >> val;
PST.change(pos, val);
cout << PST.solve(1, PST.query(1)) << endl;
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 22180kb
input:
5000 2000 1 2 701 2 3 811 3 4 548 4 5 703 5 6 32 6 7 435 7 8 368 8 9 978 9 10 68 10 11 550 11 12 667 12 13 270 13 14 486 14 15 217 15 16 486 16 17 326 17 18 418 18 19 361 19 20 344 20 21 116 21 22 373 22 23 38 23 24 563 24 25 591 25 26 800 26 27 94 27 28 210 28 29 548 29 30 278 30 31 169 31 32 1000 ...
output:
1042280 44167318 129947038 235928738 291848490 1031074026 1039321389 838783878 1074759454 1275552241 1496436865 1630065836 1790533824 2011408791 2349404883 2449941655 2607510847 2693947880 2849529711 2877352231 2885278221 3010486605 3017429085 3193336323 3265441525 3359362606 3685811046 3869008096 3...
result:
wrong answer 1st numbers differ - expected: '0', found: '1042280'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 22304kb
input:
5000 2000 1 2 576 2 3 745 3 4 672 4 5 812 5 6 770 6 7 261 7 8 191 8 9 534 9 10 209 10 11 576 11 12 184 12 13 212 13 14 996 14 15 466 15 16 360 16 17 127 17 18 180 18 19 804 19 20 74 20 21 504 21 22 912 22 23 253 23 24 113 24 25 418 25 26 723 26 27 596 27 28 92 28 29 845 29 30 215 30 31 96 31 32 224 ...
output:
157104887 98832099 187877856 190275504 293908948 342799252 602701560 605991335 978624595 1093348465 1279808917 1469314849 1510134943 1617400731 1640723079 1738820727 1743464899 2069047987 2162511133 2171043516 2171301741 2308220877 2318976013 2348883373 2385728483 2501410253 2759075789 2826583481 29...
result:
wrong answer 1st numbers differ - expected: '0', found: '157104887'
Test #3:
score: 0
Wrong Answer
time: 6ms
memory: 20332kb
input:
5000 2000 1 2 149 2 3 122 3 4 778 4 5 764 5 6 514 6 7 905 7 8 289 8 9 151 9 10 976 10 11 315 11 12 429 12 13 517 13 14 488 14 15 679 15 16 354 16 17 597 17 18 583 18 19 378 19 20 128 20 21 990 21 22 123 22 23 893 23 24 859 24 25 140 25 26 188 26 27 142 27 28 620 28 29 735 29 30 662 30 31 261 31 32 9...
output:
4462206 30695168 36080264 436437648 457408611 676805715 676885040 718838190 881919690 882676790 1054964980 1106359049 1116209688 1144167618 1639689766 1665390475 1982544148 2086941700 2091659536 2189533060 2193754348 2267987458 2455353742 2588570392 2593878424 2614355487 2686489955 2765272715 279285...
result:
wrong answer 1st numbers differ - expected: '0', found: '4462206'
Test #4:
score: 0
Wrong Answer
time: 192ms
memory: 44580kb
input:
100000 100000 1 2 31 2 3 400 3 4 488 4 5 524 5 6 665 6 7 63 7 8 381 8 9 375 9 10 936 10 11 157 11 12 657 12 13 346 13 14 408 14 15 288 15 16 138 16 17 785 17 18 15 18 19 109 19 20 319 20 21 659 21 22 773 22 23 703 23 24 995 24 25 974 25 26 159 26 27 163 27 28 468 28 29 915 29 30 245 30 31 634 31 32 ...
output:
1570603740 8580394450 22263441753 28144392957 35948586725 41376387695 53413640855 70041831459 72888863907 74091590354 77913715139 93395124361 100693273031 101897488303 103840745101 105202379326 113299573740 124627913378 126456708254 129151682927 130365244453 140132527380 143772468231 148605639756 16...
result:
wrong answer 1st numbers differ - expected: '0', found: '1570603740'
Test #5:
score: 0
Wrong Answer
time: 180ms
memory: 46624kb
input:
100000 100000 1 2 460 2 3 195 3 4 548 4 5 573 5 6 835 6 7 147 7 8 107 8 9 619 9 10 881 10 11 982 11 12 185 12 13 152 13 14 98 14 15 153 15 16 14 16 17 925 17 18 651 18 19 226 19 20 175 20 21 968 21 22 25 22 23 695 23 24 597 24 25 353 25 26 803 26 27 958 27 28 598 28 29 535 29 30 330 30 31 743 31 32 ...
output:
1333884105 6869202150 8590033189 20942263067 41894090407 45275929878 49497514086 52877742168 57814378452 61555908042 78327457164 93840847028 99828446390 99934842020 101013101249 109345169084 117876864105 134615753506 140163060898 142867046570 148940871974 157062564004 161088296740 169713953977 17031...
result:
wrong answer 1st numbers differ - expected: '0', found: '1333884105'
Test #6:
score: 0
Wrong Answer
time: 191ms
memory: 41888kb
input:
100000 100000 1 2 121 2 3 761 1 4 427 1 5 833 1 6 28 6 7 336 5 8 977 8 9 347 1 10 124 3 11 13 10 12 525 4 13 407 7 14 546 3 15 279 2 16 707 11 17 835 13 18 300 17 19 138 6 20 763 3 21 607 17 22 118 22 23 192 7 24 865 21 25 86 23 26 98 10 27 691 25 28 643 20 29 285 10 30 526 24 31 194 8 32 227 31 33 ...
output:
243848 4330352 11929567 12924462 17855554 21198058 24537382 28404326 31235630 37238909 41457497 44153177 46367587 48542539 48979206 53792475 57142878 60713086 63117418 69318778 72151672 74564208 76224438 80214018 81348649 82938589 85545349 85600149 88350213 94639672 97551658 98692936 100619614 10145...
result:
wrong answer 1st numbers differ - expected: '0', found: '243848'
Test #7:
score: 0
Wrong Answer
time: 189ms
memory: 43184kb
input:
100000 100000 1 2 76 1 3 842 1 4 532 1 5 416 2 6 353 3 7 770 4 8 416 5 9 241 6 10 682 7 11 639 8 12 302 9 13 785 10 14 784 11 15 607 12 16 889 13 17 792 14 18 891 15 19 663 16 20 88 17 21 854 18 22 681 19 23 95 20 24 81 21 25 175 22 26 329 23 27 558 24 28 422 25 29 850 26 30 919 27 31 674 28 32 474 ...
output:
2713482254 2787166459 6640436583 13501453783 17001718239 20527477585 21221756791 21677688440 29217844736 31079526416 39837886820 42766863995 43311506798 44675938098 45227927586 53320789257 53524963982 58935150002 60142944888 64659903596 65420584367 77280628303 77307909463 78481309735 83871278773 841...
result:
wrong answer 1st numbers differ - expected: '0', found: '2713482254'
Test #8:
score: 5
Accepted
time: 186ms
memory: 42028kb
input:
100000 100000 1 2 788 1 3 928 2 4 165 2 5 545 3 6 762 3 7 259 4 8 786 4 9 494 5 10 881 5 11 172 6 12 371 6 13 908 7 14 884 7 15 398 8 16 995 8 17 914 9 18 464 9 19 684 10 20 300 10 21 706 11 22 398 11 23 134 12 24 818 12 25 927 13 26 557 13 27 323 14 28 344 14 29 394 15 30 990 15 31 819 16 32 904 16...
output:
0 13759914 16740024 18992578 22378132 23867055 28122747 30335307 31749537 36290022 45900805 51670102 52846582 56682532 59579852 63392221 69141725 76492224 79540010 80805718 81557318 82453646 86256913 87664693 92106913 98535653 100697649 104040813 109689267 116355009 119615745 127498560 129757164 133...
result:
ok 100000 numbers
Test #9:
score: 0
Wrong Answer
time: 248ms
memory: 43528kb
input:
100000 100000 1 2 494 2 3 30 3 4 81 4 5 890 5 6 547 6 7 811 7 8 245 8 9 175 9 10 126 10 11 871 11 12 826 12 13 705 13 14 527 14 15 360 15 16 447 16 17 800 17 18 794 18 19 340 19 20 789 20 21 335 21 22 873 22 23 826 23 24 770 24 25 537 25 26 591 26 27 523 27 28 455 28 29 599 29 30 912 30 31 789 31 32...
output:
1981476098 3339881954 4132671170 5572338458 7853679608 11913556352 19450848436 23039882744 28354622252 33706520177 34187694563 34857911203 36133617013 38638704907 40170011901 43499064405 45668328581 45741654014 48111954206 50841021034 51391252769 51991424345 53719161653 55788465497 56336480488 59688...
result:
wrong answer 1st numbers differ - expected: '0', found: '1981476098'
Test #10:
score: 0
Wrong Answer
time: 254ms
memory: 41948kb
input:
100000 100000 1 2 386 2 3 954 3 4 980 4 5 584 5 6 346 6 7 854 7 8 763 8 9 824 9 10 909 10 11 174 11 12 635 12 13 498 13 14 578 14 15 468 15 16 248 16 17 739 17 18 175 18 19 531 19 20 93 20 21 939 21 22 795 22 23 250 23 24 54 24 25 124 25 26 273 26 27 758 27 28 597 28 29 279 29 30 149 30 31 869 31 32...
output:
988527858 2177491450 4645588637 4781778747 11209232155 14148377529 14712123721 16622382470 18932244134 19474780766 20318924524 20556268624 25093110920 26063380126 31645147878 31892406579 33324231099 34362636148 35027885052 38119827342 39415995397 41732588333 45366329594 45960882394 46493541508 46958...
result:
wrong answer 1st numbers differ - expected: '0', found: '988527858'
Test #11:
score: 0
Wrong Answer
time: 228ms
memory: 42064kb
input:
100000 100000 1 2 126 2 3 500 3 4 234 4 5 710 5 6 254 6 7 818 7 8 959 8 9 242 9 10 768 10 11 479 11 12 5 12 13 453 13 14 774 14 15 371 15 16 170 16 17 685 17 18 202 18 19 992 19 20 647 20 21 307 21 22 925 22 23 410 23 24 328 24 25 153 25 26 807 26 27 719 27 28 590 28 29 812 29 30 515 30 31 778 31 32...
output:
1645884654 1408231094 5490904326 5956465240 6318513196 12994056436 16259340660 22188529921 22393570976 23350040624 30839211284 31690500519 35839641359 39898247029 40239205549 41979816191 45497929107 46312479827 51912264577 54357709369 55640863419 56184393531 56356947178 58314094072 63965389046 67650...
result:
wrong answer 1st numbers differ - expected: '0', found: '1645884654'
Test #12:
score: 0
Wrong Answer
time: 222ms
memory: 42216kb
input:
100000 100000 1 2 949 2 3 876 3 4 748 4 5 477 5 6 381 6 7 771 7 8 32 8 9 235 9 10 81 10 11 184 11 12 358 12 13 786 13 14 421 14 15 673 15 16 841 16 17 184 17 18 556 18 19 350 19 20 930 20 21 584 21 22 882 22 23 109 23 24 189 24 25 160 25 26 883 26 27 817 27 28 234 28 29 150 29 30 817 30 31 254 31 32...
output:
4267504548 5525606378 6358878194 12565574519 16414171503 17708492219 22688743579 24473319603 29067484266 30818399502 31005356676 34064474514 34338254270 34637753789 42716985539 42719967779 45221058049 46586297617 46757786197 49281365839 53834726174 55464310804 57577690818 61797377506 66232196202 663...
result:
wrong answer 1st numbers differ - expected: '0', found: '4267504548'
Test #13:
score: 0
Wrong Answer
time: 257ms
memory: 41832kb
input:
100000 100000 1 2 973 2 3 609 3 4 712 4 5 864 5 6 415 6 7 296 7 8 367 8 9 407 9 10 987 10 11 396 11 12 942 12 13 406 13 14 109 14 15 178 15 16 95 16 17 60 17 18 647 18 19 895 19 20 347 20 21 857 21 22 887 22 23 800 23 24 280 24 25 166 25 26 144 26 27 929 27 28 138 28 29 118 29 30 408 30 31 703 31 32...
output:
3549804417 3766738272 4939897220 16154743580 17550556029 23874165208 25035526061 25450707737 25639865030 28453775638 30405513475 31014655561 34050349684 34505992245 35492539509 35812870661 37592651873 38503129086 39641510814 40627920994 43228632368 43449019128 43503250877 46225743747 50641207221 524...
result:
wrong answer 1st numbers differ - expected: '0', found: '3549804417'
Test #14:
score: 0
Wrong Answer
time: 244ms
memory: 41940kb
input:
100000 100000 1 2 249 2 3 541 3 4 679 4 5 789 5 6 301 6 7 218 7 8 281 8 9 730 9 10 906 10 11 54 11 12 568 12 13 610 13 14 445 14 15 120 15 16 370 16 17 214 17 18 876 18 19 701 19 20 935 20 21 227 21 22 492 22 23 280 23 24 627 24 25 1 25 26 451 26 27 163 27 28 554 28 29 759 29 30 386 30 31 150 31 32 ...
output:
2248887564 3905603624 8765925015 12015495340 13037376523 13760726742 16359639524 16673112848 20634593636 21578743883 23504371403 26969233346 30952749820 32325872844 33034518834 35115401114 35265588602 39709389866 42309336749 42842280813 49212628671 49499766627 56806058592 57055995232 58537380137 596...
result:
wrong answer 1st numbers differ - expected: '0', found: '2248887564'
Test #15:
score: 0
Wrong Answer
time: 266ms
memory: 42308kb
input:
100000 100000 1 2 24 2 3 258 3 4 408 4 5 587 5 6 611 6 7 919 7 8 412 8 9 229 9 10 579 10 11 931 11 12 77 12 13 824 13 14 174 14 15 492 15 16 513 16 17 904 17 18 903 18 19 147 19 20 219 20 21 753 21 22 578 22 23 658 23 24 288 24 25 816 25 26 592 26 27 988 27 28 433 28 29 643 29 30 392 30 31 663 31 32...
output:
953500512 1112245086 1664524026 1739230182 6531800211 7867905991 9868859664 10688669006 14094671333 21154179731 21659933336 22523339454 25126707745 25830767569 30157035825 30406345475 30958477655 34849373741 36226109310 37274504434 38993322856 39217605046 41255053210 46509918778 47031854733 48216574...
result:
wrong answer 1st numbers differ - expected: '0', found: '953500512'
Test #16:
score: 0
Wrong Answer
time: 246ms
memory: 42128kb
input:
100000 100000 1 2 567 2 3 812 3 4 146 4 5 65 5 6 419 6 7 86 7 8 920 8 9 832 9 10 130 10 11 53 11 12 894 12 13 247 13 14 137 14 15 712 15 16 282 16 17 393 17 18 618 18 19 535 19 20 799 20 21 227 21 22 355 22 23 181 23 24 767 24 25 350 25 26 42 26 27 710 27 28 378 28 29 428 29 30 595 30 31 234 31 32 6...
output:
117903240 2177012225 2194379308 2482790396 5528031560 11442424072 14846100370 15663402616 18142921541 20794000097 21735178688 22927373455 23499107545 28885147862 33469858094 35552296144 36230675657 39324921503 41027362395 41831277065 48214197755 48419980885 49940905857 52337687117 54848769472 549392...
result:
wrong answer 1st numbers differ - expected: '0', found: '117903240'
Test #17:
score: 0
Wrong Answer
time: 249ms
memory: 43516kb
input:
100000 100000 1 2 408 2 3 524 3 4 486 4 5 497 5 6 598 6 7 638 7 8 752 8 9 365 9 10 217 10 11 192 11 12 711 12 13 282 13 14 659 14 15 134 15 16 240 16 17 128 17 18 651 18 19 975 19 20 113 20 21 159 21 22 861 22 23 111 23 24 957 24 25 814 25 26 386 26 27 25 27 28 791 28 29 446 29 30 151 30 31 790 31 3...
output:
417542410 3381282175 8469754062 15169640577 16070969425 21295497955 21341908783 21455953813 21710283093 22149224847 22865612883 23320510170 28615038954 36252509109 38774963813 40097905361 43578973133 47073620204 48880887654 55405995529 58545578086 59270318276 65669994416 65774519094 69119966459 7236...
result:
wrong answer 1st numbers differ - expected: '0', found: '417542410'
Test #18:
score: 0
Wrong Answer
time: 239ms
memory: 43536kb
input:
100000 100000 1 2 716 2 3 57 3 4 220 4 5 368 5 6 120 6 7 843 7 8 313 8 9 211 9 10 444 10 11 886 11 12 40 12 13 811 13 14 938 14 15 14 15 16 745 16 17 725 17 18 247 18 19 592 19 20 92 20 21 483 21 22 645 22 23 393 23 24 294 24 25 247 25 26 25 26 27 667 27 28 432 28 29 852 29 30 644 30 31 694 31 32 86...
output:
4896866940 7711196668 8874195706 9440803031 10518589103 12821905503 14417165434 14728003060 15243069848 16960620980 17415190528 17766457502 18371971310 19856442830 22334478046 27241096906 31727494855 36629429617 38408988112 39196305692 40093696164 41809202556 43668475248 43713476778 44805290226 4575...
result:
wrong answer 1st numbers differ - expected: '0', found: '4896866940'
Test #19:
score: 0
Wrong Answer
time: 246ms
memory: 42056kb
input:
100000 100000 1 2 405 2 3 375 3 4 830 4 5 199 5 6 993 6 7 711 7 8 797 8 9 864 9 10 402 10 11 809 11 12 852 12 13 250 13 14 5 14 15 268 15 16 403 16 17 63 17 18 589 18 19 502 19 20 568 20 21 663 21 22 922 22 23 605 23 24 824 24 25 585 25 26 169 26 27 951 27 28 65 28 29 116 29 30 71 30 31 561 31 32 31...
output:
1254480920 2924611175 6967300475 7350507245 8065998653 12085790525 13634640057 15225656457 15834156347 16425815365 18109690021 18345818551 19945659376 20329478452 22857770348 26963436710 27791938195 35473278587 36110298887 40329153107 41497925027 42218272642 45143233042 47750454254 49188083278 49492...
result:
wrong answer 1st numbers differ - expected: '0', found: '1254480920'
Test #20:
score: 0
Wrong Answer
time: 230ms
memory: 41844kb
input:
100000 100000 1 2 246 2 3 34 3 4 21 4 5 38 5 6 476 6 7 769 7 8 511 8 9 127 9 10 165 10 11 71 11 12 638 12 13 416 13 14 29 14 15 681 15 16 594 16 17 708 17 18 560 18 19 948 19 20 433 20 21 773 21 22 963 22 23 302 23 24 194 24 25 676 25 26 414 26 27 229 27 28 790 28 29 474 29 30 517 30 31 279 31 32 53...
output:
1382919216 2068930178 2114137268 3680817356 4819242138 6529217818 6770229268 7310312339 9223848251 10045626376 13013792028 13299118607 20171906347 21498797341 26960001187 29059020392 29337328193 30335341853 32950294480 37040440930 38068437696 39863489497 44088227937 47569187037 48303473551 538089922...
result:
wrong answer 1st numbers differ - expected: '0', found: '1382919216'