답안 #971980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971980 2024-04-29T16:12:23 Z idas Event Hopping (BOI22_events) C++11
0 / 100
87 ms 8964 KB
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) int((x).size())
#define pb push_back
#define s second
#define f first

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;

const int INF=1e9;

const int N=1e5+10;
int n, q, s[N], e[N], gr[N], d[N];
set<pii> same;

int main()
{
    FAST_IO;
    cin >> n >> q;

    set<int> dif;
    vector<tiii> inf;
    FOR(i, 0, n)
    {
        cin >> s[i] >> e[i];
        inf.pb({s[i],e[i],i});

        assert(!dif.count(e[i]));

        dif.insert(e[i]);
    }

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

    int j=-1;
    for(auto it : inf){
        int a, b, i;
        tie(a, b, i)=it;

        if(j==-1){
            j=i;
            gr[i]=i;
            d[i]=0;
            continue;
        }

        if(s[i]<=e[j] && e[j]<=e[i]){
            if(e[j]==e[i]){
                same.insert({i,j});
                same.insert({j,i});
            }

            gr[i]=gr[j];
            d[i]=d[j]+1;
        }
        else{
            gr[i]=i;
            d[i]=0;
        }

        j=i;
    }

    while(q--){
        int a, b; cin >> a >> b; --a; --b;
        if(same.count({a,b})){
            cout << 1 << '\n';
            continue;
        }

        if(gr[a]!=gr[b] || d[b]<d[a]){
            cout << "impossible\n";
            continue;
        }

        cout << d[b]-d[a] << '\n';
    }

//    FOR(i, 0, n)
//    {
//        cout << gr[i] << " " << d[i] << '\n';
//    }
}
/*
5 5
1 1
1 2
2 3
4 5
5 6
1 2
2 3
3 3
3 4
4 5
*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 8448 KB Output is correct
2 Correct 71 ms 8452 KB Output is correct
3 Correct 87 ms 8568 KB Output is correct
4 Correct 67 ms 8964 KB Output is correct
5 Correct 70 ms 8776 KB Output is correct
6 Incorrect 70 ms 8708 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -