QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#356049 | #8237. Sugar Sweet II | USTC_fish_touching_team# | WA | 142ms | 3964kb | C++14 | 2.3kb | 2024-03-17 15:08:35 | 2024-03-17 15:08:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define Re register int
#define ll long long
const int N = 500005, Mod = 1e9 + 7;
int T, n, cnt, top, res, a[N], b[N], w[N], hea[N], nxt[N], to[N], q[N], d[N], f[N], len[N];
bool vis[N];
inline void add(int x, int y)
{
nxt[++cnt] = hea[x], to[cnt] = y, hea[x] = cnt;
}
inline ll fpow(ll x, int y)
{
ll ans = 1;
while (y)
{
if (y & 1) ans = ans * x % Mod;
x = x * x % Mod, y >>= 1;
}
return ans;
}
inline void dfs(int x)
{
if (vis[x])
{
while (top && q[top] ^ x) d[++res] = q[top--];
if (top) d[++res] = x;
return;
}
vis[x] = 1, q[++top] = x;
dfs(b[x]);
}
inline void dfs1(int x)
{
for (Re i = hea[x]; i; i = nxt[i])
{
int u = to[i];
if (f[u] != -1) continue;
len[u] = len[x] + 1, f[u] = 1ll * f[x] * fpow(len[u], Mod - 2) % Mod;
dfs1(u);
}
}
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
cnt = 0;
for (Re i = 1; i <= n; ++i) hea[i] = vis[i] = 0, len[i] = 1, f[i] = -1;
for (Re i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (Re i = 1; i <= n; ++i) scanf("%d", &b[i]), add(b[i], i);
for (Re i = 1; i <= n; ++i) scanf("%d", &w[i]);
for (Re i = 1; i <= n; ++i)
if (a[i] >= a[b[i]] + w[b[i]]) f[i] = 0;
else if (a[i] < a[b[i]]) f[i] = 1;
//printf("!!%d\n", f[1]);
for (Re i = 1; i <= n; ++i)
if (!vis[i])
{
res = top = 0;
dfs(i);
//printf("==%d\n", res);
if (!res) continue;
bool p = 0;
for (Re j = 1; j <= res; ++j)
if (f[d[j]] != -1)
{
p = 1;
break;
}
if (!p)
for (Re j = 1; j <= res; ++j) f[d[j]] = 0;
}
//printf("!!%d\n", f[1]);
for (Re i = 1; i <= n; ++i)
if (f[i] != -1) dfs1(i);
for (Re i = 1; i <= n; ++i)
{
ll ans = (1ll * w[i] * f[i] + a[i]) % Mod;
printf("%lld ", ans);
}
putchar('\n');
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3912kb
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: 142ms
memory: 3964kb
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'