Submission #466872

# Submission time Handle Problem Language Result Execution time Memory
466872 2021-08-20T22:13:55 Z TlenekWodoru Fountain (eJOI20_fountain) C++17
30 / 100
493 ms 36248 KB
#include <bits/stdc++.h>
using namespace std;
int srednica[100009];
int pojemnosc[100009];
vector<int>D[100009];
vector<int>D2[100009];
int V[100009][20];
int V2[100009][20];
void DFS(int v, int poprzedni, int poprzedni_odl)
{
    int ind=poprzedni;
    long long odl=poprzedni_odl;
    for(int i=0;i<=18;i++)
    {
        V2[v][i]=odl;
        V[v][i]=ind;
        odl+=V2[ind][i];
        ind=V[ind][i];
    }
    for(int i=0;i<D[v].size();i++)
    {
        int somsiad=D[v][i];
        DFS(somsiad,v,D2[v][i]);
    }
}
int main()
{ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        int r,l;
        cin>>r>>l;
        srednica[i]=r;
        pojemnosc[i]=l;
    }
    map<int,int>M;
    M[1000000009]=0;
    D[0].push_back(1);
    D2[0].push_back(1000000009);
    for(int i=n;i>=1;i--)
    {
        int r=srednica[i];
        int l=pojemnosc[i];
        D[M.upper_bound(r)->second].push_back(i);
        D2[M.upper_bound(r)->second].push_back(l);
        M[r]=i;
    }
///-=-=-==-==-=-==-==-=-=-==-=-==-==-==-=-==-==-=-==-=-==-==-=-=-=
    DFS(0,0,0);
///-==-=--==-==-=-==-==--==--==-==-=-==-==-=-==-==-==-=-==-==-=-==-
    /**cout<<endl<<endl;
    for(int i=0;i<=n;i++)
    {
        cout<<endl<<"i="<<i<<"| ";
        for(int j=0;j<10;j++)
        {
            cout<<V[i][j]<<" ";
        }
    }
    cout<<endl;
    cout<<endl;
    for(int i=0;i<=n;i++)
    {
        cout<<endl<<"i="<<i<<"| ";
        for(int j=0;j<10;j++)
        {
            cout<<V2[i][j]<<" ";
        }
    }
    cout<<endl<<endl;**/
///-=-==-=-==-=-==-=-==-==-=-===-=-==-==-=-==-=-==-==--=-=
    vector<int>odp;
    for(int i=1;i<=m;i++)
    {
        int ind;
        int k;
        cin>>ind>>k;
        for(int j=17;j>=0;j--)
        {
            if(V2[ind][j]<k)
            {
                k-=V2[ind][j];
                ind=V[ind][j];
            }
            if(ind==0){break;}
        }
        cout<<ind<<endl;
    }
    return 0;
}
/**
10 100
1 1
2 1
3 1
4 2
5 2
6 2
7 3
8 3
9 3
10 4

**/





Compilation message

fountain.cpp: In function 'void DFS(int, int, int)':
fountain.cpp:20:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=0;i<D[v].size();i++)
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 448 ms 36248 KB Output is correct
2 Correct 493 ms 33956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -