# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550861 | topovik | 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>
#define pb push_back
#define f first
#define s second
#define pi acos(-1)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll oo = 1e18;
const ld eps = (ld)1 / oo;
const ll N = 2e5 + 100;
const ll M = 24;
vector <vector <vector <pair<ll, ll> > > > binpow;
vector <ll> str;
vector <ll> s, p, w, l;
ll n;
void init(ll n1, vector <ll> s1, vector <ll> p1, vector <ll> w1, vector <ll> l1)
{
n = n1;
s = s1, p = p1, w = w1, l = l1;
for (ll i = 0; i < n; i++) str.pb(s[i]);
str.pb(0);
sort(str.begin(), str.end());
str.resize(unique(str.begin(), str.end()) - str.begin());
binpow.resize(str.size());
for (ll i = 0; i < str.size(); i++)
{
binpow[i].resize(n + 1);
for (ll j = 0; j <= n; j++) binpow[i][j].resize(M);
for (ll j = 0; j < n; j++)
if (s[j] > str[i]) binpow[i][j][0] = {l[j], p[j]};
else binpow[i][j][0] = {w[j], s[j]};
binpow[i][n][0] = {n, 0};
for (ll c = 1; c < M; c++)
{
for (ll j = 0; j <= n; j++)
{
ll nx = binpow[i][j][c - 1].f;
binpow[i][j][c].f = binpow[i][nx][c - 1].f;
binpow[i][j][c].s = binpow[i][j][c - 1].s + binpow[i][nx][c - 1].s;
}
}
}
str.pb(oo);
}
ll simulate(ll x, ll y1)
{
ll y = y1;
for (ll i = 0; i < str.size(); i++)
{
if (y < str[i])
{
for (ll j = M - 1; j >= 0; j--)
if (y + binpow[i - 1][x][j].s < str[i]) y += binpow[i - 1][x][j].s, x = binpow[i - 1][x][j].f;
if (x == n) return y;
if (y > s[x])
{
y += s[x];
x = w[x];
}
else
{
y += p[x];
x = l[x];
}
}
}
}
//int main()
//{
// srand(time(NULL));
// ll n, q;
// cin >> n >> q;
// vector <ll> a(n), b(n), c(n), d(n);
// for (ll i = 0; i < n; i++) cin >> a[i];
// for (ll i = 0; i < n; i++) cin >> b[i];
// for (ll i = 0; i < n; i++) cin >> c[i];
// for (ll i = 0; i < n; i++) cin >> d[i];
// init(n, a, b, c, d);
// while (q--)
// {
// ll x, z;
// cin >> x >> z;
// cout << simulate(x, z) << endl;
// }
//}
/*
1
4
-100000 -100000 100000 -100000 -100000 100000
-100000 -100000 100000 -100000 -100000 100000
-100000 -100000 100000 -100000 -100000 100000
-100000 -100000 100000 -100000 -100000 100000
*/