QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#140542 | #4401. Prize | APROHACK | 10 | 836ms | 283676kb | C++23 | 5.8kb | 2023-08-16 07:19:46 | 2023-08-16 07:19:47 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ff first
#define ss second
using namespace std;
int n, q, k, t;
int roots[2];
vector<int>child[500005][2];
vector<int>childReal[500005][2];
vector<int>chosen;
bool isChosen[500005];
int lca[500005][20][2];
int distancia[500005][20][2];
int deep[5000005][2];
void bfs(int s, int tri = 0){
queue<pair<int, int > >cola; // node, deep
cola.push({s, 0});
while(!cola.empty() and chosen.size() < k){
auto cur = cola.front();
cola.pop();
chosen.pb(cur.ff);
deep[cur.ff][tri] = cur.ss;
isChosen[cur.ff] = true;
for(int i = 0 ; i < child[cur.ff][tri].size() ; i ++){
lca[child[cur.ff][tri][i]][0][tri] = cur.ff;
cola.push({child[cur.ff][tri][i], cur.ss + 1});
}
}
}
int getDist(int a, int b, int tri){
if(deep[a][tri] < deep[b][tri])swap(a, b);
int dd = deep[a][tri] - deep[b][tri];
int ans = 0;
for(int i = 19 ; i >= 0 ; i --){
if(dd & (1<<i)){
ans += distancia[a][i][tri];
a = lca[a][i][tri];
}
}
if(a == b)return ans;
for(int i = 19 ; i >= 0 ; i --){
if(lca[a][i][tri] != lca[b][i][tri]){
ans += distancia[a][i][tri];
ans += distancia[b][i][tri];
a = lca[a][i][tri];
b = lca[b][i][tri];
}
}
ans += distancia[a][0][tri] + distancia[b][0][tri];
return ans;
}
struct estado{
int node;
int deep;
int arbol;
};
void bfs2(int s1, int s2){
queue<estado >cola; // node, deep
cola.push({s1, 0, 0});
cola.push({s2, 0, 1});
while(!cola.empty() and chosen.size() < k){
auto cur = cola.front();
int nd = cur.node;
int prof = cur.deep;
int tri = cur.arbol;
cola.pop();
if(!isChosen[nd]){
chosen.pb(nd);
isChosen[nd] = true;
}
for(int i = 0 ; i < child[nd][tri].size() ; i ++){
lca[child[nd][tri][i]][0][tri] = nd;
cola.push({child[nd][tri][i], prof + 1, tri});
}
}
}
void dfs(int nd, int tri, int last, int dip){
if(last != -1 and isChosen[nd]){
childReal[last][tri].pb(nd);
lca[nd][0][tri] = last;
}
if(isChosen[nd]){
last = nd;
deep[nd][tri] = dip;
dip ++ ;
}
for(int i = 0 ; i < child[nd][tri].size() ; i ++){
int &nx = child[nd][tri][i];
dfs(nx, tri, last, dip);
}
}
void getChildReal(){
dfs(roots[0], 0, -1, 0);
dfs(roots[1], 1, -1, 0);
}
int main(){
ios::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
/*
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
* */
cin >> n >> k >> q >> t;
memset(isChosen, false, sizeof isChosen);
int temp;
for(int i = 1 ; i <= n ; i ++){
cin >> temp;
if(temp == -1)roots[0] = i;
else child[temp][0].pb(i);
}
for(int i = 1 ; i <= n ; i ++){
cin >> temp;
if(temp == -1)roots[1] = i;
else child[temp][1].pb(i);
}
if(q == k-1){
bfs(roots[0]);
for(auto i : chosen)cout << i << " ";
cout << endl;
vector<int>questions;
for(int i = 0 ; i < k ; i ++){
for(int j = 0 ; j < child[chosen[i]][0].size() ; j ++){
if(isChosen[child[chosen[i]][0][j]]){
questions.pb(child[chosen[i]][0][j]);
}
}
}
for(int i = 0 ; i < questions.size() ; i ++){
cout << "? " << questions[i] << " " << lca[questions[i]][0][0] << endl;
}
cout << "!" << endl;
for(int i = 0 ; i < questions.size() ; i ++){
int a, b;
cin >> a >> b >> a >> b;
distancia[questions[i]][0][0] = a;
}
lca[roots[0]][0][0] = roots[0];
distancia[roots[0]][0][0] = 0;
for(int x = 1 ; x < 20 ; x ++){
for(auto i : chosen){
lca[i][x][0] = lca[lca[i][x-1][0]][x-1][0];
distancia[i][x][0] = distancia[lca[i][x-1][0]][x-1][0] + distancia[i][x-1][0];
//lca[i][x][1] = lca[lca[i][x-1][1]][x-1][1];
}
}
vector<pair<int, int> > queries;
for(int i = 0 ; i < t ; i ++){
int a, b;
cin >> a >> b;
queries.pb({a, b});
}
for(int i = 0 ; i < t ; i ++){
cout << getDist(queries[i].ff, queries[i].ss, 0) << " " << getDist(queries[i].ff, queries[i].ss, 0) << "\n";
}
cout << endl;
}else{
vector<int>questions2;
bfs2(roots[0], roots[1]);
for(auto i : chosen) cout << i << " ";
cout << endl;
vector<pair<int, int > >q1, q2; // child, parent
getChildReal();
for(int i = 0 ; i < k ; i ++){
for(int j = 0 ; j < childReal[chosen[i]][0].size() ; j ++){
q1.pb({childReal[chosen[i]][0][j], chosen[i]});
}
}
for(int i = 0 ; i < k ; i ++){
for(int j = 0 ; j < childReal[chosen[i]][1].size() ; j ++){
q2.pb({childReal[chosen[i]][1][j], chosen[i]});
}
}
for(int i = 0 ; i < q1.size() ; i ++){
cout << "? " << q1[i].ff << " " << q1[i].ss << endl;
}
for(int i = 0 ; i < q2.size() ; i ++){
cout << "? " << q2[i].ff << " " << q2[i].ss << endl;
}
cout << "!" << endl;
for(int i = 0 ; i < q1.size() ; i ++){
int a, b;
cin >> a >> b;
distancia[q1[i].ff][0][0] = a;
cin >> a >> b;
}
for(int i = 0 ; i < q2.size() ; i ++){
int a, b;
cin >> a >> b >> a >> b;
distancia[q2[i].ff][0][1] = a;
}
lca[roots[0]][0][0] = roots[0];
distancia[roots[0]][0][0] = 0;
lca[roots[1]][0][1] = roots[1];
distancia[roots[1]][0][1] = 0;
for(int x = 1 ; x < 20 ; x ++){
for(auto i : chosen){
lca[i][x][0] = lca[lca[i][x-1][0]][x-1][0];
distancia[i][x][0] = distancia[lca[i][x-1][0]][x-1][0] + distancia[i][x-1][0];
lca[i][x][1] = lca[lca[i][x-1][1]][x-1][1];
distancia[i][x][1] = distancia[lca[i][x-1][1]][x-1][1] + distancia[i][x-1][1];
}
}
vector<pair<int, int> > queries;
for(int i = 0 ; i < t ; i ++){
int a, b;
cin >> a >> b;
queries.pb({a, b});
}
for(int i = 0 ; i < t ; i ++){
cout << getDist(queries[i].ff, queries[i].ss, 0) << " " << getDist(queries[i].ff, queries[i].ss, 1) << "\n";
}
cout << endl;
}
int ready;
//~ cin >> ready;
return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 432ms
memory: 243688kb
input:
500000 64682 64681 100000 46115 470589 209303 2979 473162 343535 79503 299539 404621 102085 237721 279170 392890 165201 441593 456314 218991 358478 86614 410800 159785 169761 95368 285837 297549 370283 378974 26449 444381 39320 149913 404523 144109 174828 263837 49847 468694 478535 152644 216598 301...
output:
422989 414496 290928 388223 160563 301045 470257 259625 222733 231286 345214 169817 435263 277447 386014 210139 455433 225855 264772 199736 355788 288506 233893 146148 454958 267562 498596 183745 352665 151125 266374 43142 9414 204593 212097 311775 25324 300764 6643 94847 396968 428563 311355 255767...
result:
ok good job!
Test #2:
score: 0
Accepted
time: 509ms
memory: 243904kb
input:
500000 90967 90966 100000 122547 312039 290084 118442 352297 175176 294396 496975 127062 90539 132654 408480 493670 419897 53432 141795 264165 60368 473480 5634 253119 64236 85346 422987 28583 262389 111931 271291 13577 415079 132797 256502 76402 265607 11274 289667 398726 32021 302401 410650 369760...
output:
3090 193269 3028 186608 498475 64618 82114 231445 7541 329983 134623 235591 70401 18906 403427 280451 146897 355174 160090 144279 193430 332022 488244 228900 80781 84465 218682 27818 6035 368489 155673 440755 443926 241570 193717 143661 374105 56616 323329 95909 337798 20531 236329 28564 437244 4969...
result:
ok good job!
Test #3:
score: 0
Accepted
time: 387ms
memory: 230004kb
input:
500000 68287 68286 100000 273928 229768 65518 144983 311611 494773 489379 439644 467893 456131 430188 247387 485565 272285 474827 476962 338340 365804 344570 390867 390170 456217 43185 447057 385874 305750 107742 230530 259907 252254 280920 16831 45761 185191 117450 55891 175190 255615 35904 14855 2...
output:
242387 146602 170589 196742 270393 272971 277513 290951 335954 339454 343790 360585 408863 410420 416115 435584 462604 475865 106115 141534 208403 209977 237211 239423 262337 296002 322708 452430 483541 74367 118980 156994 257460 419650 336953 360548 369080 222228 264307 433002 210925 330758 346781 ...
result:
ok good job!
Test #4:
score: 0
Accepted
time: 396ms
memory: 229848kb
input:
500000 63976 63975 100000 230132 63748 303785 13497 431672 370351 360004 412191 378555 409703 485802 218204 475692 27602 220794 398856 89157 166559 116145 350738 277404 196706 40307 118602 171802 378360 389092 485168 224465 383516 33147 322617 254917 274019 57283 272241 216098 421952 489927 75641 40...
output:
210552 1449 107945 111424 204315 244893 252875 260986 300480 376032 453571 480811 497883 40773 118404 168162 204997 217368 256288 293187 301850 320642 393149 424098 438104 82457 99285 197733 238722 270472 298802 448813 478712 134521 193706 216617 225182 402014 434002 110514 134779 140337 206218 2111...
result:
ok good job!
Test #5:
score: 0
Accepted
time: 412ms
memory: 231496kb
input:
500000 87673 87672 100000 151599 456749 347511 703 348209 260440 488627 416030 419890 408089 83617 120781 133411 374231 460689 211838 137587 252914 392401 321583 55161 335205 334340 4527 14086 142229 197076 17695 262896 258702 273353 51181 10968 366799 324067 299421 281975 7236 420627 92324 299845 1...
output:
51300 4033 19229 42291 51583 74889 91845 101922 156054 189433 271298 306341 321237 338533 407800 407895 415653 427525 444649 474491 483318 486608 3297 17686 83949 141292 210462 226340 250587 330387 333267 420201 54995 72768 115579 151338 189275 191069 358089 378821 148934 213901 332993 352617 443599...
result:
ok good job!
Test #6:
score: 0
Accepted
time: 354ms
memory: 233620kb
input:
500000 77912 77911 100000 270576 129318 366297 25873 179787 473782 221947 331327 209469 412992 410608 286179 37554 355546 297085 420463 496948 223036 122019 151250 478469 468136 19073 318549 398897 364415 23730 407160 26064 436939 30150 336421 375149 131841 58480 259944 117641 414831 64311 336164 31...
output:
210887 26617 47747 65697 66936 111706 450513 209286 394458 330203 400826 372367 31977 188117 451749 243217 243665 490312 377213 17878 400064 451432 326862 393825 482110 79427 338802 25540 420037 427346 463407 343913 166743 374407 365280 324697 419374 203244 461047 50003 96053 191816 119601 246607 14...
result:
ok good job!
Test #7:
score: 0
Accepted
time: 402ms
memory: 233088kb
input:
500000 77688 77687 100000 433011 472346 395389 187114 436024 138403 189990 398859 136147 195283 331183 46789 19828 335128 387768 442181 65556 72327 318927 462834 421288 227912 37067 387794 145879 258896 185861 356020 202881 490952 443694 95413 137215 137239 112863 481338 167802 304239 309781 391976 ...
output:
176419 131882 292285 412347 35390 329939 362286 381302 111814 156219 373863 151412 9722 429048 172713 204978 273121 20522 237666 311400 297105 443479 290480 237978 358105 376930 474574 326538 492305 172116 390969 157831 223728 34874 85371 24933 163517 347566 217598 426614 62652 222554 310810 419414 ...
result:
ok good job!
Test #8:
score: 0
Accepted
time: 430ms
memory: 234468kb
input:
500000 70973 70972 100000 449081 8094 7358 89457 426121 454508 470543 485236 63347 441977 422774 88672 243638 499709 170209 157788 229166 106888 228931 289706 435222 496384 381579 323479 499140 1511 385050 44171 413854 248273 352221 305112 24289 277461 391744 395003 85800 396455 355110 186446 285096...
output:
449195 92100 139432 170991 324408 359470 431734 453335 131622 396138 62857 262646 18454 494280 516 248742 268964 246698 365411 49116 205579 441872 268796 478761 494550 118545 212775 270875 135573 466197 434345 228269 238351 328689 52558 54000 308679 406044 73730 344036 113837 58520 429984 164637 287...
result:
ok good job!
Test #9:
score: 0
Accepted
time: 397ms
memory: 227800kb
input:
500000 66403 66402 100000 297237 432967 138046 88503 315699 372893 55309 335404 127581 165919 247543 254268 285147 289728 275281 44427 94393 302830 489861 429097 425153 11083 439096 414157 386411 152968 394984 46119 149177 369378 413029 198215 134317 366218 281170 465540 39702 367778 247925 64320 86...
output:
294428 15990 17602 26152 111146 152620 178549 183834 238198 242546 321012 339735 346708 376658 413417 417544 452229 473786 60747 77238 79427 104166 114904 115479 131820 179383 250265 263956 267255 271077 297839 351735 354076 356662 387161 392460 409205 444258 450844 145593 169170 317852 361618 40460...
result:
ok good job!
Test #10:
score: 0
Accepted
time: 433ms
memory: 229260kb
input:
500000 82328 82327 100000 280281 366446 183709 14447 442815 440473 121531 103568 472324 479656 337467 424742 474404 340302 269686 457628 230012 484228 422877 10759 156759 66102 130428 307888 123685 460634 235321 98667 93133 489886 479420 34961 352500 322001 129001 121871 135775 235639 100221 221760 ...
output:
185494 36690 75237 90854 133402 145889 181174 187429 212224 294313 337250 368772 463947 481099 87374 138798 246616 456169 460527 13866 37615 56902 208445 213934 226717 250052 324069 421150 445974 9243 230858 300790 339912 360627 385009 436936 58689 99545 110599 182902 257794 315009 341634 402221 426...
result:
ok good job!
Test #11:
score: 0
Accepted
time: 353ms
memory: 227636kb
input:
500000 53948 53947 100000 287984 258934 272973 481182 131565 217198 34714 463056 337977 495727 310042 26372 320480 231799 249741 340990 365501 267377 460708 248843 285777 172137 492784 201463 213559 259528 461602 235849 398717 25475 241699 451061 188952 251790 83551 169967 335575 209367 55705 6381 2...
output:
490646 30912 58228 66900 141370 162271 168493 209420 220299 356934 368448 383176 402234 408329 426848 450187 472144 256224 419416 102019 345445 382142 494560 72417 247314 272686 290707 316488 316528 331074 460961 489786 61238 12765 18976 89792 129110 145977 305883 340153 393563 98854 122766 161729 2...
result:
ok good job!
Test #12:
score: 0
Accepted
time: 383ms
memory: 229168kb
input:
500000 77935 77934 100000 38748 422564 39441 105430 38474 225464 237519 121832 72613 477531 321661 29181 307418 314049 120252 261006 88761 17726 492112 460837 55199 354114 417097 133271 231933 436973 110894 478550 291976 50101 38774 316091 306160 121826 315769 361823 82990 188508 124574 13093 235123...
output:
423149 92225 92574 136846 180268 180932 192694 225485 232151 258860 261363 263307 278429 288537 359086 371909 399857 432427 456530 477335 497074 16389 166449 184539 292962 381527 471775 8113 24371 136137 201017 210563 479798 19305 41199 159700 176684 262158 278238 17363 182374 283422 51135 162369 17...
result:
ok good job!
Subtask #2:
score: 0
Wrong Answer
Test #13:
score: 25
Accepted
time: 836ms
memory: 283676kb
input:
500000 88721 177440 100000 30974 23891 211201 125199 180489 387190 218020 498838 230147 307989 484136 257785 353027 304420 311738 169842 334090 486070 126212 328609 174959 368840 238722 418092 488389 226349 427271 457322 332454 12958 197530 264474 355717 482774 221286 282148 216441 266659 213750 628...
output:
63742 52033 11431 383754 300071 114398 157785 255610 268420 142101 71772 483509 84553 478546 267656 394007 174540 10827 21500 332519 451751 200499 82419 299348 58833 96269 165916 225578 94199 272115 78203 43779 263216 286701 146169 388703 306934 81402 50728 334188 338250 273711 199716 430717 469441 ...
result:
ok good job!
Test #14:
score: 0
Accepted
time: 684ms
memory: 277936kb
input:
500000 50267 100532 100000 68723 142685 445548 215087 478634 201362 177405 373123 227456 161487 276716 452818 230715 466238 250886 368974 77152 493722 129115 154402 319190 170867 27898 338290 170229 428001 62611 19188 164329 435154 128 358453 137653 430592 160391 407392 125236 320137 27945 393135 17...
output:
71019 422264 495557 456046 31730 260857 116065 166921 88378 205024 303281 469438 100690 488976 375513 451217 399886 155609 191425 492027 467776 443039 333920 352750 329290 368062 14772 466255 76952 421178 27872 485791 409419 199430 154816 68517 362396 354044 408615 32079 364034 63300 455915 20532 14...
result:
ok good job!
Test #15:
score: -25
Wrong Answer
time: 622ms
memory: 230964kb
input:
500000 67604 135206 100000 269046 235003 144646 314602 323547 204450 484229 26672 78499 602 110738 117079 125630 408912 188317 256853 71590 365703 370008 194267 342683 400737 369194 127912 96314 269751 219125 431887 398790 200053 279314 365797 187505 75025 48264 492515 387506 13267 80948 378737 1106...
output:
304557 402449 5586 6636 42912 71664 101299 114759 120173 146621 149822 150901 160942 177329 196673 306329 337562 402073 9040 38654 43067 82183 83175 99560 121996 168677 193491 195016 212157 226623 245214 275561 278299 296256 306791 334229 358080 363481 385911 386190 389402 429037 486701 487592 49624...
result:
wrong answer wrong answer on the second integer of query #117: read 27949 but expected 21109
Subtask #3:
score: 0
Wrong Answer
Test #25:
score: 0
Wrong Answer
time: 208ms
memory: 199516kb
input:
500000 200 199 40000 76296 130139 291501 292412 139543 433345 372726 451574 18315 465578 324564 477223 237354 81532 65170 465332 342130 9670 193303 193680 129668 149532 268907 89969 398275 356210 324593 433492 482232 466692 135343 433758 102545 287283 432859 351864 305769 489532 101532 450535 295762...
output:
20242 414878 185020 125537 353357 496468 308518 188057 254952 120898 414314 11748 435424 326112 345902 271794 473882 337923 135188 438050 45188 88306 260313 116954 457474 435919 366460 431766 397351 392326 178950 199724 227083 282259 70917 121346 109196 193669 242154 12225 466790 155481 287973 15749...
result:
wrong answer wrong answer on the first integer of query #1: read 512146033 but expected 53295
Subtask #4:
score: 0
Runtime Error
Test #37:
score: 0
Runtime Error
input:
1000000 1000 999 100000 678746 439069 32542 85937 936926 284219 461661 203235 533462 940676 230275 621140 780674 254931 562355 229273 201341 493976 358955 963527 880412 91220 474599 160086 698841 591551 718276 844558 39859 765917 34722 401724 219774 443004 682244 545401 968419 968020 354030 411187 1...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%