Submission #511265

# Submission time Handle Problem Language Result Execution time Memory
511265 2022-01-15T13:16:19 Z alexdumitru Fountain (eJOI20_fountain) C++14
0 / 100
192 ms 17388 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[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];
            c[i][j]=c[i][j-1]+c[b[i][j-1]][j-1];
        }
    while(q--)
    {
        cin>>x>>y;
        int k=x;
        for(i=l2[n-x+1];i>=0;i--)
        {
            if(!k)break;
            if(c[k][i]<=y)
            {
                y-=c[k][i];
                k=b[k][i];
            }
        }
        cout<<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 192 ms 17388 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 -