QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#401892#8237. Sugar Sweet IIyoungerWA 51ms11700kbC++202.4kb2024-04-29 16:17:052024-04-29 16:17:06

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-04-29 16:17:06]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:11700kb
  • [2024-04-29 16:17:05]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
const int mod = 1e9 + 7 , N = 5e5 + 10;
int n;
int h[N] , ne[2 * N] , e[2 * N] , idx;
LL a[N] , b[N] , w[N] , f[N] , inv[N];
LL ans[N] , d[N];
bool st[N];

LL ksm(LL a , LL b)
{
	LL res = 1;
	while(b)
	{
		if(b & 1)res = res * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return res % mod;
}

void init()
{
	f[0] = inv[0] = 1;
	for(int i = 1 ; i <= 500000 ; i ++){
		f[i] = f[i - 1] * i % mod;
		inv[i] = ksm(f[i] , mod - 2);
	}
	return;
}

LL C(LL a , LL b)
{
	if(a < b)return 0;
	return (((f[a] * inv[b] + mod) % mod) * inv[a - b] + mod) % mod;
}

LL pmod(LL a , LL b)
{
	return (a * b % mod + mod) % mod;
}

LL amod(LL a , LL b)
{
	return (a % mod + b % mod) % mod;
}

LL mmod(LL a , LL b)
{
	return (a - b + mod) % mod;
}

void add(int a , int b)
{
	e[idx] = b , ne[idx] = h[a] , h[a] = idx ++;
	return;
}

void dfs(LL u , LL now){
	ans[u] = pmod(pmod(pmod(C(n , now) , f[n - now]) , inv[n]) , (a[u] + w[u]) % mod) % mod;
	ans[u] = amod(ans[u] % mod , pmod(a[u] , pmod(inv[n] , mmod(f[n] , pmod(C(n , now) , f[n - now])))));
	for(int i = h[u] ; ~ i ; i = ne[i]){
		int j = e[i];
		dfs(j , now + 1);
	}
	return;
}

void Asuka()
{
	cin >> n;
	idx = 0;
	for(int i = 1 ; i <= n ; i ++)cin >> a[i];
	for(int i = 1 ; i <= n ; i ++)cin >> b[i];
	for(int i = 1 ; i <= n ; i ++)cin >> w[i];
	for(int i = 1 ; i <= n ; i ++){
		ans[i] = 0;d[i] = 0;h[i] = -1;st[i] = false;
	}
	vector<int>node;
	for(int i = 1 ; i <= n ; i ++){
		if(a[b[i]] > a[i]){
			ans[i] = (a[i] + w[i]) % mod;
			node.emplace_back(i);
		}else if(a[i] >= a[b[i]] + w[b[i]] || b[i] == i){
			ans[i] = a[i] % mod;
			node.emplace_back(i);
		}else{
			add(b[i] , i);
		}
	}
	for(auto t : node){
		dfs(t , 1ll);
	}
	for(int i = 1 ; i <= n ; i ++){
		if(ans[i] == 0)ans[i] = a[i];
		cout << ans[i] << ' ';
	}
	cout << '\n';
	return;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	init();
	int t = 1;
	cin >> t;
	while(t --){
		Asuka();
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 51ms
memory: 11700kb

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'