QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#633378#8237. Sugar Sweet IILateRegistration#WA 103ms21248kbC++201.5kb2024-10-12 15:13:022024-10-12 15:13:04

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-12 15:13:04]
  • 评测
  • 测评结果:WA
  • 用时:103ms
  • 内存:21248kb
  • [2024-10-12 15:13:02]
  • 提交

answer

#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
using namespace std;
inline int read()
{
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int a[500005],b[500005],w[500005];
int zt[500005],dp[500005];
void dfs(int x)
{
	if(zt[x]!=-2)return;
	if(b[x]==x)
	{
		zt[x]=0;
		dp[x]=0;
		return;
	}
	zt[x]=-1;
	dfs(b[x]);
	if(a[x]>=a[b[x]]+w[b[x]])
	{
		zt[x]=0;
		dp[x]=0;
		return;
	}
	if(a[x]<a[b[x]])
	{
		zt[x]=1;
		dp[x]=1;
		return;
	}
	if(zt[b[x]]==1)
	{
		zt[x]=1;
		dp[x]=dp[b[x]]+1;
	}
	else zt[x]=0,dp[x]=0;
	return;
}
int jc[500005],njc[500005];
int ksm(int n,int k)
{
	int ans=1;
	while(k>=1)
	{
		if(k&1)ans=1LL*ans*n%mod;
		k>>=1;
		n=1LL*n*n%mod; 
	}
	return ans;
}
signed main()
{
	jc[0]=1;
	for(int i=1;i<=500000;i++)jc[i]=1LL*i*jc[i-1]%mod;
	njc[500000]=ksm(jc[500000],mod-2);
	for(int i=499999;i>=0;i--)njc[i]=1LL*(i+1)*njc[i+1]%mod; 
	int t,n;
	t=read();
	for(int greg=1;greg<=t;greg++)
	{
		n=read();
		for(int i=1;i<=n;i++)
		{
			a[i]=read();			
		}
		for(int i=1;i<=n;i++)
		{
			b[i]=read();
		}
		for(int i=1;i<=n;i++)
		{
			w[i]=read();
		}
		for(int i=1;i<=n;i++)
		{
			zt[i]=-2;
			dp[i]=0;
		}
		for(int i=1;i<=n;i++)
		{
			if(zt[i]==-2)dfs(i);
		}
		for(int i=1;i<=n;i++)
		{
			if(zt[i]==0)printf("%lld ",a[i]);
			else printf("%lld ",(a[i]+1LL*w[i]*njc[dp[i]])%mod);
		}
		printf("\n");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
4
2 5 5 2
4 2 1 3
3 2 1 4
3
5 4 3
1 1 1
6 6 6
3
5 4 3
2 3 1
1 2 3
5
2 1 3 2 1
5 1 1 3 4
1 3 4 2 4

output:

500000007 5 5 6 
5 10 9 
166666673 5 6 
500000006 4 3 4 5 

result:

ok 15 numbers

Test #2:

score: -100
Wrong Answer
time: 103ms
memory: 21248kb

input:

50000
5
508432375 168140163 892620793 578579275 251380640
3 4 4 1 3
346232959 736203130 186940774 655629320 607743104
1
863886789
1
364158084
18
864679185 463975750 558804051 604216585 694033700 499417132 375390750 337590759 467353355 111206671 983760005 984444619 322277587 138763925 205122047 97736...

output:

854665334 904343293 892620793 578579275 859123744 
863886789 
871186919 814243920 968784984 206455474 694033700 449261413 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 482247153 963066959 
665922935 577926775 132646723 421298438 601054667 9943882...

result:

wrong answer 3rd numbers differ - expected: '590444253', found: '892620793'