QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#519567 | #8212. Football in Osijek | Yoralen | WA | 0ms | 33936kb | C++14 | 1.8kb | 2024-08-14 21:40:16 | 2024-08-14 21:40:16 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N=500005;
int a[N],n,T,fm[N],st[N],tp,vis[N],tg[N],son[N],h[N];
int cf[N],ans[N],mx,mxx,val[N],ti,I,cl[N],d[N],md[N],cnt;
struct edge{int to,next;}w[N<<1];
vector<int>C[N];
struct node{int to,next;};
void Add(int x,int y){
// printf("%d %d\n",x,y);
w[++cnt].to=y,w[cnt].next=h[x],h[x]=cnt;
}
void Fnd(int x){
st[++tp]=x;vis[x]=ti;
if(!vis[a[x]])Fnd(a[x]);
else{
if(vis[a[x]]!=ti)return;
int y,c=0;I++;
do{y=st[tp];cl[y]=I;tp--,C[I].push_back(y);}while(y!=a[x]);
return;
}
}
void DFS1(int u,int ff){
d[u]=d[ff]+val[u];md[u]=d[u];
for(int i=h[u];i;i=w[i].next){
int e=w[i].to;
if(e==ff)continue;DFS1(e,u);
if(md[e]>md[son[u]])son[u]=e;
md[u]=max(md[u],md[e]);
}
}
void DFS2(int u,int dp){
if(son[u])DFS2(son[u],dp+val[son[u]]);
else st[++tp]=dp,mx=max(mx,dp);
for(int i=h[u];i;i=w[i].next){
int e=w[i].to;
if(e!=son[u])DFS2(e,val[e]);
}
}
bool cmp(int a,int b){return a>b;}
int main(){
int i;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d",&a[i]);
for(i=1;i<=n;i++){if(!vis[i]){tp=0;ti++;Fnd(i);}}
for(i=1;i<=n;i++){
if(cl[i])continue;
if(cl[a[i]])Add(cl[a[i]]+n,i);
else Add(a[i],i);
}
for(i=1;i<=n;i++)val[i]=1;tp=0;
for(i=n+1;i<=n+I;i++)val[i]=C[i-n].size();
for(i=n+1;i<=n+I;i++){
mx=0;DFS1(i,0);DFS2(i,val[i]);
cf[val[i]]++;cf[mx+1]--;//printf("~%d\n",mx);
mxx=max(mxx,mx);
}
for(i=1;i<=n;i++){
cf[i]+=cf[i-1];
if(cf[i])ans[i]=0,tg[i]=1;
else if(i<=mxx)ans[i]=1,tg[i]=1;
}
sort(st+1,st+1+tp,cmp);
int sc=0;
for(i=1;i<=tp;i++)sc+=st[i],fm[sc]=i-1;
for(i=1;i<=n;i++){
if(!fm[i])fm[i]=fm[i-1];
if(!tg[i])ans[i]=fm[i];
printf("%d ",ans[i]);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 33936kb
input:
5 2 3 1 3 5
output:
0 1 0 0 1
result:
ok 5 number(s): "0 1 0 0 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 32960kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 30940kb
input:
2 2 2
output:
0 0
result:
ok 2 number(s): "0 0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 31100kb
input:
10 4 7 2 8 4 3 4 9 7 3
output:
1 1 1 0 0 0 0 1 2 3
result:
ok 10 numbers
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 31184kb
input:
10 8 7 4 8 3 4 2 5 3 7
output:
1 0 0 0 0 0 0 1 2 3
result:
wrong answer 6th numbers differ - expected: '1', found: '0'