Submission #509814

# Submission time Handle Problem Language Result Execution time Memory
509814 2022-01-14T10:45:30 Z KoD Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
349 ms 22320 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;
    std::cin >> N;
    vector<int> L(N), R(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> L[i] >> R[i];
        R[i] += 1;
    }
    array<vector<int>, 20> parent = {};
    parent[0] = vector<int>(N + 1);
    parent[0][N] = N;
    {
        std::map<int, int> map;
        int r = N;
        for (int l = N - 1; l >= 0; --l) {
            while (true) {
                const auto itr = map.upper_bound(L[l]);
                if (itr != map.end() and itr->second < R[l]) {
                    r -= 1;
                    map.erase(R[r]);
                } else {
                    break;
                }
            }
            map[R[l]] = L[l];
            parent[0][l] = r;
        }
    }
    for (int i = 0; i < 19; ++i) {
        parent[i + 1] = vector<int>(N + 1);
        for (int j = 0; j <= N; ++j) {
            parent[i + 1][j] = parent[i][parent[i][j]];
        }
    }
    int Q;
    std::cin >> Q;
    while (Q--) {
        int l, r;
        std::cin >> l >> r;
        l -= 1;
        int ans = 0;
        for (int i = 19; i >= 0; --i) {
            if (parent[i][l] < r) {
                ans += 1 << i;
                l = parent[i][l];
            }
        }
        ans += 1;
        std::cout << ans << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 56 ms 17592 KB Output is correct
2 Correct 62 ms 17092 KB Output is correct
3 Correct 59 ms 17328 KB Output is correct
4 Correct 57 ms 17332 KB Output is correct
5 Correct 58 ms 18184 KB Output is correct
6 Correct 48 ms 16640 KB Output is correct
7 Correct 54 ms 16712 KB Output is correct
8 Correct 55 ms 16876 KB Output is correct
9 Correct 57 ms 17396 KB Output is correct
10 Correct 62 ms 16732 KB Output is correct
11 Correct 148 ms 20792 KB Output is correct
12 Correct 140 ms 19632 KB Output is correct
13 Correct 141 ms 19360 KB Output is correct
14 Correct 141 ms 19796 KB Output is correct
15 Correct 139 ms 19056 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 52 ms 17336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 708 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 4 ms 716 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 4 ms 748 KB Output is correct
8 Correct 4 ms 800 KB Output is correct
9 Correct 4 ms 716 KB Output is correct
10 Correct 3 ms 704 KB Output is correct
11 Correct 5 ms 844 KB Output is correct
12 Correct 4 ms 736 KB Output is correct
13 Correct 4 ms 816 KB Output is correct
14 Correct 4 ms 744 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 708 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 4 ms 716 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 4 ms 748 KB Output is correct
8 Correct 4 ms 800 KB Output is correct
9 Correct 4 ms 716 KB Output is correct
10 Correct 3 ms 704 KB Output is correct
11 Correct 5 ms 844 KB Output is correct
12 Correct 4 ms 736 KB Output is correct
13 Correct 4 ms 816 KB Output is correct
14 Correct 4 ms 744 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 73 ms 1760 KB Output is correct
19 Correct 70 ms 1724 KB Output is correct
20 Correct 69 ms 1764 KB Output is correct
21 Correct 64 ms 1604 KB Output is correct
22 Correct 67 ms 1720 KB Output is correct
23 Correct 66 ms 1716 KB Output is correct
24 Correct 70 ms 1852 KB Output is correct
25 Correct 68 ms 1724 KB Output is correct
26 Correct 66 ms 1756 KB Output is correct
27 Correct 65 ms 1740 KB Output is correct
28 Correct 50 ms 1476 KB Output is correct
29 Correct 61 ms 1228 KB Output is correct
30 Correct 59 ms 1344 KB Output is correct
31 Correct 50 ms 1236 KB Output is correct
32 Correct 50 ms 1312 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 51 ms 1940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 18152 KB Output is correct
2 Correct 60 ms 17624 KB Output is correct
3 Correct 49 ms 16580 KB Output is correct
4 Correct 52 ms 16384 KB Output is correct
5 Correct 53 ms 16644 KB Output is correct
6 Correct 48 ms 17432 KB Output is correct
7 Correct 50 ms 16516 KB Output is correct
8 Correct 55 ms 18008 KB Output is correct
9 Correct 62 ms 17900 KB Output is correct
10 Correct 63 ms 19024 KB Output is correct
11 Correct 127 ms 19252 KB Output is correct
12 Correct 153 ms 20492 KB Output is correct
13 Correct 124 ms 19140 KB Output is correct
14 Correct 129 ms 18428 KB Output is correct
15 Correct 151 ms 19268 KB Output is correct
16 Correct 0 ms 292 KB Output is correct
17 Correct 49 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 17592 KB Output is correct
2 Correct 62 ms 17092 KB Output is correct
3 Correct 59 ms 17328 KB Output is correct
4 Correct 57 ms 17332 KB Output is correct
5 Correct 58 ms 18184 KB Output is correct
6 Correct 48 ms 16640 KB Output is correct
7 Correct 54 ms 16712 KB Output is correct
8 Correct 55 ms 16876 KB Output is correct
9 Correct 57 ms 17396 KB Output is correct
10 Correct 62 ms 16732 KB Output is correct
11 Correct 148 ms 20792 KB Output is correct
12 Correct 140 ms 19632 KB Output is correct
13 Correct 141 ms 19360 KB Output is correct
14 Correct 141 ms 19796 KB Output is correct
15 Correct 139 ms 19056 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 52 ms 17336 KB Output is correct
18 Correct 4 ms 708 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 4 ms 716 KB Output is correct
23 Correct 4 ms 716 KB Output is correct
24 Correct 4 ms 748 KB Output is correct
25 Correct 4 ms 800 KB Output is correct
26 Correct 4 ms 716 KB Output is correct
27 Correct 3 ms 704 KB Output is correct
28 Correct 5 ms 844 KB Output is correct
29 Correct 4 ms 736 KB Output is correct
30 Correct 4 ms 816 KB Output is correct
31 Correct 4 ms 744 KB Output is correct
32 Correct 4 ms 716 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 3 ms 716 KB Output is correct
35 Correct 73 ms 1760 KB Output is correct
36 Correct 70 ms 1724 KB Output is correct
37 Correct 69 ms 1764 KB Output is correct
38 Correct 64 ms 1604 KB Output is correct
39 Correct 67 ms 1720 KB Output is correct
40 Correct 66 ms 1716 KB Output is correct
41 Correct 70 ms 1852 KB Output is correct
42 Correct 68 ms 1724 KB Output is correct
43 Correct 66 ms 1756 KB Output is correct
44 Correct 65 ms 1740 KB Output is correct
45 Correct 50 ms 1476 KB Output is correct
46 Correct 61 ms 1228 KB Output is correct
47 Correct 59 ms 1344 KB Output is correct
48 Correct 50 ms 1236 KB Output is correct
49 Correct 50 ms 1312 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 51 ms 1940 KB Output is correct
52 Correct 59 ms 18152 KB Output is correct
53 Correct 60 ms 17624 KB Output is correct
54 Correct 49 ms 16580 KB Output is correct
55 Correct 52 ms 16384 KB Output is correct
56 Correct 53 ms 16644 KB Output is correct
57 Correct 48 ms 17432 KB Output is correct
58 Correct 50 ms 16516 KB Output is correct
59 Correct 55 ms 18008 KB Output is correct
60 Correct 62 ms 17900 KB Output is correct
61 Correct 63 ms 19024 KB Output is correct
62 Correct 127 ms 19252 KB Output is correct
63 Correct 153 ms 20492 KB Output is correct
64 Correct 124 ms 19140 KB Output is correct
65 Correct 129 ms 18428 KB Output is correct
66 Correct 151 ms 19268 KB Output is correct
67 Correct 0 ms 292 KB Output is correct
68 Correct 49 ms 16748 KB Output is correct
69 Correct 289 ms 18804 KB Output is correct
70 Correct 297 ms 20472 KB Output is correct
71 Correct 258 ms 20428 KB Output is correct
72 Correct 258 ms 20184 KB Output is correct
73 Correct 251 ms 18876 KB Output is correct
74 Correct 349 ms 19244 KB Output is correct
75 Correct 259 ms 19532 KB Output is correct
76 Correct 270 ms 22320 KB Output is correct
77 Correct 265 ms 18900 KB Output is correct
78 Correct 285 ms 18344 KB Output is correct
79 Correct 255 ms 21292 KB Output is correct
80 Correct 216 ms 20208 KB Output is correct
81 Correct 204 ms 20836 KB Output is correct
82 Correct 232 ms 20116 KB Output is correct
83 Correct 225 ms 18828 KB Output is correct
84 Correct 0 ms 204 KB Output is correct
85 Correct 114 ms 19096 KB Output is correct