QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#485643 | #8237. Sugar Sweet II | Swarthmore# | WA | 203ms | 17316kb | C++20 | 2.0kb | 2024-07-20 22:06:24 | 2024-07-20 22:06:25 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
const char nl = '\n';
const ll MOD = 1000000007;
ll modExp(ll base, ll power) {
if (power == 0) {
return 1;
} else {
ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
if (power % 2 == 1) cur = cur * base;
cur = cur % MOD;
return cur;
}
}
const int MX = 500001;
int ans[MX];
vector<vi> graph;
ll A[MX], B[MX], W[MX];
ll facs[MX], facInvs[MX];
void dfs(int v, int d) {
ans[v] += W[v] * facInvs[d];
ans[v] %= MOD;
trav(a, graph[v]) {
dfs(a, d+1);
}
}
void solve() {
int N; cin >> N;
F0R(i, N) cin >> A[i];
F0R(i, N) cin >> B[i];
F0R(i, N) B[i]--;
F0R(i, N) cin >> W[i];
vi rts;
graph = vector<vi>(N);
F0R(i, N) {
if (A[i] < A[B[i]]) {
rts.pb(i);
} else if (A[i] < A[B[i]] + W[B[i]]) {
graph[B[i]].pb(i);
}
}
F0R(i, N) {
ans[i] = A[i];
}
trav(a, rts) {
dfs(a, 1);
}
F0R(i, N) {
cout << ans[i] << " ";
}
cout << nl;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
facs[0] = 1;
FOR(i, 1, MX) facs[i] = (facs[i-1]*i)%MOD;
F0R(i, MX) facInvs[i] = modExp(facs[i], MOD-2);
int T; cin >> T;
while (T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 84ms
memory: 16900kb
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: 203ms
memory: 17316kb
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 236762753 138675051 859123744 863886789 871186919 814243920 968784984 206455474 255018117 449261413 -151639591 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 -343015936 963066959 665922935 577926775 -340671849 421298438 601054667 9943...
result:
wrong answer 3rd numbers differ - expected: '590444253', found: '236762753'