QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#728116#8237. Sugar Sweet IIveg#WA 131ms19908kbC++141.1kb2024-11-09 14:36:012024-11-09 14:36:01

Judging History

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

  • [2024-11-09 14:36:01]
  • 评测
  • 测评结果:WA
  • 用时:131ms
  • 内存:19908kb
  • [2024-11-09 14:36:01]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
const int p=1e9+7;
using namespace std;

const int N=5e5+5;
ll inv[N],ans[N];
int a[N],b[N],w[N],d[N];
bool vis[N];

int ksm(ll a,int b) {
	ll ret=1;
	while(b) {
		if(b&1) ret=ret*a%p;
		a=a*a%p,b>>=1;
	}
	return ret;
}
int dfs(int u) {
	if(vis[u]) {
		return d[u];
	}
	vis[u]=1;
	int dep=dfs(b[u])+1; 
	if(a[u]<a[b[u]]) ans[u]=1,dep=0;
		else if(a[u]>=a[b[u]]+w[b[u]]) ans[u]=0,dep=0;
			else {
				if(ans[b[u]]) {
					ans[u]=inv[dep+1];
				} else ans[u]=0;
			}
	return d[u]=(ans[u]==0?0:dep);
}
int main() {
	ll jc=1;
	for(int i=2;i<=5e5;++i) jc=jc*i%p;
	inv[(int)5e5]=ksm(jc,p-2);
	for(int i=(int)5e5-1;i;--i) {
		inv[i]=inv[i+1]*(i+1)%p;
	}
	int T; scanf("%d",&T);
	while(T--) {
		int n; scanf("%d",&n);
		for(int i=1;i<=n;++i) {
			scanf("%d",&a[i]);
		}
		for(int i=1;i<=n;++i) {
			scanf("%d",&b[i]);
		}
		for(int i=1;i<=n;++i) {
			scanf("%d",&w[i]);
		}
		for(int i=1;i<=n;++i) {
			vis[i]=0; ans[i]=0,d[i]=0;
		}
		for(int i=1;i<=n;++i) {
			if(!vis[i]) {
				dfs(i);
			}
			printf("%lld ",(a[i]+w[i]*ans[i])%p);
		}
		puts("");
	}
	return 0;
}

详细

Test #1:

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

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: 131ms
memory: 19908kb

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'