Submission #866796

# Submission time Handle Problem Language Result Execution time Memory
866796 2023-10-27T05:51:44 Z sleepntsheep Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
378 ms 18088 KB
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
using ll = long long;
#define N 200005

int n, q, dep[N], jmp[N], par[N], t[N<<2], lz[N<<2];
pair<int, int> a[N];

void compress()
{
    vector<int> C;
    for (int i = 0; i < n; ++i) C.push_back(a[i].first), C.push_back(a[i].second);
    sort(ALL(C));
    C.erase(unique(ALL(C)), C.end());
    for (int i = 0; i < n; ++i) a[i].first = lower_bound(ALL(C), a[i].first) - C.begin(),
        a[i].second = lower_bound(ALL(C), a[i].second) - C.begin();
}

void push(int v, int l, int r)
{
    if (lz[v] < 1e9)
    {
        t[v] = lz[v];
        int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
        if (l != r) lz[vl] = lz[v], lz[vr] = lz[v];
        lz[v] = 1e9;
    }
}

void update(int v, int l, int r, int x, int y, int k)
{
    push(v, l, r);
    if (r < x || y < l) return;
    if (x <= l && r <= y) { lz[v] = k; push(v, l, r); return; }
    int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
    update(vl, l, m, x, y, k), update(vr, m+1, r, x, y, k);
    t[v] = min(t[vl], t[vr]);
}

int query(int v, int l, int r, int x, int y)
{
    push(v, l, r);
    if (r < x || y < l) return 1e9+86;
    if (x <= l && r <= y) return t[v];
    int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
    return min(query(vl, l, m, x, y), query(vr, m+1, r, x, y));
}

void init()
{
    memset(t, 63, sizeof t), memset(lz, 63, sizeof lz);
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;

    compress();
    par[n] = n; dep[n] = 0; jmp[n] = n;

    for (int i = n; i--;)
    {
        par[i] = min(query(0, 0, 2*n, a[i].first, a[i].second), par[i+1]);
        update(0, 0, 2*n, a[i].first, a[i].second, i);
        dep[i] = dep[par[i]] + 1;
        if (dep[par[i]] - dep[jmp[par[i]]] == dep[jmp[par[i]]] - dep[jmp[jmp[par[i]]]])
            jmp[i] = jmp[jmp[par[i]]];
        else jmp[i] = par[i];
    }
}

void answer()
{
    cin >> q;
    for (int x, y, z; q--;)
    {
        cin >> x >> y, --x, --y, z = dep[x];
        for (; x < y;)
        {
            if (jmp[x] <= y) x = jmp[x];
            else if (par[x] <= y) x = par[x];
            else break;
        }
        cout << 1 + z - dep[x]  << '\n';
    }
}

int main()
{
    init();
    answer();
    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 288 ms 10956 KB Output is correct
2 Correct 292 ms 10916 KB Output is correct
3 Correct 288 ms 11012 KB Output is correct
4 Correct 301 ms 10960 KB Output is correct
5 Correct 304 ms 10960 KB Output is correct
6 Correct 91 ms 10964 KB Output is correct
7 Correct 114 ms 11012 KB Output is correct
8 Correct 109 ms 10964 KB Output is correct
9 Correct 108 ms 11008 KB Output is correct
10 Correct 109 ms 10960 KB Output is correct
11 Correct 194 ms 10956 KB Output is correct
12 Correct 187 ms 10960 KB Output is correct
13 Correct 177 ms 10968 KB Output is correct
14 Correct 193 ms 10964 KB Output is correct
15 Correct 190 ms 10964 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 111 ms 10960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8796 KB Output is correct
2 Correct 8 ms 8796 KB Output is correct
3 Correct 8 ms 8796 KB Output is correct
4 Correct 8 ms 8992 KB Output is correct
5 Correct 9 ms 9048 KB Output is correct
6 Correct 4 ms 8796 KB Output is correct
7 Correct 5 ms 8796 KB Output is correct
8 Correct 5 ms 8784 KB Output is correct
9 Correct 5 ms 8968 KB Output is correct
10 Correct 5 ms 8792 KB Output is correct
11 Correct 5 ms 8796 KB Output is correct
12 Correct 5 ms 8796 KB Output is correct
13 Correct 5 ms 8796 KB Output is correct
14 Correct 6 ms 8796 KB Output is correct
15 Correct 7 ms 8792 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 5 ms 8936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8796 KB Output is correct
2 Correct 8 ms 8796 KB Output is correct
3 Correct 8 ms 8796 KB Output is correct
4 Correct 8 ms 8992 KB Output is correct
5 Correct 9 ms 9048 KB Output is correct
6 Correct 4 ms 8796 KB Output is correct
7 Correct 5 ms 8796 KB Output is correct
8 Correct 5 ms 8784 KB Output is correct
9 Correct 5 ms 8968 KB Output is correct
10 Correct 5 ms 8792 KB Output is correct
11 Correct 5 ms 8796 KB Output is correct
12 Correct 5 ms 8796 KB Output is correct
13 Correct 5 ms 8796 KB Output is correct
14 Correct 6 ms 8796 KB Output is correct
15 Correct 7 ms 8792 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 5 ms 8936 KB Output is correct
18 Correct 71 ms 11604 KB Output is correct
19 Correct 59 ms 11220 KB Output is correct
20 Correct 58 ms 11600 KB Output is correct
21 Correct 53 ms 11348 KB Output is correct
22 Correct 55 ms 11344 KB Output is correct
23 Correct 56 ms 11336 KB Output is correct
24 Correct 56 ms 11344 KB Output is correct
25 Correct 59 ms 11484 KB Output is correct
26 Correct 58 ms 11348 KB Output is correct
27 Correct 48 ms 11164 KB Output is correct
28 Correct 35 ms 10892 KB Output is correct
29 Correct 49 ms 10928 KB Output is correct
30 Correct 37 ms 11092 KB Output is correct
31 Correct 37 ms 10836 KB Output is correct
32 Correct 36 ms 10844 KB Output is correct
33 Correct 1 ms 8536 KB Output is correct
34 Correct 48 ms 11276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 328 ms 10956 KB Output is correct
2 Correct 315 ms 14800 KB Output is correct
3 Correct 274 ms 14524 KB Output is correct
4 Correct 284 ms 14428 KB Output is correct
5 Correct 288 ms 14444 KB Output is correct
6 Correct 92 ms 14460 KB Output is correct
7 Correct 101 ms 14544 KB Output is correct
8 Correct 100 ms 14288 KB Output is correct
9 Correct 102 ms 14324 KB Output is correct
10 Correct 115 ms 14552 KB Output is correct
11 Correct 185 ms 14028 KB Output is correct
12 Correct 197 ms 14296 KB Output is correct
13 Correct 178 ms 14036 KB Output is correct
14 Correct 187 ms 13940 KB Output is correct
15 Correct 195 ms 14288 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 97 ms 14576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 288 ms 10956 KB Output is correct
2 Correct 292 ms 10916 KB Output is correct
3 Correct 288 ms 11012 KB Output is correct
4 Correct 301 ms 10960 KB Output is correct
5 Correct 304 ms 10960 KB Output is correct
6 Correct 91 ms 10964 KB Output is correct
7 Correct 114 ms 11012 KB Output is correct
8 Correct 109 ms 10964 KB Output is correct
9 Correct 108 ms 11008 KB Output is correct
10 Correct 109 ms 10960 KB Output is correct
11 Correct 194 ms 10956 KB Output is correct
12 Correct 187 ms 10960 KB Output is correct
13 Correct 177 ms 10968 KB Output is correct
14 Correct 193 ms 10964 KB Output is correct
15 Correct 190 ms 10964 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 111 ms 10960 KB Output is correct
18 Correct 8 ms 8796 KB Output is correct
19 Correct 8 ms 8796 KB Output is correct
20 Correct 8 ms 8796 KB Output is correct
21 Correct 8 ms 8992 KB Output is correct
22 Correct 9 ms 9048 KB Output is correct
23 Correct 4 ms 8796 KB Output is correct
24 Correct 5 ms 8796 KB Output is correct
25 Correct 5 ms 8784 KB Output is correct
26 Correct 5 ms 8968 KB Output is correct
27 Correct 5 ms 8792 KB Output is correct
28 Correct 5 ms 8796 KB Output is correct
29 Correct 5 ms 8796 KB Output is correct
30 Correct 5 ms 8796 KB Output is correct
31 Correct 6 ms 8796 KB Output is correct
32 Correct 7 ms 8792 KB Output is correct
33 Correct 1 ms 8536 KB Output is correct
34 Correct 5 ms 8936 KB Output is correct
35 Correct 71 ms 11604 KB Output is correct
36 Correct 59 ms 11220 KB Output is correct
37 Correct 58 ms 11600 KB Output is correct
38 Correct 53 ms 11348 KB Output is correct
39 Correct 55 ms 11344 KB Output is correct
40 Correct 56 ms 11336 KB Output is correct
41 Correct 56 ms 11344 KB Output is correct
42 Correct 59 ms 11484 KB Output is correct
43 Correct 58 ms 11348 KB Output is correct
44 Correct 48 ms 11164 KB Output is correct
45 Correct 35 ms 10892 KB Output is correct
46 Correct 49 ms 10928 KB Output is correct
47 Correct 37 ms 11092 KB Output is correct
48 Correct 37 ms 10836 KB Output is correct
49 Correct 36 ms 10844 KB Output is correct
50 Correct 1 ms 8536 KB Output is correct
51 Correct 48 ms 11276 KB Output is correct
52 Correct 328 ms 10956 KB Output is correct
53 Correct 315 ms 14800 KB Output is correct
54 Correct 274 ms 14524 KB Output is correct
55 Correct 284 ms 14428 KB Output is correct
56 Correct 288 ms 14444 KB Output is correct
57 Correct 92 ms 14460 KB Output is correct
58 Correct 101 ms 14544 KB Output is correct
59 Correct 100 ms 14288 KB Output is correct
60 Correct 102 ms 14324 KB Output is correct
61 Correct 115 ms 14552 KB Output is correct
62 Correct 185 ms 14028 KB Output is correct
63 Correct 197 ms 14296 KB Output is correct
64 Correct 178 ms 14036 KB Output is correct
65 Correct 187 ms 13940 KB Output is correct
66 Correct 195 ms 14288 KB Output is correct
67 Correct 1 ms 8540 KB Output is correct
68 Correct 97 ms 14576 KB Output is correct
69 Correct 364 ms 17464 KB Output is correct
70 Correct 378 ms 17844 KB Output is correct
71 Correct 351 ms 17200 KB Output is correct
72 Correct 369 ms 17532 KB Output is correct
73 Correct 356 ms 17656 KB Output is correct
74 Correct 181 ms 18088 KB Output is correct
75 Correct 172 ms 17736 KB Output is correct
76 Correct 185 ms 18040 KB Output is correct
77 Correct 182 ms 17336 KB Output is correct
78 Correct 192 ms 17524 KB Output is correct
79 Correct 298 ms 16684 KB Output is correct
80 Correct 218 ms 16424 KB Output is correct
81 Correct 214 ms 16248 KB Output is correct
82 Correct 247 ms 16596 KB Output is correct
83 Correct 223 ms 16168 KB Output is correct
84 Correct 1 ms 8540 KB Output is correct
85 Correct 158 ms 17448 KB Output is correct