제출 #691003

#제출 시각아이디문제언어결과실행 시간메모리
691003raul2008487Fountain (eJOI20_fountain)C++17
30 / 100
1556 ms5736 KiB
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define pb push_back
using namespace std;
const int big=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
        // we will construct parent array by using minimum stack
        ll n,q,i,cs,x,idx;
        cin>>n>>q;
        vl d(n+1),c(n+1),r(q+1),parent(n+1);
        stack<ll> s;
        for(i=1;i<=n;i++){
                cin>>d[i]>>c[i];
            while(s.size()>0&&d[i]>d[s.top()]){
                parent[s.top()]=i;
                s.pop();
            }
            s.push(i);
        }
        while(s.size()>0){
                parent[s.top()]=0;
                s.pop();
            }
            /*
        for(i=1;i<=n;i++){
            cout<<parent[i]<<' ';
        }
        cout<<endl;
        */
        for(i=1;i<=q;i++){
            cin>>idx>>x;
            for(cs=idx;x>0&&cs!=0;cs=parent[cs]){
                if(x-c[cs]<=0){
                    cout<<cs<<endl;break;
                }
                else{
                    x-=c[cs];
                }
                //cout<<cs<<' ';
            }
            if(cs==0){
                cout<<0<<endl;
            }
        }
}
/*
6 5
4 10
6 8
3 5
4 14
10 9
4 20
1 25
6 30
5 8
3 13
2 8
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...