QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106959 | #5015. 树 | 275307894a | 0 | 69ms | 109052kb | C++14 | 1.9kb | 2023-05-19 21:34:29 | 2023-05-19 21:34:32 |
Judging History
answer
#include "tree.h"
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define PB push_back
#define fi first
#define se second
using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using LL=__int128;
using namespace std;const int N=1e3+5,M=N*4+5,K=20,mod=1e4+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int fa[N],w[N],d[N],F[N][11];vector<int> S[N];
int Ask(int x,int y){vector<int> Ts;Ts.PB(y);return ask(x,Ts);}
int LCA(int x,int y){
d[x]<d[y]&&(swap(d[x],d[y]),0);while(d[x]^d[y]) x=F[x][__lg(d[x]-d[y])];
if(x==y) return x;for(int i=10;~i;i--) F[x][i]^F[y][i]&&(x=F[x][i],y=F[y][i]);
return F[x][0];
}
int Dt(int x,int y){return d[x]+d[y]-d[LCA(x,y)]*2;}
int Qry(int x,vector<int> y){
int Ans=0;for(int i:y) Ans+=Dt(x,i);return Ans;
}
void Find(vector<int> S,vector<int> T){
if(!T.size()) return;
if(S.size()==1) {for(int i:T){fa[i]=S[0];F[i][0]=S[0];for(int j=1;F[i][j-1];j++) F[i][j]=F[F[i][j-1]][j-1];}return;}
vector<int> S1,S2;shuffle(S.begin(),S.end(),rnd);
int Ct=S.size();for(int i:S) if(Ct) Ct--,S1.PB(i);else S2.PB(i);
int CC=0;map<int,int> f;
for(int i:S) w[i]=Qry(i,S2),!f[w[i]]&&(f[w[i]]=++CC),w[i]=f[w[i]];
for(int i:T) w[i]=f[ask(i,S2)-S2.size()];
for(int i=1;i<=f.size();i++){
vector<int> SS,TT;
for(int j:S) if(w[j]==i) SS.PB(j);
for(int j:T) if(w[j]==i) TT.PB(j);
Find(SS,TT);
}
}
void solver(int n, int A, int B){
int Rt=R(n);int i;for(i=1;i<=n;i++) if(i^Rt) S[d[i]=Ask(Rt,i)].PB(i);
S[0].PB(Rt);for(int i=1;i<=n;i++) if(S[i].size()) Find(S[i-1],S[i]);
for(i=1;i<=n;i++) if(i^Rt) assert(fa[i]);
for(i=1;i<=n;i++) if(i^Rt) answer(fa[i],i);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 69ms
memory: 109052kb
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:
Too many queries
result:
wrong answer Wrong Answer
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 3ms
memory: 4852kb
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:
Too many queries
result:
wrong answer Wrong Answer
Subtask #3:
score: 0
Wrong Answer
Test #111:
score: 0
Wrong Answer
time: 22ms
memory: 22480kb
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:
Too many queries
result:
wrong answer Wrong Answer
Subtask #4:
score: 0
Wrong Answer
Test #211:
score: 0
Wrong Answer
time: 4ms
memory: 9184kb
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