Submission #849851

# Submission time Handle Problem Language Result Execution time Memory
849851 2023-09-15T13:10:42 Z Ahmed57 Event Hopping (BOI22_events) C++17
0 / 100
341 ms 29700 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
bool cmp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
    return a.first.second<b.first.second;
}

signed main(){
    int n,q;cin>>n>>q;
    vector<pair<pair<int,int>,int>> v;
    map<int,int> comp,sav;
    for(int i = 0;i<n;i++){
        int a,b;
        cin>>a>>b;
        comp[a]++;comp[b]++;
        v.push_back({{a,b},i});
    }
    long long z = 0;
    for(auto i:comp){
        sav[i.first] = ++z;
    }
    for(int i = 0;i<n;i++){
        v[i].first.first = sav[v[i].first.first];
        v[i].first.second = sav[v[i].first.second];
    }
    int P[100001][17],ind[100001];
    int in = 0;
    for(int i = 0;i<v.size();i++){
        ind[v[i].second] = i;
        while(in<n&&v[in].first.first<=v[i].first.second){
            in++;
        }
        P[i][0] = in-1;
    }
    for(int i = n-1;i>=0;i--){
        for(int j = 1;j<17;j++){
            P[i][j] = P[P[i][j-1]][j-1];
        }
    }
    while(q--){
        int a,b;cin>>a>>b;
        a--;b--;
        if(ind[a]>ind[b]){
        cout<<"impossible\n";
        continue;
        }else if(ind[a]==ind[b]){
        cout<<0<<endl;
        continue;
        }
        int sum = 0 , cur = ind[a];
        for(int i = 16;i>=0;i--){
            if(v[P[cur][i]].second<v[ind[b]].second){
                sum+=(1<<i);
                cur = P[cur][i];
            }
        }
        if(v[P[cur][0]].second>=v[ind[b]].second){
            cout<<sum+1<<endl;
        }else cout<<"impossible\n";
    }
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:28:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0;i<v.size();i++){
      |                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 341 ms 29700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14424 KB Output isn't correct
2 Halted 0 ms 0 KB -