Submission #868959

# Submission time Handle Problem Language Result Execution time Memory
868959 2023-11-02T15:46:00 Z AlphaMale06 Fountain (eJOI20_fountain) C++14
0 / 100
50 ms 30196 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define int long long

const int N = 1e5+3;
const int inf=1e9+10;

int p[N][17];
int sz[N][17];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n>> q;
    pair<int, int> a[n+1];
    for(int i=1; i<= n; i++)cin >> a[i].F >> a[i].S;
    stack<pair<int, int>> st;
    st.push(mp(inf, 0));
    for(int i=n; i>=1; i--){
        while(st.top().F<=a[i].F){
            st.pop();
        }
        p[i][0]=st.top().S;
        sz[i][0]=a[i].S;
        st.push(mp(a[i].F, i));
    }
    for(int j=0; j<17; j++){
        sz[0][j]=inf;
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<17; j++){
            p[i][j]=p[p[i][j-1]][j-1];
            if(p[i][j]==0){
                sz[i][j]=inf;
            }
            else{
                sz[i][j]=sz[i][j-1]+sz[p[i][j-1]][j-1];
            }
        }
    }
    while(q--){
        int x, val;
        cin >> x >> val;
        int ans=x;
        for(int i=16; i>=0; i--){
            if(sz[ans][i]<val){
                val-=sz[ans][i];
                ans=p[ans][i];
            }
        }
        if(a[ans].S>=val){
            cout << ans << '\n';
        }
        else cout << p[ans][0] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 1 ms 2804 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 30196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 1 ms 2804 KB Output isn't correct
3 Halted 0 ms 0 KB -