#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ari2 = array<int, 2>;
using ari3 = array<int, 3>;
using arl2 = array<ll, 2>;
using arl3 = array<ll, 3>;
template <class T> using vt = vector<T>;
#define all(x) begin(x), end(x)
#define size(x) (int((x).size()))
#define REP(a,b,c,d) for(int a=(b);(d)>0?a<=(c):a>=(c);a+=(d))
#define FOR(a,b,c) REP(a,b,c,1)
#define ROF(a,b,c) REP(a,b,c,-1)
constexpr int mxN = 400005, LOG = 25;
vt<int> S, P, W, L;
int N;
int lift[LOG+1][mxN][LOG+1];
ll lift_val[LOG+1][mxN][LOG+1];
ll lift_cap[LOG+1][mxN][LOG+1];
ll depth[mxN];
ll simulate(int i, int zz) {
ll z = zz;
FOR(x, 0, LOG) {
if (z > 1 << (x+1))
continue;
ROF(j, LOG, 0)
if (z <= lift_cap[x][i][j]) {
z += lift_val[x][i][j];
i = lift[x][i][j];
}
z += S[i];
i = W[i];
}
return z + depth[i];
}
void init(int _N, vt<int> _S, vt<int> _P, vt<int> _W, vt<int> _L) {
N = _N, S = _S, P = _P, W = _W, L = _L;
S.push_back(0);
P.push_back(0);
W.push_back(N);
L.push_back(N);
ROF(i, N-1, 0)
depth[i] = depth[W[i]] + S[i];
FOR(x, 0, LOG) {
FOR(i, 0, N) {
if (S[i] > 1 << x) {
lift[x][i][0] = L[i];
lift_val[x][i][0] = P[i];
lift_cap[x][i][0] = S[i] - 1;
} else {
lift[x][i][0] = W[i];
lift_val[x][i][0] = S[i];
lift_cap[x][i][0] = LLONG_MAX;
}
}
FOR(j, 1, LOG)
FOR(i, 0, N) {
lift[x][i][j] = lift[x][lift[x][i][j-1]][j-1];
lift_val[x][i][j] = lift_val[x][lift[x][i][j-1]][j-1] + lift_val[x][i][j-1];
lift_cap[x][i][j] = min(lift_cap[x][i][j-1], lift_cap[x][lift[x][i][j-1]][j-1] - lift_val[x][i][j-1]);
}
}
}
Compilation message (stderr)
/tmp/ccJnWAoP.o: in function `main':
grader.cpp:(.text.startup+0x15e): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x165): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x183): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x18a): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x196): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x19d): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1ac): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1b3): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1bf): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1c6): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1d2): additional relocation overflows omitted from the output
/usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(ios_init.o): in function `std::ios_base::Init::Init()':
(.text._ZNSt8ios_base4InitC2Ev+0x1c): failed to convert GOTPCREL relocation against '_ZNSt8ios_base4Init11_S_refcountE'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x1c6): failed to convert GOTPCREL relocation against '_ZSt4cout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x260): failed to convert GOTPCREL relocation against '_ZSt3cin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x2e2): failed to convert GOTPCREL relocation against '_ZSt4cerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x353): failed to convert GOTPCREL relocation against '_ZSt4clog'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x541): failed to convert GOTPCREL relocation against '_ZSt5wcout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x5e5): failed to convert GOTPCREL relocation against '_ZSt4wcin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x670): failed to convert GOTPCREL relocation against '_ZSt5wcerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x6e9): failed to convert GOTPCREL relocation against '_ZSt5wclog'; relink with --no-relax
/usr/bin/ld: final link failed
collect2: error: ld returned 1 exit status