QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#125291 | #5015. 树 | pandapythoner | 0 | 13ms | 9124kb | C++14 | 5.5kb | 2023-07-16 14:53:35 | 2023-07-16 14:53:36 |
Judging History
answer
#include "tree.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rnd(36346346);
const ll inf = 1e18;
#ifdef LOCAL
bool local = true;
#else
bool local = false;
#endif
void solve_aboba(vector<int> &a, int rt = -1, vector<int> dsts = {}){
int n = a.size();
if(n <= 1){
return;
}
if(n == 2){
answer(a[0], a[1]);
return;
}
int u, v;
int dst;
if(rt == -1){
auto gen_uv = [&](){
int u = a[rnd() % n];
int v = a[rnd() % n];
while(u == v){
v = a[rnd() % n];
}
return make_pair(ask(u, {v}), make_pair(u, v));
};
auto gd_uv = gen_uv();
if(n >= 25){
for(int itr = 0; itr < 6; itr += 1){
gd_uv = max(gd_uv, gen_uv());
}
}
dst = gd_uv.first;
auto uv = gd_uv.second;
u = uv.first;
v = uv.second;
} else{
u = rt;
auto gdv = make_pair(-1, -1);
for(int i = 0; i < n; i += 1){
gdv = max(gdv, make_pair(dsts[i], a[i]));
}
dst = gdv.first;
v = gdv.second;
if(dst == 1){
for(auto v: a){
if(v != rt){
answer(rt, v);
}
}
return;
}
}
vector<vector<int>> vrtcs(dst + 1);
vector<vector<int>> vdsts(dst + 1);
vrtcs[0].push_back(u);
vdsts[0].push_back(0);
vrtcs[dst].push_back(v);
vdsts[dst].push_back(0);
vector<int> base_vrtcs(dst + 1);
base_vrtcs[0] = u;
base_vrtcs[dst] = v;
for(int i = 0; i < n; i += 1){
if(a[i] == u || a[i] == v){
continue;
}
int x = a[i];
int dstu;
if(rt == -1){
dstu = ask(u, {x});
} else{
dstu = dsts[i];
}
int dstv = ask(v, {x});
ll dst_bbr = (dstu + dstv - dst) / 2;
ll rdstu = dstu - dst_bbr;
vrtcs[rdstu].push_back(x);
vdsts[rdstu].push_back(dst_bbr);
if(dst_bbr == 0){
base_vrtcs[rdstu] = x;
}
}
for(int i = 0; i < dst; i += 1){
answer(base_vrtcs[i], base_vrtcs[i + 1]);
}
for(int i = 0; i <= dst; i += 1){
solve_aboba(vrtcs[i], base_vrtcs[i], vdsts[i]);
}
}
int find_nxt(int v, vector<int> vrtcs, int d){
int n = vrtcs.size();
if(vrtcs.size() == 1){
return vrtcs[0];
}
int m = (n / 2);
vector<int> vl(vrtcs.begin(), vrtcs.begin() + m), vr(vrtcs.begin() + m, vrtcs.end());
int rs = -1;
if(ask(v, vl) == (d + 2) * m){
rs = find_nxt(v, vr, d);
} else{
rs = find_nxt(v, vl, d);
}
return rs;
}
void solve_fuck(vector<int> a){
int n = a.size();
int u = rnd() % n;
vector<vector<int>> f(n);
f[0].push_back(u);
vector<int> dsts(n);
dsts[u] = 0;
for(int v = 0; v < n; v += 1){
if(u == v){
continue;
}
int d = ask(a[u], {a[v]});
f[d].push_back(v);
dsts[v] = d;
}
vector<vector<int>> t(n);
vector<int> sz(n, 0);
vector<int> par(n, -1);
sz[u] = 1;
for(int md = 1; md < n; md += 1){
if(f[md].empty()){
break;
}
for(auto v: f[md]){
int prnt = u;
if(md > 1){
int q = u;
vector<int> usd(n, 0);
while(dsts[q] < md - 1){
if(!usd[q]){
int z = q;
vector<int> way = {z};
usd[z] = true;
while(!t[z].empty() && dsts[z] < md - 1){
pair<int, int> nxt = {-1, -1};
for(auto to: t[z]){
if(!usd[to]){
nxt = max(nxt, make_pair(sz[to], to));
}
}
if(nxt.first == -1){
break;
}
z = nxt.second;
way.push_back(z);
usd[z] = true;
}
int dstz = ask(a[v], {a[z]});
int dstlca = (dsts[z] + dsts[v] - dstz) / 2;
q = way[dstlca - dsts[q]];
} else{
vector<int> vrtcs;
for(auto to: t[q]){
if(!usd[to]){
vrtcs.push_back(to);
}
}
q = find_nxt(v, vrtcs, md - dsts[q] - 1);
}
}
prnt = q;
}
t[prnt].push_back(v);
par[v] = prnt;
int bbr = v;
while(bbr != -1){
sz[bbr] += 1;
bbr = par[bbr];
}
answer(a[v], a[prnt]);
}
}
}
void solver(int n, int A, int B){
vector<int> a(n);
for(int i = 0; i < n; i += 1){
a[i] = i + 1;
}
solve_fuck(a);
}
/*
7 1000 1000
1 2
2 3
1 4
1 5
5 6
4 7
*/
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 9ms
memory: 7648kb
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:
Invalid ask
result:
wrong answer Wrong Answer
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 1ms
memory: 4028kb
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:
Invalid ask
result:
wrong answer Wrong Answer
Subtask #3:
score: 0
Wrong Answer
Test #111:
score: 20
Accepted
time: 12ms
memory: 7700kb
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:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #112:
score: 0
Accepted
time: 3ms
memory: 7764kb
input:
1000 50000 3000000 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 2...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #113:
score: 0
Accepted
time: 13ms
memory: 7736kb
input:
1000 50000 3000000 1 2 2 3 2 4 4 5 5 6 6 7 6 8 8 9 8 10 10 11 10 12 12 13 12 14 13 15 14 16 15 17 16 18 18 19 18 20 19 21 20 22 21 23 22 24 24 25 24 26 26 27 27 28 27 29 28 30 29 31 30 32 31 33 32 34 34 35 35 36 36 37 36 38 37 39 39 40 39 41 41 42 41 43 42 44 43 45 45 46 45 47 47 48 48 49 48 50 50 5...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #114:
score: 0
Accepted
time: 8ms
memory: 7632kb
input:
1000 50000 3000000 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 2...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #115:
score: -20
Wrong Answer
time: 3ms
memory: 7752kb
input:
1000 50000 3000000 31 688 31 684 31 63 31 564 31 34 31 288 31 808 31 356 31 327 31 458 31 993 31 344 31 902 31 407 31 37 31 150 31 969 31 323 31 790 31 464 31 230 31 999 31 936 31 106 31 965 31 771 31 663 31 476 31 652 31 991 31 475 31 258 31 395 31 664 31 762 31 934 31 951 31 419 31 84 31 70 31 167...
output:
Invalid ask
result:
wrong answer Wrong Answer
Subtask #4:
score: 0
Wrong Answer
Test #211:
score: 0
Wrong Answer
time: 3ms
memory: 9124kb
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:
Too many queries
result:
wrong answer Wrong Answer