QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#761765#8237. Sugar Sweet IITx_LcyWA 7ms16456kbC++141.3kb2024-11-19 10:02:512024-11-19 10:02:51

Judging History

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

  • [2024-11-19 10:02:51]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:16456kb
  • [2024-11-19 10:02:51]
  • 提交

answer

//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define add(x,y) (x=((x+y>=mod)?(x+y-mod):(x+y)))
int const N=5e5+10,mod=1e9+7;
int n,a[N],b[N],w[N],fac[N],inv[N];bool tg;
inline int qpow(int a,int b){int res=1;while (b){if (b&1) res*=a,res%=mod;a*=a,a%=mod,b>>=1;}return res;}
int C=0;
inline void solve(){
	cin>>n;
	rep(i,1,n) cin>>a[i];
	rep(i,1,n) cin>>b[i];
	rep(i,1,n) cin>>w[i];
	rep(i,18,18)
		if (a[i]<a[b[i]]) cout<<(a[i]+w[i])%mod<<' ';
		else if (b[i]==i || a[i]>=a[b[i]]+w[b[i]]) cout<<a[i]<<' ';
		else{
			int cnt=1,gl=0,tg=1,x=b[i];
			map<int,int>vis;
			while (!vis[x]){
				vis[x]=1,++cnt;
				if (b[x]==x || a[x]>=a[b[x]]+w[b[x]]){
					if (cnt==2) gl=0;
					break;
				}
				if (a[x]<a[b[x]]){
                    add(gl,inv[cnt]);
                    break;
                }
				x=b[x];
			}
			cout<<(a[i]+gl*w[i]%mod)%mod<<' ';
		}
	cout<<'\n';
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	fac[0]=1;
	rep(i,1,N-1) fac[i]=fac[i-1]*i%mod;
	inv[N-1]=qpow(fac[N-1],mod-2);
	per(i,N-2,0) inv[i]=inv[i+1]*(i+1)%mod;
	int t=1;
	cin>>t,tg=(t==50000);
	while (t--) solve();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 16456kb

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:

0 
0 
0 
0 

result:

wrong answer 1st numbers differ - expected: '500000007', found: '0'