Submission #595517

# Submission time Handle Problem Language Result Execution time Memory
595517 2022-07-13T19:27:53 Z ThegeekKnight16 Event Hopping (BOI22_events) C++14
0 / 100
93 ms 13352 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int Inicio[MAXN], Fim[MAXN], Marc[MAXN];
vector<int> Indices;
int dp[MAXN][25];
int prox[MAXN];

bool cmp(int a, int b)
{
    if (Fim[a] == Fim[b]) return Inicio[a] < Inicio[b];
    return Fim[a] > Fim[b];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, Q;
    cin >> N >> Q;
    for (int i = 1; i <= N; i++)
    {
        cin >> Inicio[i] >> Fim[i];
        Indices.push_back(i);
    }
    sort(Indices.begin(), Indices.end(), cmp);
    vector<int> Usados, naoUsados;
    
    int L = 1e9 + 10; int Encima = -1;
    for (auto id : Indices)
    {
        if (Inicio[id] >= L) {naoUsados.push_back(id); prox[id] = Encima;}
        else
        {
            Usados.push_back(id);
            L = Inicio[id];
            Marc[id] = 1;
            Encima = id;
        }
    }
    
    int p = 0;
    for (int i = 0; i < Usados.size(); i++)
    {
        int id = Usados[i]; int pd = Usados[p];
        while (p+1 < i && Fim[id] <= Inicio[Usados[p+1]]) pd = Usados[++p];
        //cerr << id << " " << pd << '\n';
        
        if (Fim[id] < Inicio[pd] || Fim[id] > Fim[pd]) prox[id] = id;
        else prox[id] = pd;
    }
    
    for (int i = 1; i <= N; i++) {dp[i][0] = prox[i];}
    for (int k = 1; k <= 20; k++)
    {
        for (int i = 1; i <= N; i++)
        {
            dp[i][k] = dp[ dp[i][k-1] ][k-1];
        }
    }
    
    for (int q = 1; q <= Q; q++)
    {
        int X, Y;
        cin >> X >> Y;
        
        int D = X; int resp = 0;
        for (int k = 20; k >= 0; k--)
        {
            int id = dp[D][k];
            if (Fim[id] <= Fim[Y])
            {
                D = id;
                resp += (1 << k);
            }
        }
        
        if (Fim[D] < Inicio[Y] || Fim[D] > Fim[Y]) cout << "impossible" << '\n';
        else
        {
            cout << resp+1 << '\n';
        }
    }
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < Usados.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 13352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -