QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#526810 | #4401. Prize | bachbeo2007 | 0 | 1148ms | 363848kb | C++23 | 2.4kb | 2024-08-21 20:38:20 | 2024-08-21 20:38:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
const int maxl = 25;
int n,m,q;
struct Tree{
int L[maxn],T,rt=-1;
vector<int> edge[maxn];
int dep[maxn],par[maxn][maxl];
void dfs(int u,int p){
par[u][0]=p,dep[u]=dep[p]+1;
for(int i=1;i<20;i++) par[u][i]=par[par[u][i-1]][i-1];
for(int v:edge[u]) dfs(v,u);
}
int lca(int u,int v){
if(dep[u]>dep[v]) swap(u,v);
for(int i=0;i<20;i++) if((dep[v]-dep[u])>>i&1) v=par[v][i];
if(u==v) return u;
for(int i=19;i>=0;i--) if(par[u][i]!=par[v][i]) u=par[u][i],v=par[v][i];
return par[u][0];
}
int f[maxn],d[maxn];
int findpar(int u){
if(u==f[u]) return u;
int x=f[u];f[u]=findpar(f[u]);
d[u]+=d[x];
return f[u];
}
void unions(int u,int v,int w){
int pu=findpar(u),pv=findpar(v);
if(pu==pv) return;
f[pv]=pu;d[pv]+=d[u]-d[v]+w;
}
void build(){
iota(f+1,f+n+1,1);
for(int i=1;i<=n;i++){
int p;cin >> p;
if(p==-1) rt=i;
else edge[p].push_back(i);
}
dfs(rt,0);
}
}T1,T2;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
cin >> n >> m >> q >> q;
T1.build();T2.build();
vector<int> ord(n);
iota(ord.begin(),ord.end(),1);
sort(ord.begin(),ord.end(),[&](int x,int y){
return T1.L[x]<T1.L[y];
});
while((int)ord.size()>m) ord.pop_back();
sort(ord.begin(),ord.end(),[&](int x,int y){
return T2.L[x]<T2.L[y];
});
for(int i=0;i<m;i++) cout << ord[i] << ' ';
cout << endl;
for(int i=1;i<m;i++) cout << "? " << ord[i-1] << ' ' << ord[i] << '\n';
cout << "!" << endl;
for(int i=1;i<m;i++){
int u=ord[i-1],v=ord[i];
int x,y,a=T1.lca(u,v);cin >> x >> y;
T1.unions(a,u,x);T1.unions(a,v,y);
a=T2.lca(u,v);cin >> x >> y;
T2.unions(a,u,x);T2.unions(a,v,y);
}
for(int i=1;i<=n;i++) T1.findpar(i),T2.findpar(i);
vector<int> U(q),V(q);
for(int i=0;i<q;i++) cin >> U[i] >> V[i];
for(int i=0;i<q;i++){
int u=U[i],v=V[i];
int a=T1.lca(u,v);
cout << T1.d[u]+T1.d[v]-2*T1.d[a] << ' ';
a=T2.lca(u,v);
cout << T2.d[u]+T2.d[v]-2*T2.d[a] << '\n';
}
cout << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 793ms
memory: 215392kb
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:
368651 368605 368604 368603 368602 368601 368600 368599 368598 368597 368596 368595 368594 368639 368653 368652 368606 368650 368649 368648 368647 368646 368645 368644 368643 368642 368641 368640 368593 368638 368637 368636 368622 368453 368452 368451 368450 368449 368448 368447 368446 368445 368444...
result:
ok good job!
Test #2:
score: 10
Accepted
time: 817ms
memory: 217412kb
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:
354797 354786 354787 354788 354789 354790 354791 354792 354793 354794 354795 354796 354785 354783 354738 354739 354740 354741 354742 354743 354744 354745 354746 354774 354948 354949 354950 354951 354936 354769 354770 354771 354772 354773 354747 354775 354776 354777 354778 354779 354780 354781 354782...
result:
ok good job!
Test #3:
score: 0
Wrong Answer
time: 494ms
memory: 188864kb
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:
370895 370887 370888 370889 370890 370891 370892 370893 370894 370886 370896 370973 370898 370899 370900 370901 370902 371061 371053 371054 371055 371056 371057 371058 371059 371060 370903 371062 371063 371064 371049 370883 370884 370885 370867 370859 370860 370861 370862 370863 370864 370865 370882...
result:
wrong answer wrong answer on the first integer of query #1499: read 22648 but expected 15770
Subtask #2:
score: 0
Wrong Answer
Test #13:
score: 25
Accepted
time: 836ms
memory: 215568kb
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:
353366 353295 353296 353297 353298 353299 353300 353301 353302 353303 353288 353294 353367 353368 353369 353370 353371 353372 353373 353374 353375 353376 353283 353319 353274 353275 353276 353277 353278 353279 353280 353281 353282 353377 353284 353285 353286 353287 353304 353289 353290 353291 353292...
result:
ok good job!
Test #14:
score: 25
Accepted
time: 737ms
memory: 216232kb
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:
366237 366310 366309 366308 366307 366306 366305 366227 366242 366241 366240 366239 366238 366311 366236 366235 366234 366233 366232 366231 366230 366229 366228 366243 366226 366323 366274 366319 366333 366332 366331 366330 366329 366328 366327 366326 366325 366324 366225 366322 366321 366320 366273...
result:
ok good job!
Test #15:
score: 0
Wrong Answer
time: 487ms
memory: 189264kb
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:
370556 370548 370549 370550 370551 370552 370553 370554 370555 370547 370557 370558 370559 370560 370577 370562 370563 370600 370546 370593 370594 370595 370596 370597 370598 370599 370564 370601 370602 370603 370604 370605 370606 370592 370405 370397 370398 370399 370400 370401 370402 370403 370404...
result:
wrong answer wrong answer on the second integer of query #46: read 2387 but expected 6315
Subtask #3:
score: 0
Wrong Answer
Test #25:
score: 19
Accepted
time: 525ms
memory: 212752kb
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:
333453 333465 333464 333463 333462 333461 333460 333459 333458 333457 333456 333455 333454 333466 333468 333451 333450 333449 333448 333447 333446 333445 333444 333443 333442 333294 333306 333305 333304 333303 333302 333301 333300 333376 333298 333297 333296 333295 333441 333293 333292 333291 333290...
result:
ok good job!
Test #26:
score: 19
Accepted
time: 506ms
memory: 215108kb
input:
500000 200 199 40000 83785 150667 304961 267635 97760 385201 77226 6522 352645 72592 427133 30755 100574 359648 403948 394809 425453 115868 11287 351385 494434 245106 58157 395180 326236 277135 359592 13569 76251 45366 172378 122783 216597 466130 284420 342613 471698 380682 92490 79264 241049 54038 ...
output:
333453 333465 333464 333463 333462 333461 333460 333459 333458 333457 333456 333455 333454 333466 333468 333451 333450 333449 333448 333447 333446 333445 333444 333443 333442 333294 333306 333305 333304 333303 333302 333301 333300 333376 333298 333297 333296 333295 333441 333293 333292 333291 333290...
result:
ok good job!
Test #27:
score: 0
Wrong Answer
time: 403ms
memory: 185276kb
input:
500000 200 199 40000 94863 498513 460682 411416 360517 309831 253717 325019 496632 255803 130770 289206 181204 74729 481723 293737 94126 307214 342974 448321 17084 433126 387809 279606 251781 65795 125269 129465 433572 219622 11806 179248 367117 84640 114067 122590 4140 116015 77759 392439 408930 10...
output:
333453 333465 333464 333463 333462 333461 333460 333459 333458 333457 333456 333455 333454 333466 333468 333451 333450 333449 333448 333447 333446 333445 333444 333443 333442 333294 333306 333305 333304 333303 333302 333301 333300 333376 333298 333297 333296 333295 333441 333293 333292 333291 333290...
result:
wrong answer wrong answer on the second integer of query #1: read 10058 but expected 7860
Subtask #4:
score: 0
Wrong Answer
Test #37:
score: 22
Accepted
time: 1133ms
memory: 363848kb
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:
666123 666077 666032 666033 666034 666035 666036 666037 666038 666039 666040 666041 666042 666043 666044 666045 666030 666108 666109 666110 666111 666112 666113 666114 666115 666116 666117 666118 666119 666120 666121 666122 666076 666061 666046 666063 666064 666065 666066 666067 666068 666069 666070...
result:
ok good job!
Test #38:
score: 22
Accepted
time: 1148ms
memory: 363724kb
input:
1000000 1000 999 100000 530144 36744 762893 712555 181981 816257 634992 419372 362279 817260 80801 697008 163211 900947 207310 862766 871091 388529 304808 574011 609949 509094 682125 781230 431445 517909 578411 288003 874415 410542 327673 607230 278208 956997 60166 842448 708661 562761 996349 382922...
output:
666123 666077 666032 666033 666034 666035 666036 666037 666038 666039 666040 666041 666042 666043 666044 666045 666030 666108 666109 666110 666111 666112 666113 666114 666115 666116 666117 666118 666119 666120 666121 666122 666076 666061 666046 666063 666064 666065 666066 666067 666068 666069 666070...
result:
ok good job!
Test #39:
score: 0
Wrong Answer
time: 878ms
memory: 302852kb
input:
1000000 1000 999 100000 184414 849676 938006 927343 390133 327580 229110 507237 712311 8816 414520 114671 637641 82050 586607 523821 775429 139792 129360 175687 202474 801377 53523 281419 268534 488983 371227 294280 754555 448802 474939 391153 68307 762784 972243 245396 471656 982894 891252 945526 5...
output:
666123 666077 666032 666033 666034 666035 666036 666037 666038 666039 666040 666041 666042 666043 666044 666045 666030 666108 666109 666110 666111 666112 666113 666114 666115 666116 666117 666118 666119 666120 666121 666122 666076 666061 666046 666063 666064 666065 666066 666067 666068 666069 666070...
result:
wrong answer wrong answer on the second integer of query #33: read 23607 but expected 21285
Subtask #5:
score: 0
Skipped
Dependency #4:
0%