QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#342893#8237. Sugar Sweet IIucup-team191#WA 191ms11548kbC++231.9kb2024-03-01 19:19:542024-03-01 19:19:55

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-03-01 19:19:55]
  • 评测
  • 测评结果:WA
  • 用时:191ms
  • 内存:11548kb
  • [2024-03-01 19:19:54]
  • 提交

answer

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)

const int N=500010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;

int t, n;
ll a[N], b[N], w[N], bio[N], d[N];
ll fact[N], finv[N];

int add (int x, int y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}

int sub (int x, int y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}

int mul (int x, int y) {
	return (ll) x * y % MOD;
}

int pot (int x, int e) {
	if (e == 0) return 1;
	if (e == 1) return x;
	int res = pot(x, e / 2);
	res = mul(res, res);
	if (e % 2 == 1) res = mul(res, x);
	return res;
}

int inv (int x) {
	return pot(x, MOD - 2);
}

void precompute () {
	fact[0] = finv[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = mul(i, fact[i - 1]);
		finv[i] = inv(fact[i]);
	}
}

int calc (int x) {
	if (d[x] != -1) return d[x];
	bio[x] = 1;
	if (a[x] >= a[b[x]] + w[b[x]]) {
		bio[x] = 2;
		d[x] = 0;
		return 0;
	} else if (a[x] < a[b[x]]) {
		bio[x] = 2;
		d[x] = 1;
		return 1;
	} else if (bio[b[x]] == 1) {
		bio[x] = 2;
		d[x] = 0;
		return 0;
	}
	int res = 1 + calc(b[x]);
	bio[x] = 2;
	d[x] = res;
	return res;
}

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	precompute();
	cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			bio[i] = 0;
			d[i] = -1;
		}
		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++) {
			int k = calc(i);
			int sol;
			if (k == 0) {
				sol = a[i];
			} else {
				sol = add(mul(finv[k], add(a[i], w[i])), mul(sub(1, finv[k]), a[i]));
			}
			cout << sol << " ";
		}
		cout << '\n';
	}
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 85ms
memory: 11392kb

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: 191ms
memory: 11548kb

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 590444253 906393935 859123744 
863886789 
871186919 814243920 968784984 206455474 17527050 449261413 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 482247153 963066959 
138645134 902719894 132646723 421298438 601054667 99438820...

result:

wrong answer 25th numbers differ - expected: '665922935', found: '138645134'