답안 #1111077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111077 2024-11-11T12:25:19 Z huantran Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
209 ms 34644 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
const int maxn = 2e5 + 5;
const int oo = 1e9 + 7;
const ll inf = 1e18;

int n, q;
int l[maxn], r[maxn];
int up[maxn][22];
set<pair<int, int>> left_boud;

int can_add(int idx) {
    if (left_boud.empty())
        return 1;
    
    auto it = left_boud.lower_bound({l[idx], 0});
    if (it != left_boud.end()) {
        int id = (*it).second;
        if (r[idx] >= l[id])
            return 0;
    }

    if (it != left_boud.begin()) {
        it--;
        int id = (*it).second;
        if (r[id] >= l[idx])
            return 0;
    }
    return 1;
}

int get_ans(int u, int v) {
    int ans = 0;
    for (int len = 21; len >= 0; len--) {
        if (up[u][len] <= v) {
            u = up[u][len];
            ans += (1 << len);
        }
    }

    return (ans + 1);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> l[i] >> r[i];
    }

    int nxt = 1;
    for (int i = 1; i <= n; i++) {
        while (nxt <= n && can_add(nxt))
            left_boud.insert({l[nxt], nxt}), nxt++;
        
        up[i][0] = nxt;
        left_boud.erase({l[i], i});
    }

    up[n + 1][0] = n + 1;
    for (int len = 1; len < 22; len++) {
        for (int i = 1; i <= n + 1; i++) {
            up[i][len] = up[up[i][len - 1]][len - 1];
        }
    }

    cin >> q;

    while (q--) {
        int p, q;
        cin >> p >> q;
        cout << get_ans(p, q) << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 22856 KB Output is correct
2 Correct 45 ms 22620 KB Output is correct
3 Correct 43 ms 22724 KB Output is correct
4 Correct 45 ms 22912 KB Output is correct
5 Correct 51 ms 22856 KB Output is correct
6 Correct 40 ms 22600 KB Output is correct
7 Correct 44 ms 22608 KB Output is correct
8 Correct 47 ms 22636 KB Output is correct
9 Correct 50 ms 22844 KB Output is correct
10 Correct 51 ms 22600 KB Output is correct
11 Correct 165 ms 31608 KB Output is correct
12 Correct 152 ms 30600 KB Output is correct
13 Correct 147 ms 30536 KB Output is correct
14 Correct 142 ms 27464 KB Output is correct
15 Correct 128 ms 26184 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 41 ms 22916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4684 KB Output is correct
2 Correct 4 ms 4688 KB Output is correct
3 Correct 4 ms 4688 KB Output is correct
4 Correct 4 ms 4684 KB Output is correct
5 Correct 4 ms 4864 KB Output is correct
6 Correct 3 ms 4688 KB Output is correct
7 Correct 3 ms 4688 KB Output is correct
8 Correct 3 ms 4836 KB Output is correct
9 Correct 3 ms 4688 KB Output is correct
10 Correct 3 ms 4688 KB Output is correct
11 Correct 4 ms 4944 KB Output is correct
12 Correct 4 ms 4944 KB Output is correct
13 Correct 4 ms 4944 KB Output is correct
14 Correct 4 ms 4944 KB Output is correct
15 Correct 4 ms 4688 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 3 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4684 KB Output is correct
2 Correct 4 ms 4688 KB Output is correct
3 Correct 4 ms 4688 KB Output is correct
4 Correct 4 ms 4684 KB Output is correct
5 Correct 4 ms 4864 KB Output is correct
6 Correct 3 ms 4688 KB Output is correct
7 Correct 3 ms 4688 KB Output is correct
8 Correct 3 ms 4836 KB Output is correct
9 Correct 3 ms 4688 KB Output is correct
10 Correct 3 ms 4688 KB Output is correct
11 Correct 4 ms 4944 KB Output is correct
12 Correct 4 ms 4944 KB Output is correct
13 Correct 4 ms 4944 KB Output is correct
14 Correct 4 ms 4944 KB Output is correct
15 Correct 4 ms 4688 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 3 ms 4688 KB Output is correct
18 Correct 50 ms 7496 KB Output is correct
19 Correct 47 ms 7276 KB Output is correct
20 Correct 54 ms 7496 KB Output is correct
21 Correct 48 ms 7128 KB Output is correct
22 Correct 52 ms 7240 KB Output is correct
23 Correct 53 ms 7240 KB Output is correct
24 Correct 57 ms 7508 KB Output is correct
25 Correct 52 ms 7496 KB Output is correct
26 Correct 48 ms 7240 KB Output is correct
27 Correct 44 ms 7196 KB Output is correct
28 Correct 35 ms 6992 KB Output is correct
29 Correct 36 ms 7148 KB Output is correct
30 Correct 34 ms 7248 KB Output is correct
31 Correct 35 ms 6996 KB Output is correct
32 Correct 37 ms 6992 KB Output is correct
33 Correct 1 ms 2384 KB Output is correct
34 Correct 38 ms 7188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 23112 KB Output is correct
2 Correct 47 ms 22856 KB Output is correct
3 Correct 46 ms 22712 KB Output is correct
4 Correct 49 ms 22604 KB Output is correct
5 Correct 45 ms 22600 KB Output is correct
6 Correct 44 ms 22604 KB Output is correct
7 Correct 51 ms 22484 KB Output is correct
8 Correct 48 ms 22600 KB Output is correct
9 Correct 46 ms 22604 KB Output is correct
10 Correct 55 ms 22716 KB Output is correct
11 Correct 160 ms 30840 KB Output is correct
12 Correct 167 ms 31816 KB Output is correct
13 Correct 151 ms 30536 KB Output is correct
14 Correct 141 ms 26456 KB Output is correct
15 Correct 163 ms 27720 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 43 ms 22600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 22856 KB Output is correct
2 Correct 45 ms 22620 KB Output is correct
3 Correct 43 ms 22724 KB Output is correct
4 Correct 45 ms 22912 KB Output is correct
5 Correct 51 ms 22856 KB Output is correct
6 Correct 40 ms 22600 KB Output is correct
7 Correct 44 ms 22608 KB Output is correct
8 Correct 47 ms 22636 KB Output is correct
9 Correct 50 ms 22844 KB Output is correct
10 Correct 51 ms 22600 KB Output is correct
11 Correct 165 ms 31608 KB Output is correct
12 Correct 152 ms 30600 KB Output is correct
13 Correct 147 ms 30536 KB Output is correct
14 Correct 142 ms 27464 KB Output is correct
15 Correct 128 ms 26184 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 41 ms 22916 KB Output is correct
18 Correct 4 ms 4684 KB Output is correct
19 Correct 4 ms 4688 KB Output is correct
20 Correct 4 ms 4688 KB Output is correct
21 Correct 4 ms 4684 KB Output is correct
22 Correct 4 ms 4864 KB Output is correct
23 Correct 3 ms 4688 KB Output is correct
24 Correct 3 ms 4688 KB Output is correct
25 Correct 3 ms 4836 KB Output is correct
26 Correct 3 ms 4688 KB Output is correct
27 Correct 3 ms 4688 KB Output is correct
28 Correct 4 ms 4944 KB Output is correct
29 Correct 4 ms 4944 KB Output is correct
30 Correct 4 ms 4944 KB Output is correct
31 Correct 4 ms 4944 KB Output is correct
32 Correct 4 ms 4688 KB Output is correct
33 Correct 1 ms 2384 KB Output is correct
34 Correct 3 ms 4688 KB Output is correct
35 Correct 50 ms 7496 KB Output is correct
36 Correct 47 ms 7276 KB Output is correct
37 Correct 54 ms 7496 KB Output is correct
38 Correct 48 ms 7128 KB Output is correct
39 Correct 52 ms 7240 KB Output is correct
40 Correct 53 ms 7240 KB Output is correct
41 Correct 57 ms 7508 KB Output is correct
42 Correct 52 ms 7496 KB Output is correct
43 Correct 48 ms 7240 KB Output is correct
44 Correct 44 ms 7196 KB Output is correct
45 Correct 35 ms 6992 KB Output is correct
46 Correct 36 ms 7148 KB Output is correct
47 Correct 34 ms 7248 KB Output is correct
48 Correct 35 ms 6996 KB Output is correct
49 Correct 37 ms 6992 KB Output is correct
50 Correct 1 ms 2384 KB Output is correct
51 Correct 38 ms 7188 KB Output is correct
52 Correct 52 ms 23112 KB Output is correct
53 Correct 47 ms 22856 KB Output is correct
54 Correct 46 ms 22712 KB Output is correct
55 Correct 49 ms 22604 KB Output is correct
56 Correct 45 ms 22600 KB Output is correct
57 Correct 44 ms 22604 KB Output is correct
58 Correct 51 ms 22484 KB Output is correct
59 Correct 48 ms 22600 KB Output is correct
60 Correct 46 ms 22604 KB Output is correct
61 Correct 55 ms 22716 KB Output is correct
62 Correct 160 ms 30840 KB Output is correct
63 Correct 167 ms 31816 KB Output is correct
64 Correct 151 ms 30536 KB Output is correct
65 Correct 141 ms 26456 KB Output is correct
66 Correct 163 ms 27720 KB Output is correct
67 Correct 1 ms 2384 KB Output is correct
68 Correct 43 ms 22600 KB Output is correct
69 Correct 125 ms 26184 KB Output is correct
70 Correct 128 ms 26308 KB Output is correct
71 Correct 130 ms 25928 KB Output is correct
72 Correct 120 ms 26192 KB Output is correct
73 Correct 152 ms 26100 KB Output is correct
74 Correct 150 ms 26708 KB Output is correct
75 Correct 168 ms 26184 KB Output is correct
76 Correct 131 ms 26448 KB Output is correct
77 Correct 148 ms 25160 KB Output is correct
78 Correct 155 ms 25672 KB Output is correct
79 Correct 208 ms 34644 KB Output is correct
80 Correct 209 ms 33356 KB Output is correct
81 Correct 184 ms 33352 KB Output is correct
82 Correct 168 ms 29252 KB Output is correct
83 Correct 164 ms 28744 KB Output is correct
84 Correct 1 ms 2552 KB Output is correct
85 Correct 90 ms 26180 KB Output is correct