# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
562999 | hoanghq2004 | Dungeons Game (IOI21_dungeons) | C++17 | 0 ms | 0 KiB |
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>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "dungeons.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 5e4 + 10;
int n;
int nxt[N][24][24];
long long dmin[N][24][24];
long long sum[N][24][24];
vector <long long> pivot;
void init(int _n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) {
n = _n;
for (int i = 0; i < 24; ++i) pivot.push_back(1 << i);
pivot.push_back(1e18);
for (int b = 0; b + 1 < pivot.size(); ++b) {
for (int i = 0; i < n; ++i) {
if (s[i] < pivot[b]) {
nxt[i][b][0] = w[i];
dmin[i][b][0] = 1e18;
sum[i][b][0] = s[i];
} else if (s[i] >= pivot[b + 1]) {
nxt[i][b][0] = l[i];
dmin[i][b][0] = 1e18;
sum[i][b][0] = p[i];
} else {
nxt[i][b][0] = l[i];
dmin[i][b][0] = w[i];
sum[i][b][0] = p[i];
}
}
nxt[n][b][0] = n;
for (int lg = 1; lg < 24; ++lg) {
for (int i = 0; i <= n; ++i) {
nxt[i][b][lg] = nxt[nxt[i][b][lg - 1]][b][lg - 1];
sum[i][b][lg] = sum[i][b][lg - 1] + sum[nxt[i][b][lg - 1]][b][lg - 1];
dmin[i][b][lg] = min(dmin[i][b][lg - 1], dmin[nxt[i][b][lg - 1]][b][lg - 1] - sum[i][b][lg - 1]);
}
}
}
}
long long simulate(int i, long long z) {
for (int b = 0; b + 1 < pivot.size(); ++b) {
if (i == n) return z;
if (z >= pivot[b + 1]) continue;
for (int lg = 24; lg >= 0; --lg) {
if (nxt[i][b][lg] == n || z + sum[i][b][lg] >= pivot[b + 1] || dmin[i][b][lg] - z <= 0) continue;
z += sum[i][b][lg];
i = nxt[i][b][lg];
}
z += sum[i][b][0];
i = nxt[i][b][0];
}
return z;
}
//int main() {
// int n, q;
// std::vector<int> s, p, z;
// std::vector<int> w, l, x;
// std::vector<long long> answer;
//
// assert(scanf("%d %d", &n, &q) == 2);
// s.resize(n);
// p.resize(n);
// w.resize(n);
// l.resize(n);
// x.resize(q);
// z.resize(q);
// answer.resize(q);
//
// for (int i = 0; i < n; i++) {
// assert(scanf("%d", &s[i]) == 1);
// }
// for (int i = 0; i < n; i++) {
// assert(scanf("%d", &p[i]) == 1);
// }
// for (int i = 0; i < n; i++) {
// assert(scanf("%d", &w[i]) == 1);
// }
// for (int i = 0; i < n; i++) {
// assert(scanf("%d", &l[i]) == 1);
// }
//
//
// init(n, s, p, w, l);
//
// for (int i = 0; i < q; i++) {
// assert(scanf("%d %d", &x[i], &z[i]) == 2);
// answer[i] = simulate(x[i], z[i]);
// }
// fclose(stdin);
//
// for (int i = 0; i < q; i++) {
// printf("%lld\n", answer[i]);
// }
// fclose(stdout);
// return 0;
//}