답안 #659795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659795 2022-11-19T09:31:34 Z tibinyte Osumnjičeni (COCI21_osumnjiceni) C++17
60 / 110
1000 ms 62220 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;
    }
    vector<vector<int>> jump(n + 2, vector<int>(maxlog + 1));
    for (int i = 1; i <= n + 1; ++i)
    {
        jump[i][0] = next[i];
    }
    for (int j = 1; j <= maxlog; ++j)
    {
        for (int i = 1; i <= n + 1; ++i)
        {
            jump[i][j] = jump[jump[i][j - 1]][j - 1];
        }
    }
    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[wh][i] <= dr)
            {
                wh = jump[wh][i];
                ans += (1 << i);
            }
        }
        cout << ans + 1 << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 920 ms 56504 KB Output is correct
2 Correct 863 ms 56092 KB Output is correct
3 Correct 850 ms 56300 KB Output is correct
4 Correct 895 ms 56952 KB Output is correct
5 Correct 931 ms 59476 KB Output is correct
6 Correct 91 ms 25724 KB Output is correct
7 Correct 113 ms 26072 KB Output is correct
8 Correct 120 ms 26616 KB Output is correct
9 Correct 126 ms 26948 KB Output is correct
10 Correct 136 ms 26116 KB Output is correct
11 Correct 589 ms 58320 KB Output is correct
12 Correct 591 ms 54948 KB Output is correct
13 Correct 538 ms 54528 KB Output is correct
14 Correct 633 ms 58436 KB Output is correct
15 Correct 612 ms 56696 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 107 ms 27308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1832 KB Output is correct
2 Correct 14 ms 1736 KB Output is correct
3 Correct 14 ms 1748 KB Output is correct
4 Correct 14 ms 1844 KB Output is correct
5 Correct 15 ms 1808 KB Output is correct
6 Correct 4 ms 1120 KB Output is correct
7 Correct 5 ms 1100 KB Output is correct
8 Correct 4 ms 1108 KB Output is correct
9 Correct 5 ms 1120 KB Output is correct
10 Correct 6 ms 1108 KB Output is correct
11 Correct 9 ms 1876 KB Output is correct
12 Correct 9 ms 1748 KB Output is correct
13 Correct 10 ms 1740 KB Output is correct
14 Correct 10 ms 1832 KB Output is correct
15 Correct 10 ms 1880 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 3 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1832 KB Output is correct
2 Correct 14 ms 1736 KB Output is correct
3 Correct 14 ms 1748 KB Output is correct
4 Correct 14 ms 1844 KB Output is correct
5 Correct 15 ms 1808 KB Output is correct
6 Correct 4 ms 1120 KB Output is correct
7 Correct 5 ms 1100 KB Output is correct
8 Correct 4 ms 1108 KB Output is correct
9 Correct 5 ms 1120 KB Output is correct
10 Correct 6 ms 1108 KB Output is correct
11 Correct 9 ms 1876 KB Output is correct
12 Correct 9 ms 1748 KB Output is correct
13 Correct 10 ms 1740 KB Output is correct
14 Correct 10 ms 1832 KB Output is correct
15 Correct 10 ms 1880 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 3 ms 1108 KB Output is correct
18 Correct 83 ms 3160 KB Output is correct
19 Correct 75 ms 3036 KB Output is correct
20 Correct 83 ms 3168 KB Output is correct
21 Correct 73 ms 2976 KB Output is correct
22 Correct 92 ms 3040 KB Output is correct
23 Correct 71 ms 2260 KB Output is correct
24 Correct 70 ms 2380 KB Output is correct
25 Correct 81 ms 2252 KB Output is correct
26 Correct 68 ms 2320 KB Output is correct
27 Correct 62 ms 2256 KB Output is correct
28 Correct 68 ms 2620 KB Output is correct
29 Correct 52 ms 2588 KB Output is correct
30 Correct 50 ms 2636 KB Output is correct
31 Correct 51 ms 2612 KB Output is correct
32 Correct 52 ms 2728 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 49 ms 2456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 965 ms 59076 KB Output is correct
2 Correct 908 ms 58284 KB Output is correct
3 Correct 886 ms 54380 KB Output is correct
4 Correct 888 ms 55236 KB Output is correct
5 Correct 955 ms 58468 KB Output is correct
6 Correct 103 ms 28812 KB Output is correct
7 Correct 119 ms 28628 KB Output is correct
8 Correct 119 ms 28844 KB Output is correct
9 Correct 151 ms 28612 KB Output is correct
10 Correct 170 ms 30744 KB Output is correct
11 Correct 663 ms 56588 KB Output is correct
12 Correct 691 ms 62220 KB Output is correct
13 Correct 554 ms 56728 KB Output is correct
14 Correct 594 ms 58316 KB Output is correct
15 Correct 647 ms 61856 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 110 ms 29316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 920 ms 56504 KB Output is correct
2 Correct 863 ms 56092 KB Output is correct
3 Correct 850 ms 56300 KB Output is correct
4 Correct 895 ms 56952 KB Output is correct
5 Correct 931 ms 59476 KB Output is correct
6 Correct 91 ms 25724 KB Output is correct
7 Correct 113 ms 26072 KB Output is correct
8 Correct 120 ms 26616 KB Output is correct
9 Correct 126 ms 26948 KB Output is correct
10 Correct 136 ms 26116 KB Output is correct
11 Correct 589 ms 58320 KB Output is correct
12 Correct 591 ms 54948 KB Output is correct
13 Correct 538 ms 54528 KB Output is correct
14 Correct 633 ms 58436 KB Output is correct
15 Correct 612 ms 56696 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 107 ms 27308 KB Output is correct
18 Correct 15 ms 1832 KB Output is correct
19 Correct 14 ms 1736 KB Output is correct
20 Correct 14 ms 1748 KB Output is correct
21 Correct 14 ms 1844 KB Output is correct
22 Correct 15 ms 1808 KB Output is correct
23 Correct 4 ms 1120 KB Output is correct
24 Correct 5 ms 1100 KB Output is correct
25 Correct 4 ms 1108 KB Output is correct
26 Correct 5 ms 1120 KB Output is correct
27 Correct 6 ms 1108 KB Output is correct
28 Correct 9 ms 1876 KB Output is correct
29 Correct 9 ms 1748 KB Output is correct
30 Correct 10 ms 1740 KB Output is correct
31 Correct 10 ms 1832 KB Output is correct
32 Correct 10 ms 1880 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 3 ms 1108 KB Output is correct
35 Correct 83 ms 3160 KB Output is correct
36 Correct 75 ms 3036 KB Output is correct
37 Correct 83 ms 3168 KB Output is correct
38 Correct 73 ms 2976 KB Output is correct
39 Correct 92 ms 3040 KB Output is correct
40 Correct 71 ms 2260 KB Output is correct
41 Correct 70 ms 2380 KB Output is correct
42 Correct 81 ms 2252 KB Output is correct
43 Correct 68 ms 2320 KB Output is correct
44 Correct 62 ms 2256 KB Output is correct
45 Correct 68 ms 2620 KB Output is correct
46 Correct 52 ms 2588 KB Output is correct
47 Correct 50 ms 2636 KB Output is correct
48 Correct 51 ms 2612 KB Output is correct
49 Correct 52 ms 2728 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 49 ms 2456 KB Output is correct
52 Correct 965 ms 59076 KB Output is correct
53 Correct 908 ms 58284 KB Output is correct
54 Correct 886 ms 54380 KB Output is correct
55 Correct 888 ms 55236 KB Output is correct
56 Correct 955 ms 58468 KB Output is correct
57 Correct 103 ms 28812 KB Output is correct
58 Correct 119 ms 28628 KB Output is correct
59 Correct 119 ms 28844 KB Output is correct
60 Correct 151 ms 28612 KB Output is correct
61 Correct 170 ms 30744 KB Output is correct
62 Correct 663 ms 56588 KB Output is correct
63 Correct 691 ms 62220 KB Output is correct
64 Correct 554 ms 56728 KB Output is correct
65 Correct 594 ms 58316 KB Output is correct
66 Correct 647 ms 61856 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 110 ms 29316 KB Output is correct
69 Execution timed out 1073 ms 60792 KB Time limit exceeded
70 Halted 0 ms 0 KB -