답안 #599160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
599160 2022-07-19T11:05:42 Z Vanilla Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 7780 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 2e5 + 2;
struct nd {
    int x;
    int y;
    int idx;
    int l;
    int r;

    bool operator < (const nd& oth) const {
        return make_pair(x, y) < make_pair(oth.x, oth.y);
    }
} a [maxn];
vector <int> comp;
int n,q;
int ps[maxn];

vector <int> prec (int x) {
    vector <int> dist(n, 1e9);
    set <int> els;
    queue <int> q;
    q.push(x);
    dist[x] = 0;
    for (int i = 0; i < n; i++) if (i != x) els.insert(i);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        while (1) {
            auto it = els.lower_bound(a[u].l);
            if (it == els.end() || *it > a[u].r) break;
            dist[*it] = dist[u] + 1;
            q.push(*it);
            els.erase(it);
        }
    }
    return dist;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> q;
    for (int i = 0; i < n; i++){
        cin >> a[i].x >> a[i].y;
        a[i].idx = i;
    }
    sort(a, a + n);
    for (int i = 0; i < n; i++){
        ps[a[i].idx] = i;
        int l = i + 1, r = n - 1, rsr = -1;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (a[mid].x <= a[i].y) {
                rsr = mid;
                l = mid + 1;
            }
            else {
                r = mid - 1;
            }
        }
        a[i].l = i + 1, a[i].r = rsr;
    }
    int ct = 0;
    while (q--){
        int x,y;
        cin >> x >> y;
        x = ps[x - 1], y = ps[y - 1];
        vector <int> v = prec(x);
        cout << (v[y] == 1e9 ? "impossible": to_string(v[y])) << "\n";
    }
    return 0;
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:64:9: warning: unused variable 'ct' [-Wunused-variable]
   64 |     int ct = 0;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1590 ms 7744 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 14 ms 408 KB Output is correct
4 Correct 12 ms 416 KB Output is correct
5 Incorrect 14 ms 412 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 14 ms 408 KB Output is correct
4 Correct 12 ms 416 KB Output is correct
5 Incorrect 14 ms 412 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 14 ms 408 KB Output is correct
4 Correct 12 ms 416 KB Output is correct
5 Incorrect 14 ms 412 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1586 ms 7780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1590 ms 7744 KB Time limit exceeded
3 Halted 0 ms 0 KB -