Submission #720677

# Submission time Handle Problem Language Result Execution time Memory
720677 2023-04-08T23:32:56 Z Yell0 Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
318 ms 32852 KB
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> pii;
const int MN=4e5+5,LOG=20;
int N,Q,st[LOG][MN];
pii a[MN];
set<pii> s;

bool chk(int i) {
    if(s.empty()) return 1;
    auto nxt=s.lower_bound(a[i]);
    if(a[i].f<=nxt->f&&nxt->f<=a[i].s) return 0;
    if(nxt!=s.begin()) {
        nxt--;
        if(nxt->f<=a[i].f&&a[i].f<=nxt->s) return 0;
    }
    return 1;
}

int main() {
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>N;
    for(int i=1;i<=N;i++) cin>>a[i].f>>a[i].s;
    for(int l=1,r=1;l<=N;l++) {
        while(r<=N&&chk(r)) {s.insert(a[r]);r++;}
        st[0][l]=r;
        s.erase(a[l]);
    }
    st[0][N+1]=N+1;
    for(int k=1;k<LOG;k++)
        for(int i=1;i<=N+1;i++) {
            st[k][i]=st[k-1][st[k-1][i]];
        }
    cin>>Q;
    int p,q;
    while(Q--) {
        cin>>p>>q;
        int ans=1;
        for(int k=LOG-1;k>=0;k--)
            if(st[k][p]&&st[k][p]<=q) {
                p=st[k][p];
                ans+=1<<k;
            }
        cout<<ans<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 54 ms 20556 KB Output is correct
2 Correct 54 ms 20272 KB Output is correct
3 Correct 64 ms 20300 KB Output is correct
4 Correct 59 ms 20556 KB Output is correct
5 Correct 80 ms 21436 KB Output is correct
6 Correct 54 ms 19516 KB Output is correct
7 Correct 59 ms 20016 KB Output is correct
8 Correct 57 ms 19916 KB Output is correct
9 Correct 64 ms 20436 KB Output is correct
10 Correct 72 ms 19648 KB Output is correct
11 Correct 198 ms 29584 KB Output is correct
12 Correct 191 ms 27828 KB Output is correct
13 Correct 192 ms 27724 KB Output is correct
14 Correct 164 ms 25628 KB Output is correct
15 Correct 170 ms 23860 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 58 ms 20864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 980 KB Output is correct
2 Correct 4 ms 980 KB Output is correct
3 Correct 4 ms 980 KB Output is correct
4 Correct 4 ms 1044 KB Output is correct
5 Correct 4 ms 980 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 4 ms 956 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 4 ms 980 KB Output is correct
10 Correct 4 ms 980 KB Output is correct
11 Correct 6 ms 1252 KB Output is correct
12 Correct 5 ms 1200 KB Output is correct
13 Correct 5 ms 1108 KB Output is correct
14 Correct 5 ms 1084 KB Output is correct
15 Correct 5 ms 1084 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 3 ms 988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 980 KB Output is correct
2 Correct 4 ms 980 KB Output is correct
3 Correct 4 ms 980 KB Output is correct
4 Correct 4 ms 1044 KB Output is correct
5 Correct 4 ms 980 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 4 ms 956 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 4 ms 980 KB Output is correct
10 Correct 4 ms 980 KB Output is correct
11 Correct 6 ms 1252 KB Output is correct
12 Correct 5 ms 1200 KB Output is correct
13 Correct 5 ms 1108 KB Output is correct
14 Correct 5 ms 1084 KB Output is correct
15 Correct 5 ms 1084 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 3 ms 988 KB Output is correct
18 Correct 79 ms 3788 KB Output is correct
19 Correct 69 ms 3400 KB Output is correct
20 Correct 82 ms 3644 KB Output is correct
21 Correct 62 ms 3404 KB Output is correct
22 Correct 79 ms 3516 KB Output is correct
23 Correct 66 ms 3404 KB Output is correct
24 Correct 75 ms 3728 KB Output is correct
25 Correct 75 ms 3592 KB Output is correct
26 Correct 69 ms 3556 KB Output is correct
27 Correct 70 ms 3388 KB Output is correct
28 Correct 57 ms 3244 KB Output is correct
29 Correct 59 ms 3276 KB Output is correct
30 Correct 51 ms 3276 KB Output is correct
31 Correct 52 ms 3140 KB Output is correct
32 Correct 51 ms 3188 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 62 ms 3344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 21476 KB Output is correct
2 Correct 66 ms 21040 KB Output is correct
3 Correct 58 ms 19632 KB Output is correct
4 Correct 64 ms 19360 KB Output is correct
5 Correct 70 ms 20044 KB Output is correct
6 Correct 58 ms 19612 KB Output is correct
7 Correct 53 ms 19500 KB Output is correct
8 Correct 54 ms 19680 KB Output is correct
9 Correct 75 ms 19492 KB Output is correct
10 Correct 74 ms 20936 KB Output is correct
11 Correct 162 ms 27632 KB Output is correct
12 Correct 201 ms 30284 KB Output is correct
13 Correct 182 ms 27588 KB Output is correct
14 Correct 153 ms 23856 KB Output is correct
15 Correct 189 ms 26000 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 54 ms 19968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 20556 KB Output is correct
2 Correct 54 ms 20272 KB Output is correct
3 Correct 64 ms 20300 KB Output is correct
4 Correct 59 ms 20556 KB Output is correct
5 Correct 80 ms 21436 KB Output is correct
6 Correct 54 ms 19516 KB Output is correct
7 Correct 59 ms 20016 KB Output is correct
8 Correct 57 ms 19916 KB Output is correct
9 Correct 64 ms 20436 KB Output is correct
10 Correct 72 ms 19648 KB Output is correct
11 Correct 198 ms 29584 KB Output is correct
12 Correct 191 ms 27828 KB Output is correct
13 Correct 192 ms 27724 KB Output is correct
14 Correct 164 ms 25628 KB Output is correct
15 Correct 170 ms 23860 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 58 ms 20864 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 4 ms 980 KB Output is correct
21 Correct 4 ms 1044 KB Output is correct
22 Correct 4 ms 980 KB Output is correct
23 Correct 5 ms 1108 KB Output is correct
24 Correct 4 ms 956 KB Output is correct
25 Correct 4 ms 980 KB Output is correct
26 Correct 4 ms 980 KB Output is correct
27 Correct 4 ms 980 KB Output is correct
28 Correct 6 ms 1252 KB Output is correct
29 Correct 5 ms 1200 KB Output is correct
30 Correct 5 ms 1108 KB Output is correct
31 Correct 5 ms 1084 KB Output is correct
32 Correct 5 ms 1084 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 3 ms 988 KB Output is correct
35 Correct 79 ms 3788 KB Output is correct
36 Correct 69 ms 3400 KB Output is correct
37 Correct 82 ms 3644 KB Output is correct
38 Correct 62 ms 3404 KB Output is correct
39 Correct 79 ms 3516 KB Output is correct
40 Correct 66 ms 3404 KB Output is correct
41 Correct 75 ms 3728 KB Output is correct
42 Correct 75 ms 3592 KB Output is correct
43 Correct 69 ms 3556 KB Output is correct
44 Correct 70 ms 3388 KB Output is correct
45 Correct 57 ms 3244 KB Output is correct
46 Correct 59 ms 3276 KB Output is correct
47 Correct 51 ms 3276 KB Output is correct
48 Correct 52 ms 3140 KB Output is correct
49 Correct 51 ms 3188 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 62 ms 3344 KB Output is correct
52 Correct 73 ms 21476 KB Output is correct
53 Correct 66 ms 21040 KB Output is correct
54 Correct 58 ms 19632 KB Output is correct
55 Correct 64 ms 19360 KB Output is correct
56 Correct 70 ms 20044 KB Output is correct
57 Correct 58 ms 19612 KB Output is correct
58 Correct 53 ms 19500 KB Output is correct
59 Correct 54 ms 19680 KB Output is correct
60 Correct 75 ms 19492 KB Output is correct
61 Correct 74 ms 20936 KB Output is correct
62 Correct 162 ms 27632 KB Output is correct
63 Correct 201 ms 30284 KB Output is correct
64 Correct 182 ms 27588 KB Output is correct
65 Correct 153 ms 23856 KB Output is correct
66 Correct 189 ms 26000 KB Output is correct
67 Correct 0 ms 468 KB Output is correct
68 Correct 54 ms 19968 KB Output is correct
69 Correct 255 ms 23500 KB Output is correct
70 Correct 280 ms 24672 KB Output is correct
71 Correct 280 ms 22868 KB Output is correct
72 Correct 244 ms 23884 KB Output is correct
73 Correct 284 ms 23648 KB Output is correct
74 Correct 284 ms 24912 KB Output is correct
75 Correct 242 ms 23276 KB Output is correct
76 Correct 297 ms 24884 KB Output is correct
77 Correct 287 ms 23016 KB Output is correct
78 Correct 297 ms 23500 KB Output is correct
79 Correct 318 ms 32852 KB Output is correct
80 Correct 270 ms 30552 KB Output is correct
81 Correct 278 ms 30444 KB Output is correct
82 Correct 250 ms 27292 KB Output is correct
83 Correct 234 ms 26004 KB Output is correct
84 Correct 1 ms 468 KB Output is correct
85 Correct 113 ms 23132 KB Output is correct