QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#516634 | #4401. Prize | JWRuixi | 0 | 681ms | 177376kb | C++20 | 3.0kb | 2024-08-12 19:59:30 | 2024-08-12 19:59:30 |
Judging History
answer
#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;
using vi = vector<int>;
#endif
constexpr int N = 1e6 + 9;
constexpr int M = 1e5 + 9;
int n, K, Q, T;
int S[M], cnt;
struct tree {
int rt, hd[N], tot, p[N];
struct {
int v, nx;
} e[N];
void add_edge (int u, int v) {
e[++tot] = {v, hd[u]};
hd[u] = tot;
}
int dfn[N], dfc, sz[N], son[N], dep[N], tp[N];
void dfs1 (int u, int f) {
sz[u] = 1;
dfn[u] = ++dfc;
dep[u] = dep[f] + 1;
for (int i = hd[u], v; i; i = e[i].nx) {
dfs1(v = e[i].v, u);
sz[u] += sz[v];
if(sz[v] > sz[son[u]]) {
son[u] = v;
}
}
}
void dfs2 (int u, int t) {
tp[u] = t;
if (son[u]) {
dfs2(son[u], t);
}
for (int i = hd[u], v; i; i = e[i].nx) {
if ((v = e[i].v) ^ son[u]) {
dfs2(v, v);
}
}
}
int lca (int x, int y) {
while (tp[x] ^ tp[y]) {
if (dep[x] < dep[y]) {
swap(x, y);
}
x = p[tp[x]];
}
return dep[x] < dep[y] ? x : y;
}
void in () {
L (i, 1, n) {
scanf("%d", p + i);
if (p[i] == -1) {
rt = i;
} else {
add_edge(p[i], i);
}
}
dfs1(rt, 0);
dfs2(rt, rt);
}
int H[N], tt;
struct {
int v, nx, w;
} E[M * 2];
bool vis[N];
int d[N];
void add (int u, int v, int w) {
E[++tt] = {v, H[u], w};
H[u] = tt;
E[++tt] = {u, H[v], -w};
H[v] = tt;
}
void dfs (int u) {
vis[u] = true;
for (int i = H[u], v; i; i = E[i].nx) {
v = E[i].v;
if (!vis[v]) {
d[v] = d[u] + E[i].w;
dfs(v);
}
}
}
int dis (int x, int y, int id) {
int l = lca(x, y);
return d[x] + d[y] - 2 * d[l];
}
} t[2];
int qx[M], qy[M];
int main () {
scanf("%d%d%d%d", &n, &K, &Q, &T);
t[0].in();
t[1].in();
L (i, 1, n) {
if (t[0].dfn[i] <= K) {
S[++cnt] = i;
}
}
sort(S + 1, S + K + 1, [] (int x, int y) {
return t[1].dfn[x] < t[1].dfn[y];
});
L (i, 1, K) {
printf("%d ", S[i]);
}
printf("\n");
fflush(stdout);
L (i, 2, K) {
printf("? %d %d\n", S[i - 1], S[i]);
}
printf("!\n");
fflush(stdout);
L (i, 2, K) {
int x = S[i - 1], y = S[i];
int l1 = t[0].lca(x, y);
int l2 = t[1].lca(x, y);
int d1, d2, d3, d4;
scanf("%d%d%d%d", &d1, &d2, &d3, &d4);
t[0].add(l1, x, d1);
t[0].add(l1, y, d2);
t[1].add(l2, x, d3);
t[1].add(l2, y, d4);
}
t[0].dfs(S[1]);
t[1].dfs(S[1]);
L (i, 1, T) {
scanf("%d%d", qx + i, qy + i);
}
L (i, 1, T) {
printf("%d %d\n", t[0].dis(qx[i], qy[i], 0), t[1].dis(qx[i], qy[i], 1));
}
fflush(stdout);
}
// I love WHQ!
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 366ms
memory: 115028kb
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:
wrong answer wrong answer on the first integer of query #1: read 0 but expected 23499297
Subtask #2:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 422ms
memory: 116252kb
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:
299348 225578 286701 388703 273711 466172 478011 490391 462013 126494 92677 182472 13812 107732 303666 361862 256289 91025 389690 156797 268792 434419 208299 409874 319842 64913 385537 136511 498213 255392 208598 45196 97386 482069 290480 370649 225780 380585 84550 485237 301855 494683 414740 107270...
result:
wrong answer wrong answer on the first integer of query #1: read 352261 but expected 425610
Subtask #3:
score: 0
Wrong Answer
Test #25:
score: 19
Accepted
time: 307ms
memory: 112040kb
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:
12225 329473 124294 112780 478338 445039 249189 32330 65783 179054 497476 452979 319006 30813 48206 427935 466790 486377 109196 200837 164218 45188 487722 282259 229713 367076 188057 187010 232559 151913 348461 116954 20242 322713 185020 157495 443679 326708 325415 391214 266949 457474 3735 299220 2...
result:
ok good job!
Test #26:
score: 19
Accepted
time: 319ms
memory: 108340kb
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:
455890 309275 63656 335800 292806 9763 489623 63346 86191 446791 183068 362736 197911 107095 211424 101597 145440 202553 8696 425553 151090 60540 369501 412878 462364 222 148686 133609 158102 107714 270626 112101 244973 133381 421561 462192 28928 193698 101629 183699 205161 304190 364442 409432 4207...
result:
ok good job!
Test #27:
score: 0
Wrong Answer
time: 273ms
memory: 68344kb
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:
202545 440862 361010 401185 475867 496061 39372 222066 236817 48111 60999 471755 360514 236313 204451 106250 381948 236421 376463 311524 441571 461140 98374 326916 103118 4158 483991 237952 222429 81602 347639 227796 78705 480293 427895 94835 128503 382030 222511 447219 456777 442490 405317 331113 3...
result:
wrong answer wrong answer on the second integer of query #1: read 29087 but expected 29397
Subtask #4:
score: 0
Wrong Answer
Test #37:
score: 22
Accepted
time: 672ms
memory: 176032kb
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:
927453 737189 653885 840772 346403 780854 103601 49131 439139 486132 820231 177271 826206 982104 499097 409243 194435 293457 172618 662161 236859 473531 81188 533335 712368 462084 777243 239386 911529 829354 62098 492333 390487 523069 358162 163042 451543 653539 717744 885154 584533 11086 661366 952...
result:
ok good job!
Test #38:
score: 22
Accepted
time: 681ms
memory: 177376kb
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:
70930 162711 104847 600658 547594 219142 447597 811056 140247 502224 659605 421892 389493 152949 636421 692108 137214 372169 804489 399568 586198 152111 43257 899797 878142 278025 996438 364577 750352 580921 589621 139136 802259 100210 987920 563289 985356 224651 422771 630597 972354 915562 97459 56...
result:
ok good job!
Test #39:
score: 0
Wrong Answer
time: 598ms
memory: 90520kb
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:
881979 65371 912477 527036 771384 637332 77375 96895 202131 869565 189017 344963 196422 79444 100330 903304 343434 851499 371245 836709 649674 985443 866113 369794 901391 590940 852434 64909 863307 156420 172661 78866 325578 556760 158104 549272 713416 571200 129022 328902 131081 557467 370894 8037 ...
result:
wrong answer wrong answer on the second integer of query #1: read 23172 but expected 23536
Subtask #5:
score: 0
Skipped
Dependency #4:
0%