Submission #867824

# Submission time Handle Problem Language Result Execution time Memory
867824 2023-10-29T14:19:31 Z TAhmed33 Event Hopping (BOI22_events) C++
10 / 100
1500 ms 101456 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
const int MAXN = 5e3 + 25;
#define mid ((l + r) >> 1)
#define tl (node + 1)
#define tr (node + 2 * (mid - l + 1))
const int bad = 1e9;
struct SegmentTree {
    int tree[2 * MAXN];
    void init () {
        for (auto &i : tree) i = bad;
    }
    void update (int l, int r, int a, int b, int node) {
        if (l > a || r < a) return;
        if (l == r) {
            tree[node] = min(tree[node], b);
            return;
        }
        update(l, mid, a, b, tl);
        update(mid + 1, r, a, b, tr);
        tree[node] = min(tree[tl], tree[tr]);
    }
    int get (int l, int r, int a, int b, int node) {
        if (l > b || r < a) return bad;
        if (l >= a && r <= b) return tree[node];
        return min(get(l, mid, a, b, tl), get(mid + 1, r, a, b, tr));
    }
} cur;
vector <int> adj[MAXN];
vector <int> arr[MAXN];
vector <int> d;
int dp[MAXN];
vector <vector <int>> events;
int idxx[MAXN];
int ans[MAXN][MAXN];
int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        int l, r;
        cin >> l >> r;
        arr[i] = {l, r, i};
        d.push_back(l); d.push_back(r);
    }
    sort(d.begin(), d.end()); d.resize(unique(d.begin(), d.end()) - d.begin());
    for (int i = 1; i <= n; i++) {
        arr[i][0] = lower_bound(d.begin(), d.end(), arr[i][0]) - d.begin();
        arr[i][1] = lower_bound(d.begin(), d.end(), arr[i][1]) - d.begin();
        arr[i][0]++; arr[i][1]++;
    }
    sort(arr + 1, arr + n + 1, [] (vector <int> &a, vector <int> &b) {
        return a[1] == b[1] ? a[0] < b[0] : a[1] < b[1];
    });
    for (int i = 1; i <= n; i++) idxx[arr[i][2]] = i;
    for (int a = 1; a <= n; a++) {
        cur.init();
        for (int b = 1; b <= n; b++) ans[a][b] = bad;
        for (int i = idxx[a]; i <= n; i++) {
            int l = arr[i][0], r = arr[i][1], idx = arr[i][2];
            if (idx == a) {
                cur.update(1, MAXN, r, 0, 1);
                ans[a][a] = 0;
                continue;
            }
            int x = cur.get(1, MAXN, l, r, 1);
            cur.update(1, MAXN, r, x + 1, 1);
            ans[a][idx] = x + 1;
        }       
    }
    while (q--) {
        int a, b;
        cin >> a >> b;
        if (ans[a][b] > n) cout << "impossible\n";
        else cout << ans[a][b] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Runtime error 5 ms 2396 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 49 ms 21368 KB Output is correct
4 Correct 65 ms 21352 KB Output is correct
5 Correct 56 ms 21332 KB Output is correct
6 Correct 56 ms 21332 KB Output is correct
7 Correct 72 ms 21380 KB Output is correct
8 Correct 65 ms 21332 KB Output is correct
9 Correct 32 ms 21348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 49 ms 21368 KB Output is correct
4 Correct 65 ms 21352 KB Output is correct
5 Correct 56 ms 21332 KB Output is correct
6 Correct 56 ms 21332 KB Output is correct
7 Correct 72 ms 21380 KB Output is correct
8 Correct 65 ms 21332 KB Output is correct
9 Correct 32 ms 21348 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 47 ms 21368 KB Output is correct
13 Correct 53 ms 21588 KB Output is correct
14 Correct 47 ms 21324 KB Output is correct
15 Correct 58 ms 21332 KB Output is correct
16 Correct 69 ms 21368 KB Output is correct
17 Correct 68 ms 21360 KB Output is correct
18 Correct 31 ms 21340 KB Output is correct
19 Correct 1006 ms 101296 KB Output is correct
20 Correct 1466 ms 101084 KB Output is correct
21 Correct 1481 ms 101456 KB Output is correct
22 Execution timed out 1533 ms 87680 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 49 ms 21368 KB Output is correct
4 Correct 65 ms 21352 KB Output is correct
5 Correct 56 ms 21332 KB Output is correct
6 Correct 56 ms 21332 KB Output is correct
7 Correct 72 ms 21380 KB Output is correct
8 Correct 65 ms 21332 KB Output is correct
9 Correct 32 ms 21348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 63 ms 21328 KB Output is correct
13 Correct 56 ms 21376 KB Output is correct
14 Correct 49 ms 21340 KB Output is correct
15 Correct 57 ms 21116 KB Output is correct
16 Correct 74 ms 21324 KB Output is correct
17 Correct 84 ms 21332 KB Output is correct
18 Correct 31 ms 21340 KB Output is correct
19 Runtime error 6 ms 2396 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 2392 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Runtime error 5 ms 2396 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -