QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#312242 | #5015. 树 | qL | 0 | 11ms | 7972kb | C++20 | 4.1kb | 2024-01-23 17:15:29 | 2024-01-23 17:15:29 |
Judging History
answer
/**
* 交互题,启动!
* 考虑先把每个点到 1 的距离问一便,可以对点分层。
* 但是我们只知道 1 和第一层之间连边的情况,下面剩的都不知道。
* 没关系,考虑从第一层再随机一个点 p 出来,然后以这个点为根再分一次层。
* 第一次的记作 c1[x],第二次的记作 c2[x],很容易通过这个找出那些 p 子树内的点。
* 然而更下面的答案也无法确定,于是不如只问下一层的。
* 这样每个点会被 1 问一次,又会被上一层的每个点都问一次,只要他把深度做低就很好卡。
* 就算我随机也能卡,比如整个菊花套菊花。
* 而且这个做法完全不管 B,显然不合理。
* 可以把枚举单点改成集合折半问,然后可以中途剪个枝。
*/
#include <bits/stdc++.h>
template <typename T>
void read(T& x) {
x = 0;
bool sign = false;
int Ch = getchar();
for (; !isdigit(Ch); Ch = getchar()) sign |= Ch == '-';
for (; isdigit(Ch); Ch = getchar()) x = x * 10 + (sign ? -(Ch & 15) : (Ch & 15));
}
template <typename T>
void uwrite(T x) {
if (x > 9) uwrite(x / 10);
putchar((x % 10) | 48);
}
template <typename T>
void write(T x) {
if (x < 0)
putchar('-'), uwrite(-x);
else
uwrite(x);
}
void write(char Ch) { putchar(Ch); }
void write(const char* Str) {
for (; *Str; ++Str) putchar(*Str);
}
void write(char* Str) { write(static_cast<const char*>(Str)); }
template <typename... Args>
void read(Args&... args) {
void(std::initializer_list<int>{(read(args), 0)...});
}
template <typename... Args>
void write(Args... args) {
void(std::initializer_list<int>{(write(args), 0)...});
}
using i64 = long long;
using i32 = int;
using u64 = unsigned long long;
using u32 = unsigned int;
#include "tree.h"
i32 n;
std::mt19937 Rand(std::random_device{}() + std::chrono::steady_clock::now().time_since_epoch().count());
std::vector<i32> turn(const std::basic_string<i32>& vec) { return std::vector<i32>{vec.begin(), vec.end()}; }
std::vector<std::basic_string<i32>> G, Fa;
std::basic_string<i32> Dep;
i32 LCA(i32 u, i32 v) {
if (Dep[u] < Dep[v]) std::swap(u, v);
for (i32 k = Fa[u].size() - 1; ~k; --k)
if (Dep[Fa[u][k]] >= Dep[v]) u = Fa[u][k];
if (u == v) return u;
for (i32 k = std::min(Fa[u].size(), Fa[v].size()) - 1; ~k; --k)
if (Fa[u][k] != Fa[v][k]) u = Fa[u][k], v = Fa[v][k];
return Fa[u][0];
}
i32 dist(i32 u, i32 v) { return Dep[u] + Dep[v] - (Dep[LCA(u, v)] << 1); }
i32 query(i32 x, std::basic_string<i32> v) {
i32 ret = 0;
for (i32 it : v) ret += dist(x, it);
return ret;
}
void report(i32 x, i32 fa) {
answer(x, fa), G[fa] += x;
Fa[x] += fa;
for (i32 k = 1; Fa[x].back(); ++k) Fa[x] += Fa[Fa[x][k - 1]][k - 1];
}
void find(std::basic_string<i32> Fa, std::basic_string<i32> Son) {
if (Fa.empty() || Son.empty()) return;
if (Fa.size() == 1) {
for (i32 it : Son)
if (ask(it, {Fa.front()}) == 1) report(it, Fa.front());
return;
} else if (Son.size() == 1)
for (i32 it : Fa)
if (ask(it, {Son.front()}) == 1) return report(Son.front(), it);
std::shuffle(Son.begin(), Son.end(), Rand);
i32 mid{Fa.size() >> 1};
std::basic_string<i32> s[2]{{Fa.begin(), Fa.begin() + mid}, {Fa.begin() + mid, Fa.end()}};
std::map<int, std::basic_string<i32>> p, d;
for (i32 it : Son) d[ask(it, turn(s[1]))] += it;
for (i32 it : Fa) p[query(it, s[1]) + s[1].size()] += it;
for (auto pi : p)
if (d.find(pi.first) != d.end()) find(pi.second, d[pi.first]);
}
void solver(i32 _n, i32 a, i32 b) {
if (a == 50000) return;
i32 Rt = Rand() % (n = _n) + 1;
Dep.resize(n + 1);
G.resize(n + 1, {}), Fa.resize(n + 1);
std::vector<std::basic_string<i32>> cnt(n + 1, std::basic_string<int>{});
for (i32 u = 1; u <= n; ++u) cnt[Dep[u] = ask(Rt, {u})] += u;
for (i32 d = 0; d < n; ++d) {
if (cnt[d + 1].empty()) break;
find(cnt[d], cnt[d + 1]);
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1000 500000 500000 1 2 2 3 2 4 2 5 2 6 3 7 2 8 5 9 5 10 9 11 2 12 9 13 4 14 5 15 12 16 5 17 4 18 4 19 13 20 9 21 19 22 7 23 6 24 14 25 2 26 10 27 14 28 21 29 17 30 8 31 15 32 9 33 22 34 24 35 20 36 6 37 12 38 19 39 31 40 35 41 25 42 11 43 8 44 9 45 12 46 26 47 10 48 6 49 27 50 39 51 33 52 6 53 43 54...
output:
Unauthorized output
result:
Subtask #2:
score: 0
Runtime Error
Test #11:
score: 17
Accepted
time: 1ms
memory: 4180kb
input:
100 3000 40000 66 95 66 60 66 93 66 69 66 82 66 24 66 64 66 84 66 42 66 22 66 67 66 54 66 90 66 26 66 41 66 18 66 43 66 68 66 36 66 88 66 33 66 29 66 79 66 6 66 48 66 47 66 8 66 38 66 61 69 97 64 30 38 86 88 14 18 10 54 81 88 25 29 2 18 21 95 46 42 80 93 91 61 62 68 35 47 23 69 17 93 28 18 31 61 70 ...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #12:
score: 0
Accepted
time: 1ms
memory: 4104kb
input:
100 3000 40000 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 11 6 12 6 13 7 14 7 15 8 16 8 17 9 18 9 19 10 20 10 21 11 22 11 23 12 24 12 25 13 26 13 27 14 28 14 29 15 30 15 31 16 32 16 33 17 34 17 35 18 36 18 37 19 38 19 39 20 40 20 41 21 42 21 43 22 44 22 45 23 46 23 47 24 48 24 49 25 50 25 51 26 52 26 53...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #13:
score: 0
Accepted
time: 1ms
memory: 5896kb
input:
100 3000 40000 1 2 2 3 3 4 3 5 5 6 6 7 4 8 7 9 1 10 4 11 3 12 7 13 1 14 1 15 7 16 3 17 4 18 7 19 9 20 1 21 8 22 10 23 6 24 6 25 2 26 10 27 7 28 5 29 5 30 8 31 4 32 4 33 10 34 2 35 8 36 9 37 3 38 6 39 3 40 8 41 9 42 6 43 10 44 8 45 5 46 8 47 8 48 2 49 8 50 8 51 3 52 1 53 3 54 5 55 5 56 8 57 3 58 10 5...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #14:
score: -17
Runtime Error
input:
100 3000 40000 13 50 17 13 62 17 5 62 74 5 83 74 98 83 37 98 80 37 23 80 87 23 27 87 40 27 95 40 52 95 54 52 67 54 42 67 18 42 34 18 81 34 59 81 12 59 30 12 64 30 15 64 92 15 61 92 1 61 72 1 16 72 3 16 48 3 31 48 41 31 77 41 93 77 33 93 96 33 53 96 28 53 90 28 25 90 26 25 57 55 85 57 45 85 20 45 22 ...
output:
Unauthorized output
result:
Subtask #3:
score: 0
Wrong Answer
Test #111:
score: 0
Wrong Answer
time: 11ms
memory: 7972kb
input:
1000 50000 3000000 126 207 937 126 615 937 837 615 500 837 588 500 505 588 353 505 60 353 904 60 656 904 685 656 460 685 614 460 551 614 537 551 858 537 596 858 9 596 738 9 918 738 322 918 940 322 859 940 113 859 110 113 312 110 995 312 443 995 246 443 257 246 238 257 999 238 885 999 976 885 330 976...
output:
Different tree
result:
wrong answer Wrong Answer
Subtask #4:
score: 0
Runtime Error
Test #211:
score: 60
Accepted
time: 8ms
memory: 7888kb
input:
990 8500 300000 1 2 1 3 1 4 1 5 2 6 2 7 2 8 3 9 3 10 3 11 4 12 4 13 4 14 5 15 5 16 5 17 6 18 6 19 6 20 7 21 7 22 7 23 8 24 8 25 8 26 9 27 9 28 9 29 10 30 10 31 10 32 11 33 11 34 11 35 12 36 12 37 12 38 13 39 13 40 13 41 14 42 14 43 14 44 15 45 15 46 15 47 16 48 16 49 16 50 17 51 17 52 17 53 18 54 18...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #212:
score: -60
Runtime Error
input:
992 8500 300000 1 2 2 3 3 4 4 5 3 6 5 7 7 8 3 9 3 10 2 11 8 12 4 13 4 14 9 15 11 16 5 17 5 18 7 19 12 20 5 21 5 22 10 23 9 24 23 25 22 26 11 27 21 28 28 29 23 30 19 31 5 32 12 33 9 34 11 35 3 36 19 37 10 38 33 39 12 40 12 41 38 42 31 43 25 44 6 45 5 46 36 47 23 48 28 49 31 50 28 51 25 52 5 53 25 54 ...
output:
Unauthorized output