Submission #1019413

# Submission time Handle Problem Language Result Execution time Memory
1019413 2024-07-10T19:38:39 Z coolboy19521 Fountain (eJOI20_fountain) C++17
0 / 100
171 ms 40460 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 Incorrect 1 ms 2904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 171 ms 40460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2904 KB Output isn't correct
2 Halted 0 ms 0 KB -