Submission #1024086

# Submission time Handle Problem Language Result Execution time Memory
1024086 2024-07-15T11:42:40 Z vjudge1 Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
209 ms 25468 KB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second

const int N = 2e5 + 10, LG = 18; 
int n, q, par[N][LG];
pair<int, int> a[N];

set<pair<int, int>> st;
bool check(int i){
    if (st.find({a[i].first, a[i].second}) != st.end())
        return 0;

    bool good = 1;

    st.insert({a[i].first, a[i].second});
    auto p = st.find({a[i].first, a[i].second});

    p++;
    if (p != st.end()){
        auto P = *p;
        if (P.F > a[i].second)
            good &= 1;
        else
            good &= 0;
    }
    p--;
    if (p != st.begin()){
        p--;
        auto P = *p;
        if (P.S < a[i].first)
            good &= 1;
        else
            good &= 0;
    }

    if (!good)
        st.erase({a[i].first, a[i].second});
    return good;
}

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

    cin >> n;
    for (int i = 1; i <= n; i ++)
        cin >> a[i].first >> a[i].second;

    par[n + 1][0] = n + 1;
    int r = 1;
    for (int i = 1; i <= n; i ++){
        while (r <= n and check(r))
            r++;
        par[i][0] = r;
        st.erase({a[i].first, a[i].second});
    }

    for (int jump = 1; jump < LG; jump ++)
        for (int i = 1; i <= n + 1; i ++)
            par[i][jump] = par[par[i][jump - 1]][jump - 1];

    cin >> q;
    while (q--){
        int u, v;
        cin >> u >> v;

        int ans = 0;
        for (int j = LG - 1; j >= 0; j --){
            if ((par[u][j]) <= v){
                u = par[u][j];
                ans += (1 << j);
            }
        }

        cout << ans + 1 << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 50 ms 15444 KB Output is correct
2 Correct 49 ms 15212 KB Output is correct
3 Correct 43 ms 15224 KB Output is correct
4 Correct 59 ms 15444 KB Output is correct
5 Correct 70 ms 15952 KB Output is correct
6 Correct 37 ms 14732 KB Output is correct
7 Correct 38 ms 14972 KB Output is correct
8 Correct 42 ms 14928 KB Output is correct
9 Correct 44 ms 15184 KB Output is correct
10 Correct 46 ms 14932 KB Output is correct
11 Correct 153 ms 24912 KB Output is correct
12 Correct 135 ms 23376 KB Output is correct
13 Correct 147 ms 23540 KB Output is correct
14 Correct 174 ms 21212 KB Output is correct
15 Correct 160 ms 19268 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 41 ms 15632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 3 ms 2396 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 3 ms 2392 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 2 ms 2564 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 4 ms 2796 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 3 ms 2772 KB Output is correct
14 Correct 4 ms 2652 KB Output is correct
15 Correct 4 ms 2636 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 3 ms 2396 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 3 ms 2392 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 2 ms 2564 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 4 ms 2796 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 3 ms 2772 KB Output is correct
14 Correct 4 ms 2652 KB Output is correct
15 Correct 4 ms 2636 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 45 ms 3412 KB Output is correct
19 Correct 41 ms 3164 KB Output is correct
20 Correct 46 ms 3408 KB Output is correct
21 Correct 41 ms 3156 KB Output is correct
22 Correct 45 ms 3468 KB Output is correct
23 Correct 42 ms 3152 KB Output is correct
24 Correct 41 ms 3156 KB Output is correct
25 Correct 45 ms 3168 KB Output is correct
26 Correct 41 ms 3156 KB Output is correct
27 Correct 38 ms 3148 KB Output is correct
28 Correct 30 ms 2908 KB Output is correct
29 Correct 31 ms 3024 KB Output is correct
30 Correct 32 ms 2908 KB Output is correct
31 Correct 31 ms 2908 KB Output is correct
32 Correct 35 ms 2904 KB Output is correct
33 Correct 0 ms 2392 KB Output is correct
34 Correct 35 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 15952 KB Output is correct
2 Correct 51 ms 15696 KB Output is correct
3 Correct 48 ms 14928 KB Output is correct
4 Correct 48 ms 14940 KB Output is correct
5 Correct 48 ms 14952 KB Output is correct
6 Correct 37 ms 14932 KB Output is correct
7 Correct 38 ms 14928 KB Output is correct
8 Correct 41 ms 14928 KB Output is correct
9 Correct 41 ms 14940 KB Output is correct
10 Correct 49 ms 15696 KB Output is correct
11 Correct 155 ms 23424 KB Output is correct
12 Correct 167 ms 25424 KB Output is correct
13 Correct 158 ms 23292 KB Output is correct
14 Correct 165 ms 19284 KB Output is correct
15 Correct 172 ms 21172 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 37 ms 14980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 15444 KB Output is correct
2 Correct 49 ms 15212 KB Output is correct
3 Correct 43 ms 15224 KB Output is correct
4 Correct 59 ms 15444 KB Output is correct
5 Correct 70 ms 15952 KB Output is correct
6 Correct 37 ms 14732 KB Output is correct
7 Correct 38 ms 14972 KB Output is correct
8 Correct 42 ms 14928 KB Output is correct
9 Correct 44 ms 15184 KB Output is correct
10 Correct 46 ms 14932 KB Output is correct
11 Correct 153 ms 24912 KB Output is correct
12 Correct 135 ms 23376 KB Output is correct
13 Correct 147 ms 23540 KB Output is correct
14 Correct 174 ms 21212 KB Output is correct
15 Correct 160 ms 19268 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 41 ms 15632 KB Output is correct
18 Correct 3 ms 2396 KB Output is correct
19 Correct 3 ms 2396 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
21 Correct 3 ms 2392 KB Output is correct
22 Correct 3 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 3 ms 2396 KB Output is correct
26 Correct 2 ms 2564 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 4 ms 2796 KB Output is correct
29 Correct 4 ms 2652 KB Output is correct
30 Correct 3 ms 2772 KB Output is correct
31 Correct 4 ms 2652 KB Output is correct
32 Correct 4 ms 2636 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 2 ms 2396 KB Output is correct
35 Correct 45 ms 3412 KB Output is correct
36 Correct 41 ms 3164 KB Output is correct
37 Correct 46 ms 3408 KB Output is correct
38 Correct 41 ms 3156 KB Output is correct
39 Correct 45 ms 3468 KB Output is correct
40 Correct 42 ms 3152 KB Output is correct
41 Correct 41 ms 3156 KB Output is correct
42 Correct 45 ms 3168 KB Output is correct
43 Correct 41 ms 3156 KB Output is correct
44 Correct 38 ms 3148 KB Output is correct
45 Correct 30 ms 2908 KB Output is correct
46 Correct 31 ms 3024 KB Output is correct
47 Correct 32 ms 2908 KB Output is correct
48 Correct 31 ms 2908 KB Output is correct
49 Correct 35 ms 2904 KB Output is correct
50 Correct 0 ms 2392 KB Output is correct
51 Correct 35 ms 3408 KB Output is correct
52 Correct 54 ms 15952 KB Output is correct
53 Correct 51 ms 15696 KB Output is correct
54 Correct 48 ms 14928 KB Output is correct
55 Correct 48 ms 14940 KB Output is correct
56 Correct 48 ms 14952 KB Output is correct
57 Correct 37 ms 14932 KB Output is correct
58 Correct 38 ms 14928 KB Output is correct
59 Correct 41 ms 14928 KB Output is correct
60 Correct 41 ms 14940 KB Output is correct
61 Correct 49 ms 15696 KB Output is correct
62 Correct 155 ms 23424 KB Output is correct
63 Correct 167 ms 25424 KB Output is correct
64 Correct 158 ms 23292 KB Output is correct
65 Correct 165 ms 19284 KB Output is correct
66 Correct 172 ms 21172 KB Output is correct
67 Correct 1 ms 2392 KB Output is correct
68 Correct 37 ms 14980 KB Output is correct
69 Correct 126 ms 16212 KB Output is correct
70 Correct 120 ms 16768 KB Output is correct
71 Correct 113 ms 15876 KB Output is correct
72 Correct 121 ms 16468 KB Output is correct
73 Correct 122 ms 16276 KB Output is correct
74 Correct 116 ms 16976 KB Output is correct
75 Correct 102 ms 15956 KB Output is correct
76 Correct 123 ms 17236 KB Output is correct
77 Correct 108 ms 15960 KB Output is correct
78 Correct 113 ms 16072 KB Output is correct
79 Correct 209 ms 25468 KB Output is correct
80 Correct 181 ms 23892 KB Output is correct
81 Correct 198 ms 23668 KB Output is correct
82 Correct 197 ms 20048 KB Output is correct
83 Correct 190 ms 19284 KB Output is correct
84 Correct 0 ms 2396 KB Output is correct
85 Correct 93 ms 16332 KB Output is correct