이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define SZ(a) ((int)a.size())
const int MAXC = 10000000;
struct node {
    int to, lower;
    ll sum;
    node operator+(const node &a) const {
        node rt;
        rt.to = a.to;
        rt.sum = sum + a.sum;
        if (lower + sum < a.lower)
            rt.lower = a.lower - sum;
        else
            rt.lower = lower;
        return rt;
    }
};
struct node2 {
    int to;
    ll upper, sum;
    node2 operator+(const node2 &a) const {
        node2 rt;
        rt.to = a.to;
        rt.sum = sum + a.sum;
        if (a.upper == MAXC + 1)
            rt.upper = upper;
        else if (upper + sum > a.upper)
            rt.upper = a.upper - sum;
        else
            rt.upper = upper;
        return rt;
    }
};
int N, lg = __lg(MAXC);
vector<int> S, P, W, L;
vector<node> dp[30];
vector<node2> dp2[30];
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;
    dp[0].resize(N + 1);
    dp[0][N] = node{N, 0, 0};
    for (int i = 0; i < N; ++i)
       dp[0][i] = node{W[i], S[i], (ll)S[i]};
    for (int i = 1; i <= lg; ++i) {
        dp[i].resize(N + 1);
        for (int j = 0; j <= N; ++j)
            dp[i][j] = dp[i - 1][j] + dp[i - 1][dp[i - 1][j].to];
    }
    dp2[0].resize(N + 1);
    dp2[0][N] = node2{N, 0LL, 0LL};
    for (int i = 0; i < N; ++i)
       dp2[0][i] = node2{L[i], S[i] - 1, (ll)P[i]};
    for (int i = 1; i <= lg; ++i) {
        dp2[i].resize(N + 1);
        for (int j = 0; j <= N; ++j)
            dp2[i][j] = dp2[i - 1][j] + dp2[i - 1][dp2[i - 1][j].to];
    }
}
long long simulate(int x, int z) {
    ll nw = z;
    while (dp[lg][x].lower > nw) {
        for (int i = lg; i >= 0; --i)
            if (dp[i][x].lower <= nw) {
                nw += dp[i][x].sum;
                x = dp[i][x].to;
            }
        for (int i = lg; i >= 0; --i)
            if (dp2[i][x].upper >= nw) {
                nw += dp2[i][x].sum;
                x = dp2[i][x].to;
            }
    }
    return nw + dp[lg][x].sum;
}
| # | 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... |