QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#761758 | #8237. Sugar Sweet II | Mine_King | WA | 132ms | 20288kb | C++14 | 2.2kb | 2024-11-19 09:58:34 | 2024-11-19 09:58:35 |
Judging History
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];
int fac[500005], inv[500005];
int ans[500005];
struct graph {
int tot, hd[500005];
int nxt[1000005], to[1000005];
void clear(int n) {tot = 0; memset(hd, 0, sizeof(int) * n); return;}
void add(int u, int v) {
nxt[++tot] = hd[u];
hd[u] = tot;
to[tot] = v;
return;
}
} g;
void solve(int now, int dep, int root) {
if (dep > 1 && now == root) return;
if (dep > 1 && (a[now] < a[p[now]] || a[now] >= a[p[now]] + w[p[now]])) return;
ans[now] = dep > 1 ? inv[dep] % mod : 1;
for (int i = g.hd[now]; i; i = g.nxt[i]) solve(g.to[i], dep + 1, root);
return;
}
void solve2(int now) {
ans[now] = 0;
for (int i = g.hd[now]; i; i = g.nxt[i])
if (ans[g.to[i]] == -1 && a[g.to[i]] >= a[now]) solve2(g.to[i]);
}
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);
for (int Case = 1; T--; Case++) {
scanf("%d", &n);
g.clear(n + 5);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) scanf("%d", &p[i]), g.add(p[i], i);
for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
if (Case == 15) printf("%d\n", n);
for (int i = 1; i <= n; i++) ans[i] = -1;
for (int i = 1; i <= n; i++)
if (ans[i] == -1 && (p[i] == i || a[i] >= a[p[i]] + w[p[i]])) {
ans[i] = 0;
for (int j = g.hd[i]; j; j = g.nxt[j])
if (g.to[j] != i && a[g.to[j]] >= a[i]) solve2(g.to[j]);
} else if (ans[i] == -1 && a[i] < a[p[i]]) solve(i, 1, i);
for (int i = 1; i <= n; i++)
if (ans[i] == -1) ans[i] = 1;
for (int i = 1; i <= n; i++) printf("%lld ", (a[i] + (long long)ans[i] * w[i]) % mod);
puts("");
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 18244kb
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: 132ms
memory: 20288kb
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 577926775 132646723 421298438 601054667 99438820...
result:
wrong answer 126th numbers differ - expected: '269655833', found: '1'