Submission #589295

# Submission time Handle Problem Language Result Execution time Memory
589295 2022-07-04T12:11:19 Z 1zaid1 Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 3048 KB
 #include <bits/stdc++.h>
using namespace std;
#define endl '\n'

const int M = 2e5+2;
struct rng {int l, r, i;};
int nxt[M];

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    int n, q;
    cin >> n >> q;

    vector<rng> v(n);
    for (auto &[l, r, i]:v) cin >> l >> r;
    for (int i = 0; i < n; i++) v[i].i = i;

    for (auto [l, r, i]:v) {
        int mn = l, ind = -1;
        for (auto [a, b, j]:v) {
            if (i == j) continue;
            if (a < mn && l <= b && b <= r) {
                ind = j;
                mn = a;
            }
        }

        nxt[i] = ind;
    }

    bitset<100005> vis;
    while (q--) {
        int a, b;
        cin >> a >> b; a--; b--;
        if (a == b) {
            cout << 0 << endl;
            continue;
        }

        int ans = 1;
        auto tmp = v[b];
        while (v[a].r < tmp.l) {
            if (nxt[tmp.i] < 0) break;
            tmp = v[nxt[tmp.i]];
            ans++;
        }

        if (tmp.l <= v[a].r && v[a].r <= tmp.r) {
            cout << ans << endl;
        } else {
            cout << "impossible" << endl;
        }
    }

    return 0;
}
/*
8 5
1 2
3 4
1 5
6 7
5 10
10 20
15 20
999999999 1000000000
1 6
1 7
2 4
3 3
5 8

5 2
1 3
2 4
4 7
7 9
3 7
1 4
3 2
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1547 ms 1936 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 412 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 412 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 360 KB Output is correct
14 Correct 2 ms 352 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 360 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1409 ms 1232 KB Output is correct
20 Execution timed out 1577 ms 1240 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 412 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Execution timed out 1554 ms 3048 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1547 ms 1788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1547 ms 1936 KB Time limit exceeded
3 Halted 0 ms 0 KB -