QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358567#8237. Sugar Sweet IICokeWA 5ms31760kbC++141.4kb2024-03-19 21:06:492024-03-19 21:06:49

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-03-19 21:06:49]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:31760kb
  • [2024-03-19 21:06:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cerr<<#x<<' '<<x<<endl;
typedef pair<int,int>PII;
typedef long long LL;
constexpr int N=500010,mod=1e9+7;
int a[N],b[N],w[N],p[N],d[N];
vector<int>e[N];
int fact[N],infact[N];
int ksm(int a,int b)
{
	int res=1;
	while(b>0)
	{
		if(b&1)res=res*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return res;
}
void dfs(int x)
{
	for(auto y:e[x])
	{
		d[y]=d[x]+1;
		dfs(y);
	}
}
signed main()
{
	//freopen(".in","r",stdin);freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int t;
	fact[0]=1;
	for(int i=1;i<N;i++)fact[i]=fact[i-1]*i%mod;
	infact[N-1]=ksm(fact[N-1],mod-2);
	for(int i=N-2;i>=0;i--)
	infact[i]=infact[i+1]*(i+1)%mod;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i],e[i].clear(),p[i]=-1,d[i]=0;
		for(int i=1;i<=n;i++)cin>>b[i];
		for(int i=1;i<=n;i++)cin>>w[i];
		vector<int>v;
		for(int i=1;i<=n;i++)
		{
			if(a[i]>=a[b[i]]+w[b[i]])d[i]=0,v.push_back(i);
			else if(a[i]<a[b[i]])d[i]=1,v.push_back(i);
			else e[b[i]].push_back(i);
		}
		for(auto c:v)
		{	
			if(d[c]>0)
			dfs(c);
		}
		vector<int>ans(n+1);
		for(int i=1;i<=n;i++)
		{
			if(p[i]==0)ans[i]=a[i];
			else 
			{
				ans[i]=(a[i]+w[i]*ksm(fact[d[i]],mod-2)%mod)%mod;
			}
			cout<<ans[i]<<' ';
		}
		cout<<endl;
	}

}

详细

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 31760kb

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 7 6 6 
11 10 9 
166666673 5 6 
500000006 4 7 4 5 

result:

wrong answer 2nd numbers differ - expected: '5', found: '7'