Submission #857757

# Submission time Handle Problem Language Result Execution time Memory
857757 2023-10-06T21:40:45 Z gangaj21 Fountain (eJOI20_fountain) C++14
0 / 100
1500 ms 12432 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
#define MAX 1e18
#define per(i,a,b) for(ll int i=a;i<b;i++)
#define rep(i,a,b) for(ll int i=b;i>=a;i--)
#define scan(v,n) per(i,0,n){cin>>v[i];}
#define print(v,n) per(i,0,n){cout<<v[i]<<" ";}cout<<endl;
#define pb push_back


int main() {
    int n,q;
    cin>>n>>q;
    vector<int>dia(n),cap(n);
    per(i,0,n){cin>>dia[i]>>cap[i];}
    vector<vector<int>>table(n,vector<int>(ceil(log2(n))));
    per(i,0,n)table[i][0]=i;
    for(int j=1;j<=ceil(log2(n));j++){
        for(int i=0;i+(1<<j)<n;i++){
            if(dia[table[i+(1<<(j-1))][j-1]]<dia[table[i][j-1]])table[i][j]=table[i][j-1];
            else table[i][j] = table[i+(1<<(j-1))][j-1];
        }
    }
    while(q--){
        int from, c;
        cin>>from>>c;
        from--;
        int curr = from;
        while(c>0 && curr<n){
            c-=cap[curr];
            if(c>0){
                int i= curr, j=0;
                while(dia[i]==dia[curr]){
                    i = table[curr][j];
                    j++;
                }
                curr = i;
                // for(int k = curr+(1<<(j-1));k<=curr+(1<<j);k++){
                //     if(dia[curr]<dia[k]){curr = k;break;}
                // }
            }
        }
        if(c<=0)cout<<curr+1<<endl;
        else cout<<0<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1585 ms 12432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -