QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#859429#9677. 基础博弈练习题fanglong0 333ms170404kbC++142.1kb2025-01-17 18:57:552025-01-17 18:58:01

Judging History

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

  • [2025-01-17 18:58:01]
  • 评测
  • 测评结果:0
  • 用时:333ms
  • 内存:170404kb
  • [2025-01-17 18:57:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1000001;
int n,m,k;
int a[N],b[N],c[N];
vector<int> g[N];
int dfn[N],low[N],now;
int st[N],tp;
bool vis[N];
int cnt,scc[N];
vector<int> adj[N],h[N];
void dfs(int u){
	dfn[u]=low[u]=++now;
	st[++tp]=u;
	vis[u]=1;
	for(int v:g[u]){
		if(!dfn[v]){
			dfs(v);
			low[u]=min(low[u],low[v]);
		}
		else if(vis[v])low[u]=min(low[u],dfn[v]);
	}
	if(dfn[u]==low[u]){
		cnt++;
		while(1){
			int x=st[tp--];
			vis[x]=0;
			scc[x]=cnt;
			adj[cnt].push_back(x);
			for(int v:g[x])if(scc[v])h[cnt].push_back(scc[v]);
			if(x==u)break;
		}
	}
}
int p[N],q[N],d[N];
bool cmp(int i,int j){
	return p[i]<p[j];
}
int mn[N*4],bk[N];
#define mid (l+r>>1)
#define ls (p<<1)
#define rs (p<<1|1)
void build(int p,int l,int r){
	mn[p]=k+1;
	if(l==r)return;
    build(ls,l,mid);
    build(rs,mid+1,r);
}
void modify(int p,int l,int r,int x,int v){
	if(l==r){
		mn[p]=v;
		return;
	}
	if(x<=mid)modify(ls,l,mid,x,v);
	else modify(rs,mid+1,r,x,v);
	mn[p]=min(mn[ls],mn[rs]);
}
int f[N],ans[N];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)cin>>a[i],c[i]=k+1;
	for(int i=1;i<=k;i++)cin>>b[i],c[b[i]]=min(c[b[i]],i);
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
	}
	for(int i=1;i<=n;i++)if(!dfn[i])dfs(i);
	for(int i=1;i<=cnt;i++){
		d[i]=i;
		p[i]=k+1;
		for(int x:adj[i])p[i]=min(p[i],c[a[x]]);
	}
	sort(d+1,d+cnt+1,cmp);
	build(1,1,n);
	for(int i=1;i<=n;i++)bk[i]=k+1;
	for(int i=k,j=cnt;i>=1;i--){
		bk[b[i]]=i;
		modify(1,1,n,i,b[i]);
		while(j&&i==p[d[j]]){
			int u=d[j];
			for(int x:adj[u])modify(1,1,n,a[x],k+1);
			q[u]=mn[1];
			for(int x:adj[u])modify(1,1,n,a[x],bk[a[x]]);
			j--;
		}
	}
	for(int i=1;i<=cnt;i++){
		f[i]=k+1;
		ans[i]=-1;
		for(int j:h[i])f[i]=min(f[i],f[j]);
		if(f[i]<k)ans[i]=f[i];
		if(p[i]<f[i]){
			int qq=min(q[i],f[i]);
			if((p[i]+qq)&1)f[i]=p[i]-1;
			else f[i]=p[i];
		}
		if(adj[i].size()>1&&f[i]<k)ans[i]=f[i];
	}
	for(int i=1;i<=n;i++)cout<<ans[scc[i]]<<' ';
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 9ms
memory: 95988kb

input:

83 93 13
8 9 10 7 7 7 6 3 1 10 6 2 5 7 1 3 4 2 1 10 7 4 8 9 2 2 1 9 2 5 1 7 8 6 1 9 9 10 4 1 2 9 2 3 4 2 9 10 8 1 4 1 8 4 1 4 4 7 4 8 2 9 2 5 2 2 3 3 8 5 2 9 3 10 8 8 1 6 6 1 6 7 10
7 5 10 3 2 2 7 4 8 7 6 6 5
56 36
33 41
32 62
37 7
6 53
41 13
9 36
44 77
38 62
76 16
72 5
40 13
55 60
5 78
72 45
13 44
...

output:

0 -1 -1 -1 2 0 -1 8 0 -1 4 -1 0 0 2 -1 0 -1 0 0 -1 0 -1 2 -1 -1 -1 -1 -1 -1 0 0 0 -1 0 -1 4 0 0 0 0 0 -1 -1 -1 -1 0 0 0 -1 0 0 4 0 0 0 -1 -1 4 -1 0 0 0 0 0 8 -1 -1 2 -1 -1 0 4 4 -1 4 -1 4 -1 0 0 0 -1 

result:

wrong answer 8th numbers differ - expected: '7', found: '8'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #6:

score: 30
Accepted
time: 80ms
memory: 117172kb

input:

100000 355071 10000
5 7 4 7 4 1 10 5 9 4 9 4 3 10 5 4 9 1 7 10 1 6 10 3 10 9 8 4 6 3 10 8 6 8 3 5 10 9 7 7 1 3 8 8 6 2 8 4 2 9 1 10 3 6 3 8 9 10 5 7 3 2 1 5 7 4 3 4 6 4 2 7 2 5 5 6 4 6 7 4 4 6 4 2 3 9 9 9 10 8 1 6 7 2 9 8 2 3 1 6 9 4 10 3 10 1 2 3 3 4 1 1 1 5 8 6 8 3 1 6 2 9 5 9 4 7 2 10 7 5 2 2 7 4...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 100000 numbers

Test #7:

score: 30
Accepted
time: 74ms
memory: 111268kb

input:

100000 300561 10000
6 3 6 10 10 9 7 3 6 4 5 4 1 2 3 2 10 6 3 7 8 7 10 5 9 10 2 3 9 5 6 10 9 1 4 9 1 10 7 2 9 10 5 5 9 3 5 5 5 9 9 5 1 7 5 10 8 6 8 4 5 9 2 10 1 6 4 10 10 9 2 1 10 1 9 5 3 2 9 3 4 8 10 7 5 2 4 5 3 6 9 7 5 10 2 7 4 7 10 8 1 7 7 1 7 7 6 6 7 1 5 4 6 2 1 8 6 10 6 10 1 5 8 4 6 2 10 6 10 4 ...

output:

0 4 0 0 3 0 0 4 0 0 0 0 0 0 0 0 0 0 1 0 0 1 7 0 1 2 0 0 0 0 4 0 0 1 0 0 0 2 0 0 0 3 0 0 1 0 0 0 3 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 1 0 9 0 0 0 2 0 3 1 0 2 1 0 0 0 2 0 0 0 0 0 0 3 0 0 0 0 0 2 2 0 0 1 0 0 0 0 0 1 0 0 1 0 2 0 6 0 0 1 5 0 0 3 0 0 1 2 0 2 3 0 0 2 0 1 1 9 0 2 5 2 0 2 1 3 1 6 4 0 0 1 0 2 1 0 ...

result:

ok 100000 numbers

Test #8:

score: 0
Wrong Answer
time: 333ms
memory: 170404kb

input:

500000 1770902 50000
4 7 2 3 6 10 8 2 2 6 2 3 3 7 3 1 5 2 1 10 2 6 3 4 2 8 10 6 6 10 9 3 3 2 9 10 4 5 3 9 7 10 4 3 6 6 4 9 4 4 4 1 9 5 6 10 3 7 5 8 10 1 6 5 1 7 9 10 2 4 6 9 6 2 2 8 4 7 9 1 9 4 6 4 6 3 9 2 2 1 1 1 8 3 10 10 2 2 5 15 20 18 17 15 12 11 11 11 11 12 13 19 18 20 15 11 11 20 10 14 13 14 1...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 4 0 0 2 4 2 10 2 2 2 4 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 -1 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1...

result:

wrong answer 83rd numbers differ - expected: '1', found: '2'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%