QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402739 | #4401. Prize | sichengzhou | 10 | 601ms | 121736kb | C++14 | 3.2kb | 2024-05-01 11:56:41 | 2024-05-01 11:56:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+6;
int n,K,Q,T,dfn[N];
bool cmp(const int x,const int y)
{
return dfn[x]<dfn[y];
}
struct Tree{
int number;
int p[N],rt;
int fa[N][20];
struct Edge{
int v,nxt;
}e[N];
int h[N],tot1;
void addEdge(int u,int v)
{
tot1++;
e[tot1].v=v;e[tot1].nxt=h[u];
h[u]=tot1;
}
void input()
{
for(int i=1;i<=n;i++)
{
cin>>p[i];
if(p[i]>=1)addEdge(p[i],i),fa[i][0]=p[i];
else rt=i,fa[i][0]=0;
}
}
int dfn[N],idx,dep[N],rnk[N];
void dfs(int u)
{
dfn[u]=++idx;rnk[idx]=u;
for(int i=h[u];i;i=e[i].nxt)
{
int v=e[i].v;dep[v]=dep[u]+1;
dfs(v);
}
}
int a[N];
LL d[N];
int lca(int u,int v)
{
if(dep[u]<dep[v])
{
swap(u,v);
}
for(int j=19;j>=0;j--)
{
if((dep[u]-dep[v])>>j&1)
{
u=fa[u][j];
}
}
if(u==v)
{
return u;
}
for(int j=19;j>=0;j--)
{
if(fa[u][j]!=fa[v][j])
{
u=fa[u][j];
v=fa[v][j];
}
}
return fa[u][0];
}
void init()
{
dfs(rt);
for(int j=1;j<=19;j++)
{
for(int i=1;i<=n;i++)
{
fa[i][j]=fa[fa[i][j-1]][j-1];
}
}
for(int i=1;i<=K;i++)
{
a[i]=i;
}
int tp=0;
for(int i=1;i<=n;i++)
{
if(rnk[i]<=K)
{
a[++tp]=rnk[i];
}
}
for(int i=1;i<K;i++)
{
cout<<"? "<<a[i]<<' '<<a[i+1]<<endl;
}
}
void work()
{
d[a[1]]=0;
for(int i=1;i<K;i++)
{
LL X,Y,Z,W;
scanf("%lld%lld%lld%lld",&X,&Y,&Z,&W);
int x=lca(a[i],a[i+1]);
if(number==1)
{
d[x]=d[a[i]]-X;
d[a[i+1]]=d[x]+Y;
}else{
d[x]=d[a[i]]-Z;
d[a[i+1]]=d[x]+W;
}
// cout<<a[i]<<' '<<x<<' '<<a[i+1]<<endl;
// cout<<d[a[i]]<<' '<<d[x]<<' '<<d[a[i+1]]<<endl;
}
/* for(int i=1;i<=n;i++)
{
cout<<d[i]<<' ';
}
cout<<endl;*/
}
LL query(int u,int v)
{
return d[u]+d[v]-2*d[lca(u,v)];
}
}t1,t2;
int main()
{
int u[N],v[N];
cin>>n>>K>>Q>>T;
if(Q!=K-1||n>5e5)return 0;
t1.number=1;t2.number=2;
t1.input();t2.input();
for(int i=1;i<=K;i++)
{
cout<<i<<' ';
}
cout<<endl;
cout.flush();
t1.init();
cout<<"!\n";
cout.flush();
t1.work();
for(int i=1;i<=T;i++)
{
cin>>u[i]>>v[i];
}
for(int i=1;i<=T;i++)
{
cout<<t1.query(u[i],v[i])<<' '<<t1.query(u[i],v[i])<<endl;
}
cout.flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 551ms
memory: 121472kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #2:
score: 10
Accepted
time: 601ms
memory: 121736kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #3:
score: 10
Accepted
time: 499ms
memory: 115364kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #4:
score: 10
Accepted
time: 429ms
memory: 115248kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #5:
score: 10
Accepted
time: 423ms
memory: 115492kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #6:
score: 10
Accepted
time: 527ms
memory: 117088kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #7:
score: 10
Accepted
time: 532ms
memory: 117196kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #8:
score: 10
Accepted
time: 569ms
memory: 117144kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #9:
score: 10
Accepted
time: 426ms
memory: 115220kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #10:
score: 10
Accepted
time: 419ms
memory: 115344kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #11:
score: 10
Accepted
time: 421ms
memory: 115300kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Test #12:
score: 10
Accepted
time: 471ms
memory: 115332kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok good job!
Subtask #2:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 0ms
memory: 11304kb
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:
result:
wrong answer format Unexpected end of file - int32 expected
Subtask #3:
score: 0
Wrong Answer
Test #25:
score: 0
Wrong Answer
time: 392ms
memory: 120724kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
wrong answer wrong answer on the second integer of query #1: read 22200089 but expected 254659538
Subtask #4:
score: 0
Wrong Answer
Test #37:
score: 0
Wrong Answer
time: 0ms
memory: 11296kb
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:
wrong answer format Unexpected end of file - int32 expected
Subtask #5:
score: 0
Skipped
Dependency #4:
0%