Submission #659799

# Submission time Handle Problem Language Result Execution time Memory
659799 2022-11-19T09:35:47 Z tibinyte Osumnjičeni (COCI21_osumnjiceni) C++14
60 / 110
1000 ms 50356 KB
#include <bits/stdc++.h>
using namespace std;

const int maxlog = 18;

struct aint
{
    vector<int> a;
    vector<int> lazy;
    void resize(int n)
    {
        a = lazy = vector<int>(4 * n);
    }
    void prop(int node, int left, int right)
    {
        a[node] += lazy[node];
        if (left != right)
        {
            lazy[2 * node] += lazy[node];
            lazy[2 * node + 1] += lazy[node];
        }
        lazy[node] = 0;
    }
    void update(int node, int left, int right, int st, int dr, int val)
    {
        prop(node, left, right);
        if (right < st || left > dr)
        {
            return;
        }
        if (st <= left && dr >= right)
        {
            lazy[node] += val;
            prop(node, left, right);
            return;
        }
        int mid = (left + right) / 2;
        update(2 * node, left, mid, st, dr, val);
        update(2 * node + 1, mid + 1, right, st, dr, val);
        a[node] = a[2 * node] + a[2 * node + 1];
    }
    int query(int node, int left, int right, int st, int dr)
    {
        prop(node, left, right);
        if (right < st || left > dr)
        {
            return 0;
        }
        if (st <= left && dr >= right)
        {
            return a[node];
        }
        int mid = (left + right) / 2;
        return query(2 * node, left, mid, st, dr) + query(2 * node + 1, mid + 1, right, st, dr);
    }
};
int32_t main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int, int>> a(n + 1);
    vector<int> norm;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i].first >> a[i].second;
        norm.push_back(a[i].first);
        norm.push_back(a[i].second);
    }
    sort(norm.begin(), norm.end());
    map<int, int> qui;
    int p = 0;
    for (auto i : norm)
    {
        if (qui.find(i) == qui.end())
        {
            qui[i] = ++p;
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        a[i].first = qui[a[i].first];
        a[i].second = qui[a[i].second];
    }
    aint tree;
    tree.resize(p);
    vector<int> next(n + 2);
    next[n + 1] = n + 1;
    int p2 = 1;
    for (int i = 1; i <= n; ++i)
    {
        if (i != 1)
        {
            tree.update(1, 1, p, a[i - 1].first, a[i - 1].second, -1);
        }
        while (p2 <= n && tree.query(1, 1, p, a[p2].first, a[p2].second) == 0)
        {
            tree.update(1, 1, p, a[p2].first, a[p2].second, 1);
            p2++;
        }
        next[i] = p2;
    }
    int jump[maxlog + 1][n + 2];
    for (int i = 1; i <= n + 1; ++i)
    {
        jump[0][i] = next[i];
    }
    for (int j = 1; j <= maxlog; ++j)
    {
        for (int i = 1; i <= n + 1; ++i)
        {
            jump[j][i] = jump[j - 1][jump[j - 1][i]];
        }
    }
    int q;
    cin >> q;
    while (q--)
    {
        int st, dr;
        cin >> st >> dr;
        int ans = 0;
        int wh = st;
        for (int i = maxlog; i >= 0; --i)
        {
            if (jump[i][wh] <= dr)
            {
                wh = jump[i][wh];
                ans += (1 << i);
            }
        }
        cout << ans + 1 << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 875 ms 48040 KB Output is correct
2 Correct 846 ms 47440 KB Output is correct
3 Correct 830 ms 47508 KB Output is correct
4 Correct 873 ms 48056 KB Output is correct
5 Correct 919 ms 50148 KB Output is correct
6 Correct 54 ms 17312 KB Output is correct
7 Correct 71 ms 17544 KB Output is correct
8 Correct 72 ms 17712 KB Output is correct
9 Correct 85 ms 18168 KB Output is correct
10 Correct 93 ms 17636 KB Output is correct
11 Correct 583 ms 49204 KB Output is correct
12 Correct 512 ms 46232 KB Output is correct
13 Correct 527 ms 46140 KB Output is correct
14 Correct 590 ms 49348 KB Output is correct
15 Correct 560 ms 47916 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 62 ms 18360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1588 KB Output is correct
2 Correct 18 ms 1484 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 14 ms 1492 KB Output is correct
5 Correct 13 ms 1464 KB Output is correct
6 Correct 3 ms 840 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 4 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 10 ms 1464 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 11 ms 1492 KB Output is correct
14 Correct 11 ms 1492 KB Output is correct
15 Correct 11 ms 1492 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 3 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1588 KB Output is correct
2 Correct 18 ms 1484 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 14 ms 1492 KB Output is correct
5 Correct 13 ms 1464 KB Output is correct
6 Correct 3 ms 840 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 4 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 10 ms 1464 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 11 ms 1492 KB Output is correct
14 Correct 11 ms 1492 KB Output is correct
15 Correct 11 ms 1492 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 3 ms 852 KB Output is correct
18 Correct 77 ms 2448 KB Output is correct
19 Correct 69 ms 2184 KB Output is correct
20 Correct 87 ms 2392 KB Output is correct
21 Correct 70 ms 2272 KB Output is correct
22 Correct 73 ms 2260 KB Output is correct
23 Correct 59 ms 1580 KB Output is correct
24 Correct 68 ms 1584 KB Output is correct
25 Correct 64 ms 1520 KB Output is correct
26 Correct 64 ms 1484 KB Output is correct
27 Correct 63 ms 1516 KB Output is correct
28 Correct 50 ms 1740 KB Output is correct
29 Correct 53 ms 1860 KB Output is correct
30 Correct 52 ms 1860 KB Output is correct
31 Correct 63 ms 1940 KB Output is correct
32 Correct 52 ms 1864 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 49 ms 1680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 919 ms 50356 KB Output is correct
2 Correct 901 ms 49300 KB Output is correct
3 Correct 824 ms 45896 KB Output is correct
4 Correct 811 ms 45392 KB Output is correct
5 Correct 822 ms 46900 KB Output is correct
6 Correct 52 ms 17392 KB Output is correct
7 Correct 63 ms 17308 KB Output is correct
8 Correct 71 ms 17472 KB Output is correct
9 Correct 78 ms 17256 KB Output is correct
10 Correct 104 ms 18712 KB Output is correct
11 Correct 523 ms 45940 KB Output is correct
12 Correct 581 ms 50340 KB Output is correct
13 Correct 510 ms 45768 KB Output is correct
14 Correct 568 ms 47140 KB Output is correct
15 Correct 631 ms 50132 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 53 ms 17588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 875 ms 48040 KB Output is correct
2 Correct 846 ms 47440 KB Output is correct
3 Correct 830 ms 47508 KB Output is correct
4 Correct 873 ms 48056 KB Output is correct
5 Correct 919 ms 50148 KB Output is correct
6 Correct 54 ms 17312 KB Output is correct
7 Correct 71 ms 17544 KB Output is correct
8 Correct 72 ms 17712 KB Output is correct
9 Correct 85 ms 18168 KB Output is correct
10 Correct 93 ms 17636 KB Output is correct
11 Correct 583 ms 49204 KB Output is correct
12 Correct 512 ms 46232 KB Output is correct
13 Correct 527 ms 46140 KB Output is correct
14 Correct 590 ms 49348 KB Output is correct
15 Correct 560 ms 47916 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 62 ms 18360 KB Output is correct
18 Correct 15 ms 1588 KB Output is correct
19 Correct 18 ms 1484 KB Output is correct
20 Correct 13 ms 1492 KB Output is correct
21 Correct 14 ms 1492 KB Output is correct
22 Correct 13 ms 1464 KB Output is correct
23 Correct 3 ms 840 KB Output is correct
24 Correct 4 ms 724 KB Output is correct
25 Correct 4 ms 724 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 4 ms 724 KB Output is correct
28 Correct 10 ms 1464 KB Output is correct
29 Correct 10 ms 1408 KB Output is correct
30 Correct 11 ms 1492 KB Output is correct
31 Correct 11 ms 1492 KB Output is correct
32 Correct 11 ms 1492 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 3 ms 852 KB Output is correct
35 Correct 77 ms 2448 KB Output is correct
36 Correct 69 ms 2184 KB Output is correct
37 Correct 87 ms 2392 KB Output is correct
38 Correct 70 ms 2272 KB Output is correct
39 Correct 73 ms 2260 KB Output is correct
40 Correct 59 ms 1580 KB Output is correct
41 Correct 68 ms 1584 KB Output is correct
42 Correct 64 ms 1520 KB Output is correct
43 Correct 64 ms 1484 KB Output is correct
44 Correct 63 ms 1516 KB Output is correct
45 Correct 50 ms 1740 KB Output is correct
46 Correct 53 ms 1860 KB Output is correct
47 Correct 52 ms 1860 KB Output is correct
48 Correct 63 ms 1940 KB Output is correct
49 Correct 52 ms 1864 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 49 ms 1680 KB Output is correct
52 Correct 919 ms 50356 KB Output is correct
53 Correct 901 ms 49300 KB Output is correct
54 Correct 824 ms 45896 KB Output is correct
55 Correct 811 ms 45392 KB Output is correct
56 Correct 822 ms 46900 KB Output is correct
57 Correct 52 ms 17392 KB Output is correct
58 Correct 63 ms 17308 KB Output is correct
59 Correct 71 ms 17472 KB Output is correct
60 Correct 78 ms 17256 KB Output is correct
61 Correct 104 ms 18712 KB Output is correct
62 Correct 523 ms 45940 KB Output is correct
63 Correct 581 ms 50340 KB Output is correct
64 Correct 510 ms 45768 KB Output is correct
65 Correct 568 ms 47140 KB Output is correct
66 Correct 631 ms 50132 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 53 ms 17588 KB Output is correct
69 Execution timed out 1059 ms 48692 KB Time limit exceeded
70 Halted 0 ms 0 KB -