Submission #1246123

#TimeUsernameProblemLanguageResultExecution timeMemory
1246123sano던전 (IOI21_dungeons)C++20
0 / 100
1 ms580 KiB
//#include "parks.h"
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<fstream>
#include<algorithm>
#include <iomanip>
#include<map>
#include <set>
#include <unordered_map>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <cstdint>
#include <cassert>
#include <bitset>
#include <random>
#include <chrono>
#include <cstring>
#include <variant>
#define shit short int
#define ll long long
#define ld long double
//#define int ll
#define For(i, n) for(int i = 0; i < (int)n; i++)
#define ffor(i, a, n) for(int i = (int)a; i < (int)n; i++)
#define rfor(i, n) for(int i = (int)n; i >= (int)0; i--)
#define rffor(i, a, n) for(int i = (int)n; i >= (int)a; i--)
#define vec vector
#define ff first
#define ss second
#define pb push_back
#define pii pair<int, int>
#define pld pair<ld, ld>
#define NEK 2000000000
#define mod 1000000007
#define mod2 1000000009
#define rsz resize 
#define prv 43
#define prv2 47
#define D 8
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) (x).begin(), (x).end()
#define sig 0.0000001

using namespace std;

class intervalac {
    int n;
    vec<int> l, r, in;
    void update(int s) {
        in[s] = in[s * 2] + in[s * 2 + 1];
        return;
    }
public:
    void postav(int vel) {
        n = 1;
        while (n < vel) n *= 2;
        l.resize(2 * n); r.resize(2 * n); in.resize(2 * n, 0);
        For(i, n) {
            l[i + n] = r[i + n] = i;
        }
        rffor(i, 1, (n - 1)) {
            l[i] = l[i * 2];
            r[i] = r[i * 2 + 1];
        }
        return;
    }
    void zmen(int a, int b) {
        a += n;
        in[a] += b;
        a /= 2;
        while (a) {
            update(a);
            a /= 2;
        }
        return;
    }
    int daj(int a, int b, int s = 1) {
        if (l[s] > b || r[s] < a) return 0;
        if (a <= l[s] && r[s] <= b) return in[s];
        return daj(a, b, s * 2) + daj(a, b, s * 2 + 1);
    }
};

int n;
vec<int> s, p, w, l;
vec<int> dist;
vec<vec<int>> skok;
vec<vec<int>> sila;
void init(int n1, vec<int>s1, vec<int>p1, vec<int>w1, vec<int>l1) {
    n = n1;
    s = s1, p = p1, w = w1, l = l1;
    dist.resize(n + 1);
    dist[n] = 0;
    rfor(i, n - 1) {
        dist[i] = dist[w[i]] + s[i];
    }
    skok.resize(n + 1, vec<int>(20));
    sila.resize(n + 1, vec<int>(20));
    For(i, n) {
        skok[i][0] = l[i];
        sila[i][0] = p[i];
    }
    skok[n][0] = n;
    sila[n][0] = 0;
    ffor(i, 1, 20) {
        For(j, n + 1) {
            skok[j][i] = skok[skok[j][i - 1]][i - 1];
            sila[j][i] = sila[j][i - 1] + sila[skok[j][i - 1]][i - 1];
        }
    }
    return;
}

void chod(ll& x, ll& z) {
    ll S = s[0];
    if (z >= S) {
        return;
    }
    rfor(i, 19) {
        if (z + sila[x][i] < S) {
            z += sila[x][i];
            x = skok[x][i];
        }
    }
    z += sila[x][0];
    x = skok[x][0];
    return;
}

void najdi_n(ll& x, ll& z) {
    ll S = s[0];
    if (z >= S) {
        return;
    }
    rfor(i, 19) {
        if (skok[x][i] !=  n) {
            z += sila[x][i];
            x = skok[x][i];
            
        }
    }
    z += sila[x][0];
    x = skok[x][0];
    return;
}

ll simulate(int x1, int z1) {
    ll x = x1, z = z1;
    int S = s[0];
    ll x2 = x, z2 = z;
    najdi_n(x2, z2);
    chod(x, z);
    if (z2 < z) {
        return z2;
    }
    z += dist[x];
    return z;
}
/*
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n1; cin >> n1; int q; cin >> q;
    vec<int> s1(n1), p1(n1), w1(n1), l1(n1);
    For(i, n1) {
        cin >> s1[i];
    }
    For(i, n1) {
        cin >> p1[i];
    }
    For(i, n1) {
        cin >> w1[i];
    }
    For(i, n1) {
        cin >> l1[i];
    }
    init(n1, s1, p1, w1, l1);
    For(i, q) {
        int a, b; cin >> a >> b;
        cout << simulate(a, b) << '\n';
    }
    return 0;
}*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...