QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#531164 | #8237. Sugar Sweet II | StayAlone | WA | 84ms | 28936kb | C++14 | 3.0kb | 2024-08-24 18:51:56 | 2024-08-24 18:51:57 |
Judging History
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];
// cout << "??" << x << endl;
++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 << sk[i] << ' '; puts("");
rep1(i, 1, n) if (vis[i]) dp(i);
rep1(i, 1, n) if (!vis[i]) dp(i);
// cout << "??" << d[3] << endl;
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: 27468kb
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: 84ms
memory: 28936kb
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 67th numbers differ - expected: '777692470', found: '416086330'