제출 #653566

#제출 시각아이디문제언어결과실행 시간메모리
653566AlperenTEvent Hopping (BOI22_events)C++17
0 / 100
54 ms4520 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n, q, where[N], pref[N];

struct Event{
    int l, r;

    bool operator < (const Event &sc) const{
        if(r == sc.r) return l < sc.l;
        else return r < sc.r;
    }
};

Event arr[N];

bool canmove(Event a, Event b){
    return b.l <= a.r && a.r <= b.r;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n >> q;

    for(int i = 1; i <= n; i++) cin >> arr[i].l >> arr[i].r;

    vector<pair<Event, int>> v;

    for(int i = 1; i <= n; i++) v.push_back({arr[i], i});

    sort(v.begin(), v.end());

    for(int i = 1; i < n; i++) pref[i] = pref[i - 1] + canmove(v[i - 1].first, v[i].first);

    for(int i = 0; i < n; i++) where[v[i].second] = i;

    while(q--){
        int s, e;

        cin >> s >> e;

        s = where[s], e = where[e];

        if(s <= e){
            if(pref[e] - pref[s] == (e - s)) cout << e - s << "\n";
            else cout << "impossible\n";
        }
        else cout << "impossible\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...