This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int K = 30;
const int N = 400400;
int n, m;
int s[N];
int p[N];
int w[N];
int l[N];
int maximum;
ll dp0[N];
int dp1[2][K][N];
int dp2[2][K][N];
ll dp3[2][K][N];
void init(int n, vector<int> S, vector<int> P, vector<int> W, vector<int> L) {
::n = n;
copy(S.begin(), S.end(), s);
copy(P.begin(), P.end(), p);
copy(W.begin(), W.end(), w);
copy(L.begin(), L.end(), l);
maximum = *max_element(S.begin(), S.end());
for (int i = n - 1; ~i; --i) {
dp0[i] = s[i] + dp0[w[i]];
}
l[n] = w[n] = n;
for (int i = 0; i <= n; i++) {
dp1[0][0][i] = l[i];
dp2[0][0][i] = s[i];
dp3[0][0][i] = p[i];
dp1[1][0][i] = w[i];
dp2[1][0][i] = s[i];
dp3[1][0][i] = s[i];
}
for (int r = 0; r < 2; r++) {
for (int j = 1; j < K; j++) {
for (int i = 0; i <= n; i++) {
dp1[r][j][i] = dp1[r][j - 1][dp1[r][j - 1][i]];
dp3[r][j][i] = dp3[r][j - 1][i] + dp3[r][j - 1][dp1[r][j - 1][i]];
}
}
}
for (int j = 1; j < K; j++) {
for (int i = 0; i <= n; i++) {
dp2[0][j][i] = min(dp2[0][j - 1][i], dp2[0][j - 1][dp1[0][j - 1][i]]);
dp2[1][j][i] = max(dp2[1][j - 1][i], dp2[1][j - 1][dp1[1][j - 1][i]]);
}
}
}
ll simulate(int i, int z) {
ll x = z;
while (i < n && x < maximum) {
for (int j = K - 1; ~j; --j) {
if (dp2[0][j][i] > x) {
x += dp3[0][j][i];
i = dp1[0][j][i];
}
}
for (int j = K - 1; ~j; --j) {
if (dp2[1][j][i] <= x) {
x += dp3[1][j][i];
i = dp1[1][j][i];
}
}
}
x += dp0[i];
i = n;
return x;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |