QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#761734#8237. Sugar Sweet IIMine_KingWA 7ms16144kbC++141.7kb2024-11-19 09:41:242024-11-19 09:41:24

Judging History

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

  • [2024-11-19 09:41:24]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:16144kb
  • [2024-11-19 09:41:24]
  • 提交

answer

// Think twice, code once.
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define eputchar(c) putc(c, stderr)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define eputs(str) fputs(str, stderr), putc('\n', stderr)
using namespace std;

const int mod = 1e9 + 7;

int T, n, a[500005], p[500005], w[500005], q[500005];
int fac[500005], inv[500005];
int ans[500005];

void solve(int st) {
	ans[st] = 1;
	int now = q[st];
	while (now != st) {
		if (ans[now] != - 1 || a[now] < a[p[now]] || a[now] >= a[p[now]] + w[p[now]]) break;
		ans[now] = ans[p[now]] + 1;
		now = q[now];
	}
	for (int j = q[st]; j != now; j = q[j]) ans[j] = inv[ans[j]] % mod;
	return;
}

int main() {
	fac[0] = fac[1] = 1;
	inv[0] = inv[1] = 1;
	for (int i = 2; i <= 500000; i++) {
		fac[i] = (long long)fac[i - 1] * i % mod;
		inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;
	}
	for (int i = 2; i <= 500000; i++) inv[i] = (long long)inv[i - 1] * inv[i] % mod;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for (int i = 1; i <= n; i++) scanf("%d", &p[i]), q[p[i]] = i;
		for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
		for (int i = 1; i <= n; i++) ans[i] = -1;
		for (int i = 1; i <= n; i++)
			if (ans[i] == -1 && a[i] >= a[p[i]] + w[p[i]]) {
				ans[i] = 0;
				if (p[i] == i) continue;
				for (int j = q[i]; j != i; j = q[j])
					if (ans[j] != -1 && a[j] >= a[p[j]]) ans[j] = 0;
					else break;
			} else if (ans[i] == -1 && a[i] < a[p[i]]) solve(i);
		for (int i = 1; i <= n; i++)
			if (ans[i] == -1) ans[i] = 0;
		for (int i = 1; i <= n; i++) printf("%lld ", (a[i] + (long long)ans[i] * w[i]) % mod);
		puts("");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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 
3 4 3 4 5 

result:

wrong answer 11th numbers differ - expected: '500000006', found: '3'