답안 #863135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863135 2023-10-19T16:25:33 Z 3omar_ahmed Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
986 ms 117324 KB
#include <bits/stdc++.h>
using namespace std ;
#define int long long
#define endl '\n'
#define all(a) a.begin() , a.end()
#define alr(a) a.rbegin() , a.rend()

struct segtree {
    int sz;
    vector < int > tree, lazy;
    void init(int n) {
        sz = 1;
        while(sz <= n) sz <<= 1;
        lazy = tree = vector < int > (sz << 2, 1e9);
    }

    void prop(int node) {
        if(lazy[node] != 1e9) {
            tree[node * 2 + 1] = tree[node * 2 + 2] = lazy[node];
            lazy[node * 2 + 1] = lazy[node * 2 + 2] = lazy[node];

            lazy[node] = 1e9;
        }
    }

    void update(int node, int lnode, int rnode, int l, int r, int val) {
        if(rnode <= l || r <= lnode) return;
        if(lnode >= l && rnode <= r) {
            tree[node] = lazy[node] = val;
            return;
        }
        int mid = (lnode + rnode) >> 1;
        prop(node);
        update(node * 2 + 1, lnode, mid, l, r, val);
        update(node * 2 + 2, mid, rnode, l, r, val);
        tree[node] = min(tree[node * 2 + 1], tree[node * 2 + 2]);
    }
    void update(int l, int r, int val) {
        update(0, 0, sz, l, r, val);
    }

    int query(int node, int lnode, int rnode, int l, int r) {
        if(rnode <= l || r <= lnode) return 1e9;
        if(lnode >= l && rnode <= r) {
            return tree[node];
        }
        int mid = (lnode + rnode) >> 1;
        prop(node);
        int a = query(node * 2 + 1, lnode, mid, l, r);
        int b = query(node * 2 + 2, mid, rnode, l, r);
        return min(a, b);
    }
    int query(int l, int r) {
        return query(0, 0, sz, l, r);
    }
};


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

    int n;
    cin >> n;
    n += 1;
    vector < pair < int , int >> a(n);
    set < int > ss;
    for(int i = 0 ; i + 1 < n ; i++) {
        cin >> a[i].first >> a[i].second;
        ss.insert(a[i].first);
        ss.insert(a[i].second);
    }    
    map < int,  int > mp;
    int cnt = 1;
    for(auto i : ss) {
        mp[i] = cnt++;
    }
    for(int i = 0 ; i + 1 < n ; i++) {
        a[i].first = mp[a[i].first];
        a[i].second = mp[a[i].second];
    }

    a[n - 1] = {1, n};
    vector < vector < int >> nxt(20, vector < int > (n + 1, -1));
    nxt[0][n - 1] = n - 1;

    segtree s; s.init(ss.size() + 10);
    for(int i = n - 2 ; i >= 0 ; i--) {
        nxt[0][i] = min(nxt[0][i + 1], n - 2);
        nxt[0][i] = min(nxt[0][i], s.query(a[i].first, a[i].second + 1));
        s.update(a[i].first, a[i].second + 1, i - 1);
    }

    // for(int i = 0 ; i < n - 1 ; i ++) cout << nxt[0][i] + 1 << " ";
    // cout << endl;

    for(int i = 1 ; i < 20 ; i++) {
        for(int j = 0 ; j < n ; j++) {
            if(nxt[i - 1][j] != -1)
                nxt[i][j] = nxt[i - 1][nxt[i - 1][j] + 1];
        }
    }

    int q;
    cin >> q;
    while(q--) {
        int l, r;
        cin >> l >> r;
        l -= 1, r -= 1;
        int ans = 0;
        for(int i = 19 ; i >= 0 ; i--) {
            if(nxt[i][l] <= r && nxt[i][l] != -1) {
                ans += (1ll << i);
                l = nxt[i][l] + 1;
            }
        }
        ans += (l <= r);
        cout << ans << endl;
    }
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 748 ms 108040 KB Output is correct
2 Correct 706 ms 110612 KB Output is correct
3 Correct 704 ms 110820 KB Output is correct
4 Correct 697 ms 111816 KB Output is correct
5 Correct 795 ms 115008 KB Output is correct
6 Correct 48 ms 36436 KB Output is correct
7 Correct 58 ms 37104 KB Output is correct
8 Correct 57 ms 37716 KB Output is correct
9 Correct 58 ms 38372 KB Output is correct
10 Correct 59 ms 36948 KB Output is correct
11 Correct 601 ms 113188 KB Output is correct
12 Correct 473 ms 107956 KB Output is correct
13 Correct 475 ms 107988 KB Output is correct
14 Correct 557 ms 113056 KB Output is correct
15 Correct 536 ms 110684 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 66 ms 39056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3420 KB Output is correct
2 Correct 9 ms 3420 KB Output is correct
3 Correct 9 ms 3500 KB Output is correct
4 Correct 10 ms 3420 KB Output is correct
5 Correct 9 ms 3420 KB Output is correct
6 Correct 3 ms 1412 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
8 Correct 3 ms 1372 KB Output is correct
9 Correct 3 ms 1448 KB Output is correct
10 Correct 4 ms 1372 KB Output is correct
11 Correct 12 ms 3420 KB Output is correct
12 Correct 7 ms 3288 KB Output is correct
13 Correct 9 ms 3420 KB Output is correct
14 Correct 8 ms 3420 KB Output is correct
15 Correct 7 ms 3540 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 3 ms 1472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3420 KB Output is correct
2 Correct 9 ms 3420 KB Output is correct
3 Correct 9 ms 3500 KB Output is correct
4 Correct 10 ms 3420 KB Output is correct
5 Correct 9 ms 3420 KB Output is correct
6 Correct 3 ms 1412 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
8 Correct 3 ms 1372 KB Output is correct
9 Correct 3 ms 1448 KB Output is correct
10 Correct 4 ms 1372 KB Output is correct
11 Correct 12 ms 3420 KB Output is correct
12 Correct 7 ms 3288 KB Output is correct
13 Correct 9 ms 3420 KB Output is correct
14 Correct 8 ms 3420 KB Output is correct
15 Correct 7 ms 3540 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 3 ms 1472 KB Output is correct
18 Correct 70 ms 6088 KB Output is correct
19 Correct 64 ms 5672 KB Output is correct
20 Correct 71 ms 6252 KB Output is correct
21 Correct 65 ms 5716 KB Output is correct
22 Correct 68 ms 5864 KB Output is correct
23 Correct 72 ms 3864 KB Output is correct
24 Correct 64 ms 3988 KB Output is correct
25 Correct 63 ms 3976 KB Output is correct
26 Correct 60 ms 3940 KB Output is correct
27 Correct 71 ms 3768 KB Output is correct
28 Correct 44 ms 5464 KB Output is correct
29 Correct 47 ms 5568 KB Output is correct
30 Correct 46 ms 5540 KB Output is correct
31 Correct 47 ms 5456 KB Output is correct
32 Correct 47 ms 5456 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 44 ms 3736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 776 ms 111544 KB Output is correct
2 Correct 742 ms 113916 KB Output is correct
3 Correct 716 ms 107964 KB Output is correct
4 Correct 629 ms 107212 KB Output is correct
5 Correct 712 ms 109628 KB Output is correct
6 Correct 49 ms 36892 KB Output is correct
7 Correct 52 ms 36432 KB Output is correct
8 Correct 52 ms 36700 KB Output is correct
9 Correct 56 ms 36296 KB Output is correct
10 Correct 63 ms 39248 KB Output is correct
11 Correct 547 ms 107712 KB Output is correct
12 Correct 547 ms 114744 KB Output is correct
13 Correct 472 ms 107368 KB Output is correct
14 Correct 516 ms 109656 KB Output is correct
15 Correct 597 ms 114244 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 50 ms 37260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 748 ms 108040 KB Output is correct
2 Correct 706 ms 110612 KB Output is correct
3 Correct 704 ms 110820 KB Output is correct
4 Correct 697 ms 111816 KB Output is correct
5 Correct 795 ms 115008 KB Output is correct
6 Correct 48 ms 36436 KB Output is correct
7 Correct 58 ms 37104 KB Output is correct
8 Correct 57 ms 37716 KB Output is correct
9 Correct 58 ms 38372 KB Output is correct
10 Correct 59 ms 36948 KB Output is correct
11 Correct 601 ms 113188 KB Output is correct
12 Correct 473 ms 107956 KB Output is correct
13 Correct 475 ms 107988 KB Output is correct
14 Correct 557 ms 113056 KB Output is correct
15 Correct 536 ms 110684 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 66 ms 39056 KB Output is correct
18 Correct 10 ms 3420 KB Output is correct
19 Correct 9 ms 3420 KB Output is correct
20 Correct 9 ms 3500 KB Output is correct
21 Correct 10 ms 3420 KB Output is correct
22 Correct 9 ms 3420 KB Output is correct
23 Correct 3 ms 1412 KB Output is correct
24 Correct 3 ms 1372 KB Output is correct
25 Correct 3 ms 1372 KB Output is correct
26 Correct 3 ms 1448 KB Output is correct
27 Correct 4 ms 1372 KB Output is correct
28 Correct 12 ms 3420 KB Output is correct
29 Correct 7 ms 3288 KB Output is correct
30 Correct 9 ms 3420 KB Output is correct
31 Correct 8 ms 3420 KB Output is correct
32 Correct 7 ms 3540 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 3 ms 1472 KB Output is correct
35 Correct 70 ms 6088 KB Output is correct
36 Correct 64 ms 5672 KB Output is correct
37 Correct 71 ms 6252 KB Output is correct
38 Correct 65 ms 5716 KB Output is correct
39 Correct 68 ms 5864 KB Output is correct
40 Correct 72 ms 3864 KB Output is correct
41 Correct 64 ms 3988 KB Output is correct
42 Correct 63 ms 3976 KB Output is correct
43 Correct 60 ms 3940 KB Output is correct
44 Correct 71 ms 3768 KB Output is correct
45 Correct 44 ms 5464 KB Output is correct
46 Correct 47 ms 5568 KB Output is correct
47 Correct 46 ms 5540 KB Output is correct
48 Correct 47 ms 5456 KB Output is correct
49 Correct 47 ms 5456 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 44 ms 3736 KB Output is correct
52 Correct 776 ms 111544 KB Output is correct
53 Correct 742 ms 113916 KB Output is correct
54 Correct 716 ms 107964 KB Output is correct
55 Correct 629 ms 107212 KB Output is correct
56 Correct 712 ms 109628 KB Output is correct
57 Correct 49 ms 36892 KB Output is correct
58 Correct 52 ms 36432 KB Output is correct
59 Correct 52 ms 36700 KB Output is correct
60 Correct 56 ms 36296 KB Output is correct
61 Correct 63 ms 39248 KB Output is correct
62 Correct 547 ms 107712 KB Output is correct
63 Correct 547 ms 114744 KB Output is correct
64 Correct 472 ms 107368 KB Output is correct
65 Correct 516 ms 109656 KB Output is correct
66 Correct 597 ms 114244 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 50 ms 37260 KB Output is correct
69 Correct 955 ms 113060 KB Output is correct
70 Correct 937 ms 117324 KB Output is correct
71 Correct 862 ms 110836 KB Output is correct
72 Correct 920 ms 115204 KB Output is correct
73 Correct 986 ms 113872 KB Output is correct
74 Correct 293 ms 41804 KB Output is correct
75 Correct 297 ms 38992 KB Output is correct
76 Correct 263 ms 42048 KB Output is correct
77 Correct 244 ms 38780 KB Output is correct
78 Correct 260 ms 39568 KB Output is correct
79 Correct 710 ms 117008 KB Output is correct
80 Correct 552 ms 110784 KB Output is correct
81 Correct 576 ms 110368 KB Output is correct
82 Correct 609 ms 114764 KB Output is correct
83 Correct 595 ms 111280 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 104 ms 38856 KB Output is correct