QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#531139#8237. Sugar Sweet IIStayAloneWA 88ms28932kbC++142.9kb2024-08-24 18:34:182024-08-24 18:34:18

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-08-24 18:34:18]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:28932kb
  • [2024-08-24 18:34:18]
  • 提交

answer

#include <bits/stdc++.h>
#define rep1(i, l, r) for (int i = l; i <= int(r); ++i)
#define rep2(i, l, r) for (int i = l; i >= int(r); --i)
#define rer(i, l, r, a) rep1(i, l, r) read(a[i])
#define ptc putchar
#define il inline
#define eb emplace_back
#define ef emplace_front
#define mp make_pair
#define fst first
#define snd second
#define sqr(x) ((x) * (x))
#define ls(x) x << 1
#define rs(x) x << 1 | 1
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// typedef __int128 bll;
// typedef unsigned __int128 ubll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5 + 10, LOGN = log2(MAXN) + 1, inf = ~0U >> 2, INF = ~0U >> 1;
const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
namespace stupid_lrc {
	template <typename T> il bool read(T &x) {
		x = 0; bool f = false; char ch;
 		while (!isdigit(ch = getchar())) {
			f ^= !(ch ^ '-');
			if (ch == EOF) return false;
		}
		while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch & 15), ch = getchar();
		if (f) x = ~x + 1; return true;
	}
	il int read() {int x; read(x); return x;}

	template <typename T> il bool read(pair <T, T> &x) {return read(x.fst) && read(x.snd);}

	template <typename T> il void gmin(T &x, T y) {x = x < y ? x : y;}

 	template <typename T> il void gmax(T &x, T y) {x = x > y ? x : y;}

	template <typename T, typename ...L>
	il bool read(T &x, L &...y) {return read(x) && read(y...);}

	template <typename T> il T lowbit(const T &x) {return x & -x;}
}
using namespace stupid_lrc;
int n, a[MAXN], b[MAXN], w[MAXN], vis[MAXN], sk[MAXN], d[MAXN], ind[MAXN], cnt[MAXN]; ll prob[MAXN];
ll fac[MAXN], inv[MAXN];
const int mod = 1e9 + 7;

il int qpow(ll a, int b) {
	ll ans = 1;
	while (b) {
		if (b & 1) (ans *= a) %= mod;
		(a *= a) %= mod; b >>= 1;
	} return ans;
}

il int dp(int x) {
	if (cnt[x]) return d[x];
	++cnt[x];
	if (~sk[x]) return d[x] = 1;
	dp(b[x]);
	return d[x] = d[b[x]] ? d[b[x]] + 1 : 0;
}

il void solve() {
	read(n); rer(i, 1, n, a); rer(i, 1, n, b); rer(i, 1, n, w);
	rep1(i, 1, n) vis[i] = 1, sk[i] = -1, ind[i] = cnt[i] = d[i] = 0;
	rep1(i, 1, n) {
		if (a[i] < a[b[i]]) sk[i] = 1;
		else if (a[i] >= a[b[i]] + w[b[i]]) sk[i] = 0;
		++ind[b[i]];
	} queue <int> q;
	rep1(i, 1, n) if (!ind[i]) q.emplace(i);
	while (q.size()) {
		int x = q.front(); q.pop();
		vis[x] = 0;
		if (!--ind[b[x]]) q.emplace(b[x]);
	}
//	rep1(i, 1, n) cout << vis[i]; puts("");
	rep1(i, 1, n) if (vis[i]) dp(i);
	rep1(i, 1, n) prob[i] = ~sk[i] ? sk[i] : inv[d[i]];
	rep1(i, 1, n) printf("%lld ", (prob[i] * (a[i] + w[i]) + (1 + mod - prob[i]) * a[i]) % mod); puts("");
}

int main() {
	fac[0] = 1;
	rep1(i, 1, 5e5) fac[i] = fac[i - 1] * i % mod;
	inv[MAXN - 10] = qpow(fac[MAXN - 10], mod - 2);
	rep2(i, MAXN - 11, 1) inv[i] = inv[i + 1] * (i + 1) % mod;
	for (int T = read(); T--; ) solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 28664kb

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: 88ms
memory: 28932kb

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 375390750 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 512133948 963066959 
665922935 577926775 132646723 421298438 601054667 99438820...

result:

wrong answer 13th numbers differ - expected: '196759729', found: '375390750'