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];
int st[nax], at = 0;
void go(int i, long long sum = 0) {
if(i==n) {
while(at) {
sum_toNext[st[at]] += sum;
nxtBig[st[at]] = n; --at;
}
return;
}
while(at && s[st[at]]<s[i]) {
sum_toNext[st[at]] += sum;
nxtBig[st[at]] = i;
--at;
}
++at, st[at] = i;
sum_toNext[i] = -sum;
go(w[i], sum + s[i]);
}
long long go2(int i) {
if(i==n) return 0LL;
if(sum_toN[i]) return sum_toN[i];
return sum_toN[i] = go2(w[i]) + s[i];
}
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) if(nxtBig[i]==-1) {
go(i);
}
for(int i=0; i<n; ++i) if(sum_toN[i]==0) {
go2(i);
}
}
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... |