QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#344412#8212. Football in OsijekCrysfly#WA 3ms58904kbC++173.5kb2024-03-04 15:06:012024-03-04 15:06:02

Judging History

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

  • [2024-03-04 15:06:02]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:58904kb
  • [2024-03-04 15:06:01]
  • 提交

answer

// what is matter? never mind. 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,modint b){return a.x==b.x;}
	friend bool operator !=(modint a,modint b){return a.x!=b.x;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 2000005
#define inf 0x3f3f3f3f

int n,to[maxn],res[maxn],vis[maxn];
vi e[maxn];

int st[maxn],tp,rt;
vi o;
int sum;
bool on[maxn];

int dfs(int u,int pa){
//	cout<<"dfs "<<u<<" "<<pa<<"\n";
	vis[u]=1;
	vi p;
	for(int v:e[u])
		if(!vis[v]){
			int w=dfs(v,u);
			p.pb(w);
		}
	sort(ALL(p));
	if(!p.size())p.pb(0);
	int mx=p.back(); p.pop_back();
	for(int x:p) o.pb(x);
	return mx+1;
}

void work(int u)
{
	while(!on[u]) on[u]=1,u=to[u];
//	cout<<"u: "<<u<<"\n";
	rt=u; tp=0; sum=0;
	for(int x=u;!vis[x];x=to[x]) st[++tp]=x,vis[x]=1;
	
	vi p;
	For(i,1,tp) {
		int t=dfs(st[i],0)-1;
		p.pb(t);
	}
	sort(ALL(p));
	int mx=p.back(); p.pop_back();
	for(int x:p) o.pb(x);
	o.pb(tp+mx);
	For(i,tp,tp+mx)res[i]=0;
}

void work()
{
	n=read();
	For(i,1,n)to[i]=read(),e[to[i]].pb(i);
	For(i,1,n)res[i]=inf;
	For(i,1,n)
		if(!vis[i])work(i);
	sort(ALL(o));
	for(int x:o)cout<<x<<" "; cout<<"\n";
	int mx=o.back(); o.pop_back();
	reverse(ALL(o));
	For(i,1,mx) if(res[i]>0) res[i]=1;
	int qwq=0;
	for(int x:o){
		int now=mx+x;
		++qwq;
		For(i,mx+1,now) if(res[i]>0) res[i]=qwq;
		mx=now;
	}
	For(i,1,n)cout<<res[i]<<" ";
}

signed main()
{
	int T=1;
	while(T--)work();
	return 0;
}
/*

*/

详细

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 58904kb

input:

5
2 3 1 3 5

output:

0 0 1 4 
0 1 0 0 1 

result:

wrong answer 2nd numbers differ - expected: '1', found: '0'