Submission #511260

# Submission time Handle Problem Language Result Execution time Memory
511260 2022-01-15T13:09:23 Z alexdumitru Fountain (eJOI20_fountain) C++14
0 / 100
179 ms 17260 KB
#include <bits/stdc++.h>
using namespace std;
int j,b[100005][20],x,y,c[100005][20],i,n,q,dr[100005],pu[20],l2[100005];
pair<int,int> a[100005];
stack<int> s;
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>q;
    for(i=1;i<=n;i++)
    {
        if(i>1)l2[i]=l2[i>>1]+1;
        //dr[i]=n+1;
        cin>>a[i].first>>a[i].second;
        while(!s.empty()&&a[i].first>a[s.top()].first)
        {
            dr[s.top()]=i;
            s.pop();
        }
        s.push(i);
    }
    pu[0]=1;
    for(i=1;i<=20;i++)
        pu[i]=pu[i-1]<<1;
    for(i=1;i<=n;i++)
    {
        b[i][0]=dr[i];
        c[i][0]=a[dr[i]].second;
    }
    for(j=1;j<=l2[n];j++)
        for(i=1;i<=n;i++)
        {
            b[i][j]=b[b[i][j-1]][j-1];
            //if(b[i][j])
                c[i][j]=c[i][j-1]+c[b[i][j-1]][j-1];
            //else c[i][j]=(1<<30);
        }
    while(q--)
    {
        cin>>x>>y;
        if(a[x].second>=y)
        {
            cout<<x<<'\n';
            continue;
        }
        y-=a[x].second;
        int k=x;
        int sum=0;
        for(i=l2[n-x+1];i>=0;i--)
            if(c[k][i]<=y)
            {
                //y-=c[k][i];
                sum=c[k][i];
                k=b[k][i];
            }
        if(sum==y)cout<<k<<'\n';
        else cout<<dr[k]<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 179 ms 17260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -