QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574209#8237. Sugar Sweet IIzrzringWA 123ms3872kbC++201.9kb2024-09-18 21:05:552024-09-18 21:05:56

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-09-18 21:05:56]
  • 评测
  • 测评结果:WA
  • 用时:123ms
  • 内存:3872kb
  • [2024-09-18 21:05:55]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using A2 = std::array<i64, 2>;

#define Fast_IOS std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)

const i64 mod = 1e9 + 7;

template <class T>
T MOD(T& x, i64 p = mod) {
	return x = (x % p + p) % p;
}
template <class T>
T MOD(T&& x, i64 p = mod) {
	return x = (x % p + p) % p;
}

i64 qpow(i64 a, i64 x = mod - 2) {
	a %= mod;
	x %= mod - 1;
	i64 res = 1;
	while (x) {
		if (x & 1) res = res * a % mod;
		a = a * a % mod;
		x >>= 1;
	}
	return res;
}

class WORK {
public:
	int N;

	WORK() {}

	void solve() {
		int n;
		std::cin >> n;
		std::vector<i64> a(n + 1), to(n + 1), b(n + 1), fac(n + 1), ifac(n + 1);
		for (int i = 1; i <= n; i++) {
			std::cin >> a[i];
		}
		for (int i = 1; i <= n; i++) {
			std::cin >> to[i];
		}
		for (int i = 1; i <= n; i++) {
			std::cin >> b[i];
		}
		fac[0] = 1;
		for (int i = 1; i <= n; i++) {
			fac[i] = fac[i - 1] * i % mod;
		}
		ifac[n] = qpow(fac[n]);
		for (int i = n - 1; i >= 0; i--) {
			ifac[i] = ifac[i + 1] * (i + 1) % mod;
		}
		std::vector<i64> dep(n + 1), vis(n + 1);
		auto dfs = [&](auto self, int u) -> void {
			vis[u] = 1;
			int v = to[u];
			if (a[u] < a[v]) {
				dep[u] = 1;
				return;
			}
			if (to[u] == u || a[u] >= a[v] + b[v]) {
				dep[u] = -1;
				return;
			}
			if (dep[v]) {
				dep[u] = dep[v] + 1;
				return;
			}
			if (vis[v]) {
				dep[u] = -1;
				return;
			}
			self(self, v);
			if (dep[v] == -1) dep[u] = -1;
			else dep[u] = dep[v] + 1;
		};
		for (int i = 1; i <= n; i++) {
			if (!dep[i]) dfs(dfs, i);
		}
		for (int i = 1; i <= n; i++) {
			if (dep[i] == -1) {
				std::cout << a[i] << " \n"[i == n];
			} else {
				std::cout << (a[i] + b[i] * ifac[dep[i]]) % mod << " \n"[i == n];
			}
		}
	}
};

int main() {
	Fast_IOS;
	WORK work;
	int T = 1;
	std::cin >> T;
	while (T--) {
		work.solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3872kb

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: 123ms
memory: 3712kb

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
665922935 902719894 132646723 421298438 601054667 99438820 94...

result:

wrong answer 26th numbers differ - expected: '577926775', found: '902719894'