Submission #915438

# Submission time Handle Problem Language Result Execution time Memory
915438 2024-01-23T22:50:58 Z SalihSahin Osumnjičeni (COCI21_osumnjiceni) C++14
60 / 110
1000 ms 71764 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){
        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(){
    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);
    vector<int> go(n);
    bool inc, flag = 1;
    int r = 0;
    for(int l = 0; l < n; l++){
        inc = 0;
        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);
            inc = 1;
            r++;
        }

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

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

    vector<vector<int> > lift(K, vector<int>(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;
    cin>>q;
    while(q--){
        int l, r;
        cin>>l>>r;
        int ans = 1;
        l--, r--;
        
        for(int i = K-1; i >= 0; i--){
            if(lift[i][l] <= r){
                l = lift[i][l];
                ans += (1 << i);
            }
        }

        cout<<ans<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 882 ms 68516 KB Output is correct
2 Correct 829 ms 67256 KB Output is correct
3 Correct 826 ms 67392 KB Output is correct
4 Correct 824 ms 68504 KB Output is correct
5 Correct 889 ms 71300 KB Output is correct
6 Correct 138 ms 19536 KB Output is correct
7 Correct 143 ms 19636 KB Output is correct
8 Correct 145 ms 20044 KB Output is correct
9 Correct 157 ms 20336 KB Output is correct
10 Correct 161 ms 19792 KB Output is correct
11 Correct 570 ms 69200 KB Output is correct
12 Correct 537 ms 65284 KB Output is correct
13 Correct 562 ms 65012 KB Output is correct
14 Correct 581 ms 69456 KB Output is correct
15 Correct 516 ms 67540 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 147 ms 20616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2136 KB Output is correct
2 Correct 20 ms 2140 KB Output is correct
3 Correct 19 ms 2136 KB Output is correct
4 Correct 20 ms 2136 KB Output is correct
5 Correct 26 ms 1884 KB Output is correct
6 Correct 12 ms 860 KB Output is correct
7 Correct 12 ms 972 KB Output is correct
8 Correct 12 ms 1112 KB Output is correct
9 Correct 14 ms 860 KB Output is correct
10 Correct 12 ms 856 KB Output is correct
11 Correct 16 ms 2116 KB Output is correct
12 Correct 15 ms 1884 KB Output is correct
13 Correct 15 ms 2148 KB Output is correct
14 Correct 16 ms 2140 KB Output is correct
15 Correct 23 ms 2136 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 12 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2136 KB Output is correct
2 Correct 20 ms 2140 KB Output is correct
3 Correct 19 ms 2136 KB Output is correct
4 Correct 20 ms 2136 KB Output is correct
5 Correct 26 ms 1884 KB Output is correct
6 Correct 12 ms 860 KB Output is correct
7 Correct 12 ms 972 KB Output is correct
8 Correct 12 ms 1112 KB Output is correct
9 Correct 14 ms 860 KB Output is correct
10 Correct 12 ms 856 KB Output is correct
11 Correct 16 ms 2116 KB Output is correct
12 Correct 15 ms 1884 KB Output is correct
13 Correct 15 ms 2148 KB Output is correct
14 Correct 16 ms 2140 KB Output is correct
15 Correct 23 ms 2136 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 12 ms 860 KB Output is correct
18 Correct 349 ms 4764 KB Output is correct
19 Correct 322 ms 4596 KB Output is correct
20 Correct 341 ms 4688 KB Output is correct
21 Correct 315 ms 4732 KB Output is correct
22 Correct 325 ms 4580 KB Output is correct
23 Correct 308 ms 3412 KB Output is correct
24 Correct 320 ms 3484 KB Output is correct
25 Correct 335 ms 3732 KB Output is correct
26 Correct 321 ms 3408 KB Output is correct
27 Correct 313 ms 3412 KB Output is correct
28 Correct 302 ms 3940 KB Output is correct
29 Correct 313 ms 4180 KB Output is correct
30 Correct 312 ms 4208 KB Output is correct
31 Correct 306 ms 3920 KB Output is correct
32 Correct 304 ms 4180 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 309 ms 3296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 936 ms 71764 KB Output is correct
2 Correct 947 ms 70144 KB Output is correct
3 Correct 831 ms 65336 KB Output is correct
4 Correct 822 ms 64548 KB Output is correct
5 Correct 871 ms 66640 KB Output is correct
6 Correct 139 ms 19628 KB Output is correct
7 Correct 146 ms 19508 KB Output is correct
8 Correct 142 ms 19536 KB Output is correct
9 Correct 153 ms 19372 KB Output is correct
10 Correct 166 ms 20820 KB Output is correct
11 Correct 583 ms 64596 KB Output is correct
12 Correct 622 ms 70484 KB Output is correct
13 Correct 550 ms 61524 KB Output is correct
14 Correct 577 ms 63264 KB Output is correct
15 Correct 610 ms 67316 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 140 ms 16208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 882 ms 68516 KB Output is correct
2 Correct 829 ms 67256 KB Output is correct
3 Correct 826 ms 67392 KB Output is correct
4 Correct 824 ms 68504 KB Output is correct
5 Correct 889 ms 71300 KB Output is correct
6 Correct 138 ms 19536 KB Output is correct
7 Correct 143 ms 19636 KB Output is correct
8 Correct 145 ms 20044 KB Output is correct
9 Correct 157 ms 20336 KB Output is correct
10 Correct 161 ms 19792 KB Output is correct
11 Correct 570 ms 69200 KB Output is correct
12 Correct 537 ms 65284 KB Output is correct
13 Correct 562 ms 65012 KB Output is correct
14 Correct 581 ms 69456 KB Output is correct
15 Correct 516 ms 67540 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 147 ms 20616 KB Output is correct
18 Correct 20 ms 2136 KB Output is correct
19 Correct 20 ms 2140 KB Output is correct
20 Correct 19 ms 2136 KB Output is correct
21 Correct 20 ms 2136 KB Output is correct
22 Correct 26 ms 1884 KB Output is correct
23 Correct 12 ms 860 KB Output is correct
24 Correct 12 ms 972 KB Output is correct
25 Correct 12 ms 1112 KB Output is correct
26 Correct 14 ms 860 KB Output is correct
27 Correct 12 ms 856 KB Output is correct
28 Correct 16 ms 2116 KB Output is correct
29 Correct 15 ms 1884 KB Output is correct
30 Correct 15 ms 2148 KB Output is correct
31 Correct 16 ms 2140 KB Output is correct
32 Correct 23 ms 2136 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 12 ms 860 KB Output is correct
35 Correct 349 ms 4764 KB Output is correct
36 Correct 322 ms 4596 KB Output is correct
37 Correct 341 ms 4688 KB Output is correct
38 Correct 315 ms 4732 KB Output is correct
39 Correct 325 ms 4580 KB Output is correct
40 Correct 308 ms 3412 KB Output is correct
41 Correct 320 ms 3484 KB Output is correct
42 Correct 335 ms 3732 KB Output is correct
43 Correct 321 ms 3408 KB Output is correct
44 Correct 313 ms 3412 KB Output is correct
45 Correct 302 ms 3940 KB Output is correct
46 Correct 313 ms 4180 KB Output is correct
47 Correct 312 ms 4208 KB Output is correct
48 Correct 306 ms 3920 KB Output is correct
49 Correct 304 ms 4180 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 309 ms 3296 KB Output is correct
52 Correct 936 ms 71764 KB Output is correct
53 Correct 947 ms 70144 KB Output is correct
54 Correct 831 ms 65336 KB Output is correct
55 Correct 822 ms 64548 KB Output is correct
56 Correct 871 ms 66640 KB Output is correct
57 Correct 139 ms 19628 KB Output is correct
58 Correct 146 ms 19508 KB Output is correct
59 Correct 142 ms 19536 KB Output is correct
60 Correct 153 ms 19372 KB Output is correct
61 Correct 166 ms 20820 KB Output is correct
62 Correct 583 ms 64596 KB Output is correct
63 Correct 622 ms 70484 KB Output is correct
64 Correct 550 ms 61524 KB Output is correct
65 Correct 577 ms 63264 KB Output is correct
66 Correct 610 ms 67316 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 140 ms 16208 KB Output is correct
69 Execution timed out 1055 ms 63716 KB Time limit exceeded
70 Halted 0 ms 0 KB -