답안 #653566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653566 2022-10-27T10:07:06 Z AlperenT Event Hopping (BOI22_events) C++17
0 / 100
54 ms 4520 KB
#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";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 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 54 ms 3784 KB Output is correct
2 Correct 50 ms 3992 KB Output is correct
3 Correct 51 ms 4016 KB Output is correct
4 Correct 54 ms 4520 KB Output is correct
5 Correct 53 ms 4288 KB Output is correct
6 Incorrect 54 ms 4188 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -