QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#397210 | #2792. 幸运数字 | james1BadCreeper | 100 ✓ | 1701ms | 159536kb | C++14 | 2.0kb | 2024-04-23 19:42:46 | 2024-04-23 19:42:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
int n, m;
int f[15][20005], dep[20005];
i64 a[20005];
struct lb {
i64 p[65];
lb() { memset(p, 0, sizeof p); }
void operator+= (i64 x) {
for (int i = 61; i >= 0; --i) if (x >> i & 1) {
if (!p[i]) { p[i] = x; break; }
else x ^= p[i];
}
}
i64 &operator[](int x) { return p[x]; }
void operator+= (lb &x) {
for (int i = 61; i >= 0; --i)
if (x[i]) *this += x[i];
}
friend lb operator+(lb &x, lb &y) {
lb z = x;
for (int i = 61; i >= 0; --i) if (y[i]) z += y[i];
return z;
}
i64 askmx(void) {
i64 res = 0;
for (int i = 61; i >= 0; --i) if ((res ^ p[i]) > res) res ^= p[i];
return res;
}
} l[15][20005];
vector<int> G[20005];
void dfs(int x, int fa) {
l[0][x] += a[x]; dep[x] = dep[f[0][x] = fa] + 1;
for (int y : G[x]) if (y != fa) dfs(y, x);
}
inline i64 query(int x, int y) {
lb ans;
if (dep[x] < dep[y]) swap(x, y);
for (int i = 14; i >= 0; --i) if (dep[f[i][x]] >= dep[y])
ans += l[i][x], x = f[i][x];
if (x == y) return ans += a[x], ans.askmx();
for (int i = 14; i >= 0; --i) if (f[i][x] != f[i][y])
ans += l[i][x], ans += l[i][y], x = f[i][x], y = f[i][y];
ans += l[0][x]; ans += l[0][y]; x = f[0][x]; ans += a[x];
return ans.askmx();
}
int main(void) {
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i < n; ++i) {
int x, y; cin >> x >> y;
G[x].emplace_back(y); G[y].emplace_back(x);
}
dfs(1, 0);
for (int i = 1; i <= 14; ++i) for (int j = 1; j <= n; ++j)
f[i][j] = f[i - 1][f[i - 1][j]], l[i][j] = l[i - 1][j] + l[i - 1][f[i - 1][j]];
while (m--) {
int x, y; cin >> x >> y;
cout << query(x, y) << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 11ms
memory: 156912kb
input:
1000 1000 10 30 64 26 34 37 4163 15 4896 29 262145 2092 6 58 15 514 1034 39 30 4194386 43 15 54 67 16391 396 328 0 32 96 46 8324 14 278 166 23 26 13 16777349 56 51 27 92 1344 44 45 27 42 3 8 34 46 265 833 14 58 83 102 16393 6 60 12 262528 130 1045 5 262185 141 646 15 152 1066 131 513 4196 11 657 154...
output:
2824191 10027007 4095 11239423 1372159 327679 263614 135987199 1085439 1961983 134660095 18214911 136314879 634879 3469311 136314879 537919487 4846 43519 356351 196607 18874367 143355 136314879 634879 134361087 1372159 538968063 537919487 141859 136314879 2097151 327679 1507327 134905855 143327231 1...
result:
ok 1000 lines
Test #2:
score: 10
Accepted
time: 566ms
memory: 158056kb
input:
10000 50000 12 643 72 30 27 53 2089 78 20 2069 4133 1065 41028 46 294 169 29 15 172 0 67 130 10 39 11 1049 41 8203 262149 308 12 16902 2572 65609 289 27 131081 27 4229 53 76 524 116 282 23 1037 7 39 29 23 3216 1033 33040 298 4 57 14 23 12 212 45 76 57 58 16518 16426 101 12 1041 29 26 35 312 8706 269...
output:
1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 536870911 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 754974719 1073741823 1073741823 1073741823 1073741823 10737...
result:
ok 50000 lines
Test #3:
score: 10
Accepted
time: 840ms
memory: 159492kb
input:
20000 50000 2058 1027 27 57 60 69 393 300 101 1028 77 8226 46 30 30 277 198 39 142 8388660 43 257 51 4648 2 51 530 42 36 92 298 105 33282 30 1035 29 1080 268435484 226 1091 16 1604 274 46 3 21 106 2313 6 46 170 154 16395 18 16428 11 16448 11 165 2 54 78 52 1050 15 30 58 45 54 209 262163 23 15 10 340...
output:
277411266559 110595407871 2542620639231 18176301596671 2680059592703 2594160246783 11542724607 292012031 20890720927743 2748779069439 2680059592703 20409684590591 2611340115967 20890720927743 20890720927743 2558726766591 2611340115967 2611340115967 15569256447 80530636799 18210661335039 208907209277...
result:
ok 50000 lines
Test #4:
score: 10
Accepted
time: 1337ms
memory: 159536kb
input:
20000 100000 46 86020 664 262200 45 30 65536 60 43 42 46 2076 22 99 77 3 104 16408 44 270 15 293 153 139 262166 29 72 561 132 8201 289 71 15 7 16400 15 106 16777224 54 34 54 6 2117 154 9 32777 85 101 3201 136 65556 14 353 1286 582 177 1100 521 12 72 34560 306 262 2144 131112 1050 41 14 131392 71 30 ...
output:
279201710079 70746701299711 5427189394702335 352805793562623 352805793562623 437510143 5422653909237759 6106906623 422655 70471823392767 20468203519 5422653909237759 71330816851967 20870856703 71330816851967 5422653909237759 4859703955816447 5422653909237759 4859426930425855 5422653909237759 3525287...
result:
ok 100000 lines
Test #5:
score: 10
Accepted
time: 392ms
memory: 157680kb
input:
10000 50000 1038 71 284 81 4096 15 54 4194341 165 15 29 4162 150 7 20 658 51 92 43 270 46 1034 27 45 1048644 15 2049 17 554 30 16777218 332 540 22 1345 2056 141 149 1 51 139 524553 153 352 520 13 184 17 2061 15 9216 46 35 46 65539 147474 11 27 532 15 50 3137 166 360 24576 1030 97 550 8388613 2 202 9...
output:
369098751 402653183 393215999 13303807 394264575 213909503 369098751 402653183 759807 78118911 536870911 348127231 245759 348127231 348127231 83886079 393215999 19922943 536870911 528482303 402653183 11010047 536870911 402653183 15204351 385875967 394264575 13369343 15204351 348127231 83886079 33646...
result:
ok 50000 lines
Test #6:
score: 10
Accepted
time: 604ms
memory: 158752kb
input:
20000 50000 2316 169 39 270 2097202 2304 116 49 71 43 8196 46 32802 30 33 15 540 57 9 153 27 1 65668 27 11 7 27 332 156 8392962 8208 8480 76 8 85 1029 34 13 80 2122 4132 552 146 38 16402 89 578 16777352 8454 1064 3 2304 15 525 30 67 14 4 30 267 23 15 13 16409 142 15 32805 15 77 141 15 4107 12 67590 ...
output:
40802189311 5368709119 36473667583 5799673855 36473667583 5905580031 5905580031 4026531839 100663295 4026531839 4031 36071014399 6408896511 78512127 40802189311 234881023 5905580031 36205232127 3381657599 805306367 1576927231 5905580031 40802189311 5100273663 5905580031 491519 227016703 5905580031 6...
result:
ok 50000 lines
Test #7:
score: 10
Accepted
time: 823ms
memory: 158744kb
input:
20000 80000 524 142 39 134 85 278 70 43 356 18 30 8201 2112 68 4140 116 43 23 201 15 106 65540 101 78 3 32779 259 4107 13 133 4613 194 153 29 2608 56 113 75 15 153 20 33554456 131085 16388 15 17 34 33029 13 16 65620 72 73 15 23 89 45 67 524376 268438018 16578 40 33280 4294967436 21 4136 146 9 305 2 ...
output:
72147242353426431 72147242890297343 72146108482060287 72146108482060287 585726164991 1136371171327 18145431519231 72146142841798655 72127964197683199 38117834751 3080191 72147242219208703 134569983 75857919 284278783 72146692463394815 34745090047 88514427355135 34366914559 72146108482060287 72147242...
result:
ok 80000 lines
Test #8:
score: 10
Accepted
time: 1143ms
memory: 158680kb
input:
20000 120000 34824 180 1044 29 101 4162 35 6 129 774 530 97 153 577 1046 15 8472 32781 8388626 262150 178 15 291 360 296 35 29 41 131073 27 15 15 30 2122 45 1224 308 45 46 531 54 308 1290 201 178 133 39 28 1538 45 562 1057 544 512 43 15 289 530 23 2147483684 53 43 72 27 15 777 840 292 16422 46 101 1...
output:
4406636445695 1130305737981951 36423204863 3087007743 83886079 1125903392309247 1130306543288319 1130305721204735 4406636445695 1125902318567423 1130580884324351 4406636445695 32505855 4405814362111 4406636445695 2818572287 34134527 1126179578839039 3087007743 3087007743 1130581421195263 11303062748...
result:
ok 120000 lines
Test #9:
score: 10
Accepted
time: 1701ms
memory: 158684kb
input:
20000 200000 140 29 4194310 29 44 139 15 27 101 29 14 25 24 92 131082 129 8195 4195393 27 259 139 8272 17411 1073741829 78 23 32838 135 2070 51 77 69 7 46 27 135 258 524624 232 170 15 515 8388706 22 85 13 15 68157536 201 150 644 14 8389152 432 0 4194852 1076 4370 16403 306 20 23 264 39 2065 304 8258...
output:
704643071 14495514623 32212254719 15032385535 32212254719 34359738367 29229055 70254591 32212254719 23622320127 68740448255 14428405759 23622320127 889192447 1031798783 5704253439 32212254719 6408896511 7851737087 32212254719 15032385535 32212254719 32212254719 23592959 22548578303 23622320127 14428...
result:
ok 200000 lines
Test #10:
score: 10
Accepted
time: 12ms
memory: 157036kb
input:
100 100 57 15 65665 1192 15 1050 10 39 2 11 519 36 16929 78 65600 4 45 70 15 1068 58 524332 142 45 13 1030 13 4610 21 389 1052 2116 204 66088 0 42 2625 8704 22 39 15 56 4 9 43 30 202 16396 78 513 268 515 39 198 1 130 297 67 150 27 30 102 15 15 44 106 132 15 139 73734 15 15 17410 16402 180 15 3 54 40...
output:
618239 634879 593391 610047 91647 83560 600063 618495 609919 602111 82665 65743 533375 592111 2302 610047 83708 147515 527354 592111 592111 82682 92159 590015 525243 537520 602111 620031 91647 67054 543359 590062 98366 638975 533503 73341 544511 602111 604159 592127 606207 592111 535551 602111 59212...
result:
ok 100 lines