Submission #1024904

# Submission time Handle Problem Language Result Execution time Memory
1024904 2024-07-16T12:07:29 Z vjudge1 Fountain (eJOI20_fountain) C++17
100 / 100
515 ms 35668 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, q;
    cin>>n>>q;
    int L=log2(n)+1;
    int d[n+1], c[n+1];
    c[0]=d[0]=1e9+1;
    pair<int, long long>up[n+1][L+1];
    for(int i=1; i<=n; i++)
    {
        cin>>d[i]>>c[i];
    }
    stack<pair<long long, long long>>s;
    s.push({c[0], 0});
    for(int i=n; i; i--)
    {
        while(d[i]>=s.top().first)
        {
            s.pop();
        }
        up[i][0].first=s.top().second;
        up[i][0].second=c[s.top().second];
        for(int j=1; j<=L; j++)
        {
            up[i][j].first=up[up[i][j-1].first][j-1].first;
            up[i][j].second=up[i][j-1].second+up[up[i][j-1].first][j-1].second;
        }
        s.push({d[i], i});
    }
    while(q--)
    {
        int idx;
        long long val;
        cin>>idx>>val;
        val-=c[idx];
        if(val<=0)
        {
            cout<<idx<<"\n";
            continue;
        }
        for(int i=L; i>=0; i--)
        {
            if(up[idx][i].second<val)
            {
                val-=up[idx][i].second;
                idx=up[idx][i].first;
            }
        }
        cout<<up[idx][0].first<<"\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 354 ms 32988 KB Output is correct
2 Correct 376 ms 30668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 354 ms 32988 KB Output is correct
9 Correct 376 ms 30668 KB Output is correct
10 Correct 4 ms 600 KB Output is correct
11 Correct 212 ms 17888 KB Output is correct
12 Correct 515 ms 35668 KB Output is correct
13 Correct 482 ms 34128 KB Output is correct
14 Correct 376 ms 33096 KB Output is correct
15 Correct 344 ms 33360 KB Output is correct