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;
const int nax = 4e5 + 3;
int n;
vector<int>s, p, w, l;
int nxtBig[nax];
long long sum_toNext[nax], sum_toN[nax];
vector<int>g[nax];
set<pair<int,int>> dfs(int v, long long sum = 0) {
if(v < n) sum += s[v];
sum_toN[v] = sum;
set<pair<int,int>>me;
for(int u : g[v]) {
auto he = dfs(u, sum);
if(me.size()<he.size()) me.swap(he);
for(auto e : he) me.insert(e);
}
while(!me.empty()) {
auto [val, he] = *me.begin();
if(v < n && val >= s[v]) break;
nxtBig[he] = v;
sum_toNext[he] = sum_toN[he] - sum_toN[v];
me.erase(me.begin());
}
if(v < n) me.insert({s[v], v});
return me;
}
void init(int N, vector<int> S, vector<int> P, vector<int> W, vector<int> L) {
n = N, s = S, p = P, w = W, l = L;
for(int i=0; i<n; ++i) {
nxtBig[i] = -1;
}
for(int i=0; i<n; ++i) {
g[w[i]].push_back(i);
}
dfs(n);
}
const int anax = 1e7;
long long simulate(int x, int z) {
long long cz = z;
while(x < n && cz < anax) {
if(cz >= s[x]) {
cz += sum_toNext[x];
x = nxtBig[x];
} else {
cz += s[x];
x = l[x];
}
}
cz += sum_toN[x];
return cz;
}
# | 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... |