답안 #745834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745834 2023-05-21T08:31:32 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
179 ms 3492 KB
#include <bits/stdc++.h>

// #define MULTI_TEST_CASE
// #define TEST_TEXT

using namespace std;

#define ll long long
#define MAX(a, b) (a) = max((a), (b))
#define MIN(a, b) (a) = min((a), (b))
#define all(a) (a).begin(), (a).end()
#define sortedpair(a, b) {min((a), (b)), max((a), (b))}

const ll MOD = 1e9+7;

struct event{
    int start, end, ind;
    event(){}
    bool operator<(const event&o){
        return end < o.end;
    }
};

int n, q;
vector<event> v;
vector<int> p;

void solve(){
    cin>>n>>q;
    v.resize(n);
    for(int i = 0; i < n; i++){
        cin>>v[i].start>>v[i].end;
        v[i].ind = i;
    }
    sort(all(v));
    vector<int> hol(n);
    for(int i = 0; i < n; i++){
        hol[v[i].ind] = i;
    }
    vector<int> megszakit;
    for(int i = 0; i < n-1; i++){
        if(v[i].end < v[i+1].start){
            megszakit.push_back(i);
        }
    }
    megszakit.push_back(1e9);
    while(q--){
        int a, b; cin>>a>>b; a--; b--;
        if(v[hol[b]].end < v[hol[a]].end){
            cout<<"impossible"<<endl;
            continue;
        }
        if(v[hol[b]].end == v[hol[a]].end){
            cout<<1<<endl;
            continue;
        }
        if(*lower_bound(megszakit.begin(), megszakit.end(), hol[a]) < hol[b]){
            cout<<"impossible"<<endl;
            continue;
        }
        cout<<hol[b]-hol[a]<<endl;
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int _t = 1;
#ifdef MULTI_TEST_CASE
    cin >> _t;
#endif
    for(int _i = 0; _i < _t; _i++){
        #ifdef TEST_TEXT
        cout<<"Case #"<<_i+1<<": ";
        #endif
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 2404 KB Output is correct
2 Correct 161 ms 2544 KB Output is correct
3 Correct 161 ms 2464 KB Output is correct
4 Correct 179 ms 3492 KB Output is correct
5 Incorrect 160 ms 2756 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -