Submission #573627

# Submission time Handle Problem Language Result Execution time Memory
573627 2022-06-07T03:17:33 Z eecs Event Hopping (BOI22_events) C++17
25 / 100
1500 ms 8968 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 100010, SZ = 300;
int n, q, b[maxn], rmq[20][maxn];
int bel[maxn], bl[maxn], br[maxn], mn[maxn];
array<int, 2> a[maxn];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> q;
    vector<int> V;
    for (int i = 1; i <= n; i++) {
        cin >> a[i][0] >> a[i][1], V.push_back(a[i][1]);
    }
    sort(V.begin(), V.end());
    V.resize(unique(V.begin(), V.end()) - V.begin());
    fill(b + 1, b + n + 1, n + 1);
    for (int i = 1; i <= n; i++) {
        a[i][0] = lower_bound(V.begin(), V.end(), a[i][0]) - V.begin() + 1;
        a[i][1] = lower_bound(V.begin(), V.end(), a[i][1]) - V.begin() + 1;
        b[a[i][1]] = min(b[a[i][1]], a[i][0]);
    }
    for (int i = 1; i <= n; i++) {
        br[bel[i] = (i - 1) / SZ + 1] = i;
        if (!bl[bel[i]]) bl[bel[i]] = i;
    }
    copy(b + 1, b + n + 1, rmq[0] + 1);
    for (int k = 1; k < 20; k++) {
        for (int i = 1; i + (1 << k) - 1 <= n; i++) {
            rmq[k][i] = min(rmq[k - 1][i], rmq[k - 1][i + (1 << (k - 1))]);
        }
    }
    auto qmin = [&](int l, int r) {
        int k = __lg(r - l + 1);
        return min(rmq[k][l], rmq[k][r - (1 << k) + 1]);
    };
    for (int k = 1; k <= bel[n]; k++) {
        for (int i = bl[k]; i <= br[k]; i++) {
            mn[i] = min(i == bl[k] ? INT_MAX : mn[i - 1], b[i]);
        }
    }
    auto go = [&](int s, int r) {
        int lb = s + 1, rb = r, ans = 0;
        while (lb <= rb) {
            int mid = (lb + rb) / 2;
            qmin(mid, r) <= s ? lb = (ans = mid) + 1 : rb = mid - 1;
        }
        return ans;
    };
    auto brute = [&](int &s, int l, int r) {
        int ans = 0;
        while (s < l) {
            s = go(s, r), ans++;
            if (!s) break;
        }
        return ans;
    };
    while (q--) {
        int s, t;
        cin >> s >> t;
        if (s == t) { cout << "0\n"; continue; }
        s = a[s][1];
        int ans = brute(s, a[t][0], a[t][1]);
        if (a[t][0] <= s && s <= a[t][1]) cout << ans + 1 << "\n";
        else cout << "impossible\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 1587 ms 8948 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 5 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Execution timed out 1598 ms 868 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 4 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 650 ms 8932 KB Output is correct
20 Correct 152 ms 8948 KB Output is correct
21 Correct 56 ms 8924 KB Output is correct
22 Correct 92 ms 8928 KB Output is correct
23 Correct 53 ms 8948 KB Output is correct
24 Correct 55 ms 8928 KB Output is correct
25 Correct 24 ms 8968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1575 ms 8940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 1587 ms 8948 KB Time limit exceeded
3 Halted 0 ms 0 KB -