답안 #915442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915442 2024-01-23T22:59:20 Z SalihSahin Osumnjičeni (COCI21_osumnjiceni) C++14
60 / 110
1000 ms 69204 KB
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
 
const int mod = 998244353;

struct SEGT{
    vector<int> tree, lazy;

    void init(int n){
        tree.assign(4*n, 0);
        lazy.assign(4*n, 0);
    }

    void push(int ind){
        if(lazy[ind]){
            tree[ind*2] += lazy[ind];
            tree[ind*2+1] += lazy[ind];
            lazy[ind*2] += lazy[ind];
            lazy[ind*2+1] += lazy[ind];
        }
        lazy[ind] = 0;
    }

    void update(int ind, int l, int r, int ql, int qr, int val){
        if(l > r || l > qr || r < ql) return;
        if(l >= ql && r <= qr){
            tree[ind] += val;
            lazy[ind] += val;
        }
        else{
            push(ind);
            int m = (l + r)/2;

            update(ind*2, l, m, ql, qr, val);
            update(ind*2+1, m+1, r, ql, qr, val);
            tree[ind] = max(tree[ind*2], tree[ind*2+1]);
        }
    }

    int query(int ind, int l, int r, int ql, int qr){
        if(l > r || l > qr || r < ql) return 0;
        if(l >= ql && r <= qr) return tree[ind];
        else{
            push(ind);
            int m = (l + r)/2;

            return max(query(ind*2, l, m, ql, qr),  query(ind*2+1, m+1, r, ql, qr));
        }
    }
};

int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<pair<int, int> > a(n);
    set<int> ste;

    for(int i = 0; i < n; i++){
        int l, r;
        cin>>l>>r;
        ste.insert(l);
        ste.insert(r);
        a[i] = mp(l, r);
    }
    map<int, int> conv;
    int val = 1;
    for(auto itr: ste){
        conv[itr] = val;
        val++;
    }
    for(int i = 0; i < n; i++){
        a[i] = mp(conv[a[i].first], conv[a[i].second]);
    }
    int N = val + 5;
    
    SEGT seg;
    seg.init(N);
    int go[n];
    bool flag = 1;
    int r = 0;
    for(int l = 0; l < n; l++){
        while(r < n && flag && seg.query(1, 1, N, a[r].first, a[r].second) == 0){
            seg.update(1, 1, N, a[r].first, a[r].second, 1);
            r++;
        }

        go[l] = r;
        if(r < n && !(a[l].second < a[r].first || a[r].second < a[l].first)) flag = 1;
        else flag = 0;

        seg.update(1, 1, N, a[l].first, a[l].second, -1);
    }

    int K = 18;
    int lift[K][n+1];
    for(int i = 0; i < n; i++){
        lift[0][i] = go[i];
    }
    lift[0][n] = n;

    for(int i = 1; i < K; i++){
        for(int j = 0; j <= n; j++){
            lift[i][j] = lift[i-1][lift[i-1][j]];
        }
    }

    int q, ans;
    cin>>q;
    while(q--){
        int lq, rq;
        cin>>lq>>rq;
        lq--, rq--;

        ans = 1;

        for(int i = K-1; i >= 0; i--){
            if(lift[i][lq] <= rq){
                lq = lift[i][lq];
                ans += (1 << i);
            }
        }

        cout<<ans<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 747 ms 66132 KB Output is correct
2 Correct 754 ms 65280 KB Output is correct
3 Correct 760 ms 65620 KB Output is correct
4 Correct 750 ms 66284 KB Output is correct
5 Correct 790 ms 68952 KB Output is correct
6 Correct 49 ms 17604 KB Output is correct
7 Correct 53 ms 17744 KB Output is correct
8 Correct 58 ms 18000 KB Output is correct
9 Correct 66 ms 18404 KB Output is correct
10 Correct 73 ms 17748 KB Output is correct
11 Correct 472 ms 67280 KB Output is correct
12 Correct 434 ms 63060 KB Output is correct
13 Correct 427 ms 63052 KB Output is correct
14 Correct 474 ms 67364 KB Output is correct
15 Correct 467 ms 65740 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 51 ms 18516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2140 KB Output is correct
2 Correct 16 ms 2140 KB Output is correct
3 Correct 15 ms 2140 KB Output is correct
4 Correct 16 ms 2140 KB Output is correct
5 Correct 16 ms 2140 KB Output is correct
6 Correct 8 ms 860 KB Output is correct
7 Correct 8 ms 856 KB Output is correct
8 Correct 10 ms 856 KB Output is correct
9 Correct 9 ms 860 KB Output is correct
10 Correct 9 ms 980 KB Output is correct
11 Correct 13 ms 2136 KB Output is correct
12 Correct 12 ms 2136 KB Output is correct
13 Correct 12 ms 2140 KB Output is correct
14 Correct 13 ms 2136 KB Output is correct
15 Correct 13 ms 2392 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 8 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2140 KB Output is correct
2 Correct 16 ms 2140 KB Output is correct
3 Correct 15 ms 2140 KB Output is correct
4 Correct 16 ms 2140 KB Output is correct
5 Correct 16 ms 2140 KB Output is correct
6 Correct 8 ms 860 KB Output is correct
7 Correct 8 ms 856 KB Output is correct
8 Correct 10 ms 856 KB Output is correct
9 Correct 9 ms 860 KB Output is correct
10 Correct 9 ms 980 KB Output is correct
11 Correct 13 ms 2136 KB Output is correct
12 Correct 12 ms 2136 KB Output is correct
13 Correct 12 ms 2140 KB Output is correct
14 Correct 13 ms 2136 KB Output is correct
15 Correct 13 ms 2392 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 8 ms 860 KB Output is correct
18 Correct 309 ms 4180 KB Output is correct
19 Correct 254 ms 4088 KB Output is correct
20 Correct 281 ms 4176 KB Output is correct
21 Correct 252 ms 3924 KB Output is correct
22 Correct 262 ms 4076 KB Output is correct
23 Correct 243 ms 2900 KB Output is correct
24 Correct 263 ms 2716 KB Output is correct
25 Correct 263 ms 2788 KB Output is correct
26 Correct 262 ms 2872 KB Output is correct
27 Correct 242 ms 2732 KB Output is correct
28 Correct 237 ms 3408 KB Output is correct
29 Correct 269 ms 3520 KB Output is correct
30 Correct 249 ms 3668 KB Output is correct
31 Correct 260 ms 3596 KB Output is correct
32 Correct 241 ms 3648 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 255 ms 3100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 811 ms 69204 KB Output is correct
2 Correct 843 ms 67824 KB Output is correct
3 Correct 736 ms 63336 KB Output is correct
4 Correct 693 ms 62612 KB Output is correct
5 Correct 774 ms 64600 KB Output is correct
6 Correct 48 ms 17748 KB Output is correct
7 Correct 56 ms 17732 KB Output is correct
8 Correct 68 ms 17748 KB Output is correct
9 Correct 59 ms 17340 KB Output is correct
10 Correct 72 ms 18680 KB Output is correct
11 Correct 456 ms 62728 KB Output is correct
12 Correct 562 ms 68692 KB Output is correct
13 Correct 509 ms 62548 KB Output is correct
14 Correct 504 ms 64848 KB Output is correct
15 Correct 507 ms 68468 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 57 ms 17748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 747 ms 66132 KB Output is correct
2 Correct 754 ms 65280 KB Output is correct
3 Correct 760 ms 65620 KB Output is correct
4 Correct 750 ms 66284 KB Output is correct
5 Correct 790 ms 68952 KB Output is correct
6 Correct 49 ms 17604 KB Output is correct
7 Correct 53 ms 17744 KB Output is correct
8 Correct 58 ms 18000 KB Output is correct
9 Correct 66 ms 18404 KB Output is correct
10 Correct 73 ms 17748 KB Output is correct
11 Correct 472 ms 67280 KB Output is correct
12 Correct 434 ms 63060 KB Output is correct
13 Correct 427 ms 63052 KB Output is correct
14 Correct 474 ms 67364 KB Output is correct
15 Correct 467 ms 65740 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 51 ms 18516 KB Output is correct
18 Correct 16 ms 2140 KB Output is correct
19 Correct 16 ms 2140 KB Output is correct
20 Correct 15 ms 2140 KB Output is correct
21 Correct 16 ms 2140 KB Output is correct
22 Correct 16 ms 2140 KB Output is correct
23 Correct 8 ms 860 KB Output is correct
24 Correct 8 ms 856 KB Output is correct
25 Correct 10 ms 856 KB Output is correct
26 Correct 9 ms 860 KB Output is correct
27 Correct 9 ms 980 KB Output is correct
28 Correct 13 ms 2136 KB Output is correct
29 Correct 12 ms 2136 KB Output is correct
30 Correct 12 ms 2140 KB Output is correct
31 Correct 13 ms 2136 KB Output is correct
32 Correct 13 ms 2392 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 8 ms 860 KB Output is correct
35 Correct 309 ms 4180 KB Output is correct
36 Correct 254 ms 4088 KB Output is correct
37 Correct 281 ms 4176 KB Output is correct
38 Correct 252 ms 3924 KB Output is correct
39 Correct 262 ms 4076 KB Output is correct
40 Correct 243 ms 2900 KB Output is correct
41 Correct 263 ms 2716 KB Output is correct
42 Correct 263 ms 2788 KB Output is correct
43 Correct 262 ms 2872 KB Output is correct
44 Correct 242 ms 2732 KB Output is correct
45 Correct 237 ms 3408 KB Output is correct
46 Correct 269 ms 3520 KB Output is correct
47 Correct 249 ms 3668 KB Output is correct
48 Correct 260 ms 3596 KB Output is correct
49 Correct 241 ms 3648 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 255 ms 3100 KB Output is correct
52 Correct 811 ms 69204 KB Output is correct
53 Correct 843 ms 67824 KB Output is correct
54 Correct 736 ms 63336 KB Output is correct
55 Correct 693 ms 62612 KB Output is correct
56 Correct 774 ms 64600 KB Output is correct
57 Correct 48 ms 17748 KB Output is correct
58 Correct 56 ms 17732 KB Output is correct
59 Correct 68 ms 17748 KB Output is correct
60 Correct 59 ms 17340 KB Output is correct
61 Correct 72 ms 18680 KB Output is correct
62 Correct 456 ms 62728 KB Output is correct
63 Correct 562 ms 68692 KB Output is correct
64 Correct 509 ms 62548 KB Output is correct
65 Correct 504 ms 64848 KB Output is correct
66 Correct 507 ms 68468 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 57 ms 17748 KB Output is correct
69 Execution timed out 1037 ms 66972 KB Time limit exceeded
70 Halted 0 ms 0 KB -