QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#858064 | #9676. Ancestors | Aurore | 0 | 25ms | 41820kb | C++23 | 1.8kb | 2025-01-16 13:45:19 | 2025-01-16 13:45:20 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int buf[30];
inline void print(int x,char ch=' '){
if(x<0) putchar('-'),x=-x;
int tot=0;
do{
buf[++tot]=x%10;
x/=10;
}while(x);
for(int i=tot;i;i--)
putchar(buf[i]+'0');
putchar(ch);
}
const int MAXN=1e5+5;
int n,m,root;
vector<int> e[MAXN];
struct node{
int siz,dep,son,dist;
}a[MAXN];
void dfs1(int x,int dep){
a[x].siz=1,a[x].dep=dep;
for(int to:e[x]){
dfs1(to,dep+1);
a[x].siz+=a[to].siz;
if(a[to].dist>a[a[x].son].dist)
a[x].son=to;
}
a[x].dist=a[a[x].son].dist+1;
}
set<int> s[MAXN];
set<int>::iterator it;
int *f[MAXN],g[MAXN],*now=g,tot;
struct info{
int u,v,x;
info(int a=0,int b=0,int c=0){
u=a,v=b,x=c;
}
}b[MAXN<<1];
int num;
void dfs2(int x){
s[f[x][0]=++tot].insert(x);
if(!a[x].son) return ;
f[a[x].son]=f[x]+1;
dfs2(a[x].son);
for(int to:e[x]){
if(to==a[x].son) continue;
f[to]=now,now+=a[to].dist;
dfs2(to);
for(int i=0;i<a[to].dist;i++)
for(int y:s[f[to][i]]) s[f[x][i+1]].insert(y);
}
for(int to:e[x]){
if(to==a[x].son) continue;
for(int i=0;i<a[to].dist;i++){
for(int y:s[f[to][i]]){
it=s[f[x][i+1]].lower_bound(y);
if(it!=s[f[x][i+1]].begin()){
it--;
b[++num]=info(*it,y,i+1);
it++;
}
if(it!=s[f[x][i+1]].end()){
it++;
b[++num]=info(y,*it,i+1);
it--;
}
}
}
}
}
signed main(){
n=read(),m=read();
for(int i=1;i<=n;i++){
int x=read();
if(x==0) root=i;
else e[x].push_back(i);
}
dfs1(root,1);
f[root]=now,now+=a[root].dist;
dfs2(root);
cout<<num;
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 15280kb
input:
7 5 3 1 0 5 3 5 1 1 3 1 5 7 2 1 5 1 4 7 1 4 7 2
output:
10
result:
wrong answer 1st numbers differ - expected: '2', found: '10'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #30:
score: 0
Wrong Answer
time: 10ms
memory: 29380kb
input:
50000 200000 42574 43129 47328 17982 40521 6668 12729 32377 201 11940 8599 11734 18349 41045 26854 22540 9897 33419 7463 1243 47272 27135 49050 49111 22435 42539 39924 20272 5843 9308 45963 3283 31185 13692 38952 20583 15885 24802 4773 953 49907 28689 36942 23550 19449 8970 33340 31665 5407 46023 18...
output:
0
result:
wrong answer 1st numbers differ - expected: '12045', found: '0'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #67:
score: 0
Wrong Answer
time: 25ms
memory: 41820kb
input:
100000 1000000 6457 23693 90928 23592 90440 75018 16865 3342 83718 16731 95103 31510 38719 27886 29093 41955 6596 46409 51839 10527 91993 61074 14405 34833 53674 42363 11490 43757 46191 6058 59164 96938 57858 40178 97523 84164 21582 72243 11267 47368 97058 6637 95208 60092 53943 16441 28363 64965 52...
output:
0
result:
wrong answer 1st numbers differ - expected: '52956', found: '0'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%