#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#define sig signed
#define int long long
#define vec vector
#define arr array
const int N = 4e5 + 5, LG = 27, INF = 1e18;
int n;
arr<int, N> wn, ls, wn_nd, ls_nd;
vec<int> unq;
int id(int x) {
int ans = 0;
for (int i = 0; i < unq.size(); i++)
if (x >= unq[i]) ans = i;
return ans;
}
int nx(int i) {
if (i + 1 == unq.size()) return INF;
else return unq[i + 1];
}
void unq_cmp() {
unq.push_back(0);
for (int u = 0; u < n; u++) unq.push_back(wn[u]);
unq.erase(unique(unq.begin(), unq.end()), unq.end());
// for (int x : unq) cout << x << " ";
// cout << '\n';
}
arr<arr<arr<vec<int>, N>, LG>, 10> jmp;
void jmp_cmp() {
for (int i = 0; i < unq.size(); i++) {
for (int u = 0; u <= n; u++) {
if (unq[i] >= wn[u])
jmp[i][0][u] = {wn_nd[u], wn[u], nx(i) - 1};
else
jmp[i][0][u] = {ls_nd[u], ls[u], nx(i) - 1};
}
for (int j = 1; j <= 25; j++) {
for (int u = 0; u <= n; u++) {
vec<int> x = jmp[i][j - 1][u];
vec<int> y = jmp[i][j - 1][x[0]];
jmp[i][j][u] = {y[0], x[1] + y[1], min(x[2], y[2] - x[1])};
}
}
}
// cout << jmp[0][1][0][0] << " " << jmp[0][1][0][1] << '\n';
}
void init(sig _n, vec<sig> _wn, vec<sig> _ls, vec<sig> _wn_nd, vec<sig> _ls_nd) {
n = _n;
for (int u = 0; u < n; u++)
wn[u] = _wn[u], ls[u] = _ls[u], wn_nd[u] = _wn_nd[u], ls_nd[u] = _ls_nd[u];
wn[n] = ls[n] = 0, wn_nd[n] = ls_nd[n] = n;
unq_cmp();
jmp_cmp();
}
void mv(int &u, int &s) {
if (u == n) return;
if (s >= wn[u]) {
s += wn[u];
u = wn_nd[u];
} else {
s += ls[u];
u = ls_nd[u];
}
}
int simulate(sig _u, sig _s) {
int u = _u, s = _s;
for (int i = 0; i < unq.size(); i++) {
for (int j = 25; j >= 0; j--) {
vec<int> x = jmp[i][j][u];
if (s > x[2]) continue;
if (x[0] == n) continue;
// cout << i << " " << j << " " << u << ": " << x[0] << " " << x[1] << '\n';
u = x[0], s += x[1];
}
mv(u, s);
if (u == n) break;
// cout << u << " " << s << '\n';
}
return s;
}
Compilation message (stderr)
/tmp/ccjG3vDr.o: in function `id(long long)':
dungeons.cpp:(.text+0x137): relocation truncated to fit: R_X86_64_PC32 against symbol `unq' defined in .bss section in /tmp/ccjG3vDr.o
dungeons.cpp:(.text+0x13e): relocation truncated to fit: R_X86_64_PC32 against symbol `unq' defined in .bss section in /tmp/ccjG3vDr.o
/tmp/ccjG3vDr.o: in function `nx(long long)':
dungeons.cpp:(.text+0x437): relocation truncated to fit: R_X86_64_PC32 against symbol `unq' defined in .bss section in /tmp/ccjG3vDr.o
dungeons.cpp:(.text+0x442): relocation truncated to fit: R_X86_64_PC32 against symbol `unq' defined in .bss section in /tmp/ccjG3vDr.o
/tmp/ccjG3vDr.o: in function `jmp_cmp()':
dungeons.cpp:(.text+0x485): relocation truncated to fit: R_X86_64_PC32 against symbol `unq' defined in .bss section in /tmp/ccjG3vDr.o
dungeons.cpp:(.text+0x49a): relocation truncated to fit: R_X86_64_PC32 against symbol `unq' defined in .bss section in /tmp/ccjG3vDr.o
dungeons.cpp:(.text+0x4b1): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccjG3vDr.o
dungeons.cpp:(.text+0x4e6): relocation truncated to fit: R_X86_64_PC32 against symbol `wn_nd' defined in .bss section in /tmp/ccjG3vDr.o
dungeons.cpp:(.text+0x560): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccjG3vDr.o
dungeons.cpp:(.text+0x574): relocation truncated to fit: R_X86_64_PC32 against symbol `unq' defined in .bss section in /tmp/ccjG3vDr.o
dungeons.cpp:(.text+0x57b): 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
collect2: error: ld returned 1 exit status