Submission #1019412

# Submission time Handle Problem Language Result Execution time Memory
1019412 2024-07-10T19:37:25 Z coolboy19521 Fountain (eJOI20_fountain) C++17
30 / 100
190 ms 38596 KB
#include "bits/stdc++.h"
#define int long long

using namespace std;

const int inf = 1e18 + 18;
const int sz = 1e5 + 5;
const int sm = 25;

vector<int> aj[sz];
int pf[sz], dm[sz];
int up[sm][sz];

void dfs(int v, int s = 0) {
    for (int i = 1; i < sm; i ++)
        up[i][v] = up[i-1][up[i-1][v]];

    pf[v] = s;

    for (int u : aj[v]) {
        up[0][u] = v;
        dfs(u, s + dm[u]);
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int n, q;
    cin >> n >> q;

    vector<pair<int,int>> a;

    for (int i = 1; i <= n; i ++) {
        int d, c;
        cin >> d >> c;
        dm[i] = c;
        a.push_back(make_pair(d, i));
    }

    sort(begin(a),end(a));
    set<int> rs = {n+1};

    for (auto it = rbegin(a); it != rend(a); it ++) {
        int v = it->second;
        int u = *rs.upper_bound(v);
        aj[u].push_back(v);
        rs.insert(v);
    }

    dfs(n+1);

    while (q --) {
        int r, v;
        cin >> r >> v;

        int s = pf[r];

        for (int i = sm-1; -1 < i; i --) {
            if (s - pf[up[i][r]] < v) {
                r = up[i][r];
            }
        }

        if (n+1 == r)
            r = 0;

        cout << r << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Incorrect 2 ms 2904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 183 ms 38596 KB Output is correct
2 Correct 190 ms 35780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Incorrect 2 ms 2904 KB Output isn't correct
3 Halted 0 ms 0 KB -