Submission #868958

# Submission time Handle Problem Language Result Execution time Memory
868958 2023-11-02T15:40:31 Z AlphaMale06 Fountain (eJOI20_fountain) C++14
0 / 100
51 ms 32796 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];
    for(int i=0; i< n; i++)cin >> a[i].F >> a[i].S;
    stack<pair<int, int>> st;
    st.push(mp(inf, 0));
    for(int i=n-1; i>=0; i--){
        while(st.top().F<=a[i].F){
            st.pop();
        }
        p[i+1][0]=st.top().S;
        sz[i+1][0]=a[i].S;
        st.push(mp(a[i].F, i+1));
    }
    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 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 32796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -