QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#798321#9810. Obliviate, Then ReincarnateXJK404WA 682ms47264kbC++142.2kb2024-12-04 11:59:072024-12-04 11:59:08

Judging History

This is the latest submission verdict.

  • [2024-12-04 11:59:08]
  • Judged
  • Verdict: WA
  • Time: 682ms
  • Memory: 47264kb
  • [2024-12-04 11:59:07]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int tot,ver[2145141],head[2145141],nex[2145141],n,m,u,v,son[2145141];
int dfn[2145141],low[2145141],h[2145141],top,fa[2145141];
int stac[2145141],st,tot2,ver2[2145141],nex2[2145141],head2[2145141],h2[2145141];
queue<int> q;
int Q;
int ans[2145141]; 
long long edge[2145141];
void add(int x,int y,long long leng)
{
	nex[++tot]=head[x];
	head[x]=tot;
	ver[tot]=y;
	edge[tot]=leng;
}
void add2(int x,int y)
{
	nex2[++tot2]=head2[x];
	head2[x]=tot2;
	ver2[tot2]=y;
	son[y]++;
}
long long cal(long long A)
{
	return (A%n+n)%n;
}
map<long long,long long>ma;
int tarjan(int x,int fl)
{
	h[x]=1;
	stac[++st]=x;
	dfn[x]=low[x]=++top;
	for(int i=head[x];i;i=nex[i])
	{
		int y=ver[i];
		if(!dfn[y])
		{
			ma[y]=ma[x]+edge[i];
			fl=max(fl,tarjan(y,fl));
			low[x]=min(low[x],low[y]);
		}
		else
		{
			if(h[y])
			{
				if(ma[y]!=ma[x]+edge[i])fl=1;
				low[x]=min(low[x],dfn[y]);	
			} 
		}
	}
	if(dfn[x]==low[x])
	{
		int qq=st;
		while(stac[st]!=x)
		{
			fl=max(fl,ans[stac[st]]);
			fa[stac[st]]=x;
			h[stac[st]]=0;
			st--;
		}
		fl=max(fl,ans[x]);
		for(int i=st;i<=qq;i++)
			ans[stac[i]]=max(ans[stac[i]],fl);
		st--;
		h[x]=0;
	}
	return fl;
}
void topsort()
{
	for(int i=0;i<n;i++)
		if(son[fa[i]]==0)
			q.push(fa[i]);
	while(!q.empty())
	{
		int g=q.front();
		q.pop();
		if(h2[g]==0)
		{
			h2[g]=1;
			for(int i=head2[g];i;i=nex2[i])
			{
				int y=ver2[i];
				son[y]--;
				ans[y]=max(ans[y],ans[g]);
				if(son[y]==0)
				q.push(y);
			}
		}
	}	
}
string P(int x)
{
	if(x==1)return "Yes";
	return "No";
}
int main()
{
	cin>>n>>m>>Q;
	for(int i=1;i<=m;i++)
	{
		cin>>u>>v;
		add(cal(u),cal(u+v),v);
	//	cout<<cal(u)<<' '<<cal(u+v)<<' '<<v<<endl;
	}
	for(int i=0;i<n;i++)
	fa[i]=i;
	for(int i=0;i<n;i++)
	{
		if(!dfn[i])
		{
			ma.clear();
			tarjan(i,0);
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=head[i];j;j=nex[j])
		{
			int y=ver[j];
			if(fa[i]!=fa[y])
			{
				add2(fa[y],fa[i]);
			}
		}
	}
	topsort();
	for(int i=1;i<=Q;i++)
	{
		long long FT;
		cin>>FT;
		FT=cal(FT);
		cout<<P(ans[FT])<<endl;
	}
	return 0;
}
/*
5 5 5
2 -1
3 -1
3 1 
4 -11
3 2
0
1
2
3
4
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 22320kb

input:

3 2 3
1 1
-1 3
1
2
3

output:

Yes
Yes
No

result:

ok 3 tokens

Test #2:

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

input:

3 2 3
1 1
-1 0
1
2
3

output:

No
No
No

result:

ok 3 tokens

Test #3:

score: 0
Accepted
time: 2ms
memory: 15824kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

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

input:

3 2 3
0 1000000000
1 -1000000000
-1000000000
0
-1000000000

output:

No
No
No

result:

ok 3 tokens

Test #5:

score: 0
Accepted
time: 677ms
memory: 40316kb

input:

50134 500000 500000
-154428638 -283522863
-186373509 -327130969
154999046 46750274
-933523447 349415487
-437683609 140099255
864996699 -262318199
811293034 -264299324
120273173 52410685
874944410 -52048424
445049930 -803690605
-138111276 -104634331
720288580 126597671
471164416 -348777147
-356502322...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 500000 tokens

Test #6:

score: -100
Wrong Answer
time: 682ms
memory: 47264kb

input:

100848 500000 500000
720352587 361776806
231853504 -933882325
960971230 -83519300
-152772415 -631132247
842871215 -666621297
857194330 -754943024
-698506963 -705416545
-3551931 -927937446
628710320 -942247987
674921043 847145884
-325629529 475694308
-339363446 686789318
236702996 654762989
420412365...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

wrong answer 25th words differ - expected: 'No', found: 'Yes'