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 "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
const int N = 4 * (int)1e5;
const int C = 4;
const int H = 24 / C;
pair<int, ll> jmp[N + 1][H][H];
ll add[N + 1];
ll str[N + 1];
ll bns[N + 1];
int wt[N + 1];
int lt[N + 1];
int n;
pair<int, ll> advance(pair<int, ll> cur) {
if (str[cur.first] > cur.second) return {lt[cur.first], bns[cur.first] + cur.second};
else return {wt[cur.first], str[cur.first] + cur.second};
}
void init(int n_, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
n = n_;
for (int i = 0; i < n; ++i) str[i] = s[i];
for (int i = 0; i < n; ++i) bns[i] = p[i];
for (int i = 0; i < n; ++i) wt[i] = w[i];
for (int i = 0; i < n; ++i) lt[i] = l[i];
str[n] = 0;
bns[n] = 0;
wt[n] = n;
lt[n] = n;
add[n] = 0;
for (int i = n-1; i >= 0; --i) add[i] = add[wt[i]] + str[i];
for (int a = 0; a < H; ++a) {
ll lo = 1 << (C * a);
ll hi = 1 << (C * (a + 1));
for (int i = 0; i <= n; ++i) {
if ((lo <= str[i] && str[i] < hi) || i == n) {
jmp[i][a][0] = {i, INF};
} else if (str[i] < lo) {
jmp[i][a][0] = {wt[i], str[i]};
} else {
jmp[i][a][0] = {lt[i], bns[i]};
}
}
for (int b = 1; b < H; ++b) {
for (int i = 0; i <= n; ++i) {
pair<int, ll> res = {i, 0ll};
for (int it = 0; it < (1 << C); ++it) {
res.second += jmp[res.first][a][b - 1].second;
res.first = jmp[res.first][a][b - 1].first;
}
jmp[i][a][b] = res;
}
}
}
}
long long simulate(int start_i, int ini_pwr) {
pair<int, ll> state = {start_i, (ll)ini_pwr};
for (int a = 0; a < H; ++a) {
ll lo = 1 << (C * a);
ll hi = 1 << (C * (a + 1));
while(state.first != n && lo <= state.second && state.second < hi) {
for (int b = H-1; b >= 0; --b) {
while(state.second + jmp[state.first][a][b].second < hi) {
state.second += jmp[state.first][a][b].second;
state.first = jmp[state.first][a][b].first;
}
}
state = advance(state); // either fight against opponent in same strength bracket, or break out of strength bracket
}
}
return state.second + add[state.first];
}
# | 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... |