Submission #838789

# Submission time Handle Problem Language Result Execution time Memory
838789 2023-08-27T18:31:44 Z VMaksimoski008 Fountain (eJOI20_fountain) C++14
30 / 100
1500 ms 42100 KB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

vector<vector<int> > up, graph;
vector<vector<ll> > sum;
vector<pii> v;

void dfs(int u, int p) {
    for(int i=1; i<LOG; i++) {
        up[u][i] = up[ up[u][i-1] ][i-1];
        sum[u][i] = 1ll * (sum[u][i-1] + sum[ up[u][i-1] ][i-1]);
    }

    for(int &next : graph[u]) {
        if(next == p) continue;
         up[next][0] = u;
         sum[next][0] = v[u].second + v[next].second;
         dfs(next, u);
    }
}

int jmp(int a, int b) {
    int currNode = a;
    int currLeft = b;

    while(v[currNode].second < b) {
        b -= v[currNode].second;
        currNode = up[currNode][0];
    }

    return currNode;
}

int32_t main() {
    setIO();

    int n, q;
    cin >> n >> q;
    graph.resize(n+1);
    up.resize(n+1, vector<int>(LOG, 0));
    sum.resize(n+1, vector<ll>(LOG, 0));

    v.resize(n+1);
    v[0] = {1500000000, 1500000000};
    for(int i=1; i<=n; i++) {
        cin >> v[i].first >> v[i].second;
    }

    stack<pii> curr;
    for(int i=1; i<=n; i++) {
        while(!curr.empty() && curr.top().second < v[i].first) {
            graph[i].push_back(curr.top().first);
            graph[curr.top().first].push_back(i);
            curr.pop();
        }
        curr.push({ i, v[i].first });
    }

    while(!curr.empty()) {
        graph[0].push_back(curr.top().first);
        graph[curr.top().first].push_back(0);
        curr.pop();
    }

    dfs(0, 0);

    while(q--) {
        int a, b;
        cin >> a >> b;

        if(v[a].second >= b) {
            cout << a << '\n';
            continue;
        }

        cout << jmp(a, b) << '\n';
    }

    return 0;
}

Compilation message

fountain.cpp: In function 'int jmp(int, int)':
fountain.cpp:50:9: warning: unused variable 'currLeft' [-Wunused-variable]
   50 |     int currLeft = b;
      |         ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1555 ms 42100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Execution timed out 1555 ms 42100 KB Time limit exceeded
9 Halted 0 ms 0 KB -