이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |