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][25][24], nxt_win[N], s_win[N];
long long dmin[N][25][24];
long long sum[N][25][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 < n; ++i) nxt_win[i] = w[i], s_win[i] = s[i];
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] = s[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]);
}
}
}
// cout << w[0] << "aaaaaaa\n";
}
long long simulate(int i, int z) {
long long cur = z;
cout << dmin[0][13][0] << "aaaa\n";
for (int b = 0; b + 1 < pivot.size(); ++b) {
if (i == n) return cur;
if (cur >= pivot[b + 1]) continue;
assert(cur < pivot[b + 1]);
// if (b == 13) cout << dmin[i][b][23] << ' ' << cur << "aaaaaaaa\n";
// if (b == 13) cout << cur << '\n';
for (int lg = 23; lg >= 0; --lg) {
if (nxt[i][b][lg] == n || cur + sum[i][b][lg] >= pivot[b + 1] || dmin[i][b][lg] - cur <= 0) continue;
cur += sum[i][b][lg];
i = nxt[i][b][lg];
}
if (dmin[i][b][0] <= cur) {
cur += s_win[i];
i = nxt_win[i];
} else {
cur += sum[i][b][0];
i = nxt[i][b][0];
}
}
return cur;
}
//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;
//}
Compilation message (stderr)
dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:27:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int b = 0; b + 1 < pivot.size(); ++b) {
| ~~~~~~^~~~~~~~~~~~~~
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:58:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int b = 0; b + 1 < pivot.size(); ++b) {
| ~~~~~~^~~~~~~~~~~~~~
# | 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... |