QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#380927#8212. Football in OsijekOOBMABTRAMS#WA 7ms45764kbC++172.0kb2024-04-07 15:06:162024-04-07 15:06:17

Judging History

你现在查看的是最新测评结果

  • [2024-04-07 15:06:17]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:45764kb
  • [2024-04-07 15:06:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int N=500013;
typedef long long ll;
int a[N],in[N];
int R[N];
vector<int>mp[N];
int top[N],son[N],len[N];
void dfs(int x){
    for(auto i:mp[x])dfs(i),len[x]=max(len[i]+1,len[x]);
}
void dfs2(int x,int tp){
    top[x]=tp;
    int sn=0;
    for(auto i:mp[x])if(len[i]>len[sn])sn=i;
    son[x]=sn;
    for(auto i:mp[x])if(i==sn)dfs2(i,tp);else dfs2(i,i);
}
int f[N],sz[N],val[N];
int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
void merge(int x,int y){x=find(x),y=find(y);if(x^y)f[x]=y,sz[y]+=sz[x],val[y]=max(val[y],val[x]);}
int zero[N],ans[N];
vector<int>l[N];
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i],in[a[i]]++;
    queue<int>q;
    for(int i=1;i<=n;i++)R[i]=1;
    for(int i=1;i<=n;i++)if(!in[i])q.push(i);
    while(!q.empty()){
        int x=q.front();
        q.pop();R[x]=0;
        if(!--in[a[x]])q.push(a[x]);
    }
    for(int i=1;i<=n;i++)if(R[i])sz[i]=1;else mp[a[i]].push_back(i);
    for(int i=1;i<=n;i++)if(R[i])dfs(i),dfs2(i,i);
    for(int i=1;i<=n;i++)f[i]=i,val[i]=len[i];
    for(int i=1;i<=n;i++)merge(i,a[i]);
    int mx=0;
    for(int i=1;i<=n;i++){
        mx=max(val[find(i)]+sz[find(i)],mx);
        zero[sz[find(i)]]++,zero[sz[find(i)]+val[find(i)]+1]--;
    }
    for(int i=1;i<=mx;i++)zero[i]+=zero[i-1];
    for(int i=1;i<=mx;i++)if(!zero[i])ans[i]=1;
    for(int i=1;i<=n;i++)if(top[i]==i)l[find(i)].push_back(len[i]);
    for(int i=1;i<=n;i++)sort(l[i].begin(),l[i].end(),greater<>());
    for(int i=1;i<=n;i++)if(!l[i].empty())l[i][0]+=sz[find(i)];
    vector<int>ve;
    for(int i=1;i<=n;i++)for(auto x:l[i])ve.push_back(x);
    sort(ve.begin(),ve.end(),greater<>());
    int nw=ve[0];
    for(int i=1;i<ve.size();i++){
        for(int j=nw+1;j<=nw+ve[i];j++)ans[j]=i;
        nw+=ve[i];
    }
    for(int i=1;i<=n;i++)cout<<ans[i]<<' ';
}

signed main(){
    ios::sync_with_stdio(false);
    int T=1;
   // cin>>T;
    while(T--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 45144kb

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: 5ms
memory: 45764kb

input:

1
1

output:

0 

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 45608kb

input:

2
2 2

output:

0 0 

result:

ok 2 number(s): "0 0"

Test #4:

score: -100
Wrong Answer
time: 3ms
memory: 44824kb

input:

10
4 7 2 8 4 3 4 9 7 3

output:

1 1 1 0 0 0 0 1 0 0 

result:

wrong answer 9th numbers differ - expected: '2', found: '0'