답안 #1028922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028922 2024-07-20T10:21:33 Z vjudge1 Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
538 ms 31272 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
int const N=2e5+5;
int const mod=1e9+7;

set<pair<int,int>> st;
pair<int,int> a[N];
int par[N][18];

bool check(int i){
    if(st.find(a[i])!=st.end())
        return 0;
    st.insert(a[i]);
    auto p=st.lower_bound(a[i]);
    p++;
    bool ok=1;
    if(p!=st.end()){
        auto nxt=*p;
        if(nxt.first<=a[i].second)
            ok=0;
    }
    p--;
    if(p!=st.begin()){
        p--;
        auto nxt=*p;
        if(nxt.second>=a[i].first)
            ok=0;
    }
    if(ok==0)
        st.erase(a[i]);
    return ok;
}

int main(){
    int n;
    cin>>n;
    for (int i = 1; i <=n; ++i)
        cin>>a[i].first>>a[i].second;
    int j=1;
    for(int i=1;i<=n;i++){
        while(j<=n and check(j))
            j++;
        par[i][0]=j;
        // cout<<j<<' ';
        st.erase(a[i]);
    }
    // cout<<endl;
    par[n+1][0]=n+1;
    for(int p=1;p<18;p++)
        for(int i=1;i<=n+1;i++)
            par[i][p]=par[par[i][p-1]][p-1];
    int q;
    cin>>q;
    while(q--){
        int u,v;
        cin>>u>>v;
        int ans=0;
        for(int p=17;p>=0;p--){
            // cout<<u<<' ';
            if(par[u][p]<=v){
                u=par[u][p];
                ans+=(1<<p);
            }
        }
        // cout<<endl;
        cout<<ans+1<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 19616 KB Output is correct
2 Correct 121 ms 19628 KB Output is correct
3 Correct 133 ms 19556 KB Output is correct
4 Correct 125 ms 19620 KB Output is correct
5 Correct 130 ms 19900 KB Output is correct
6 Correct 111 ms 19308 KB Output is correct
7 Correct 125 ms 19364 KB Output is correct
8 Correct 131 ms 19480 KB Output is correct
9 Correct 115 ms 19452 KB Output is correct
10 Correct 115 ms 19284 KB Output is correct
11 Correct 235 ms 28224 KB Output is correct
12 Correct 244 ms 27472 KB Output is correct
13 Correct 223 ms 26192 KB Output is correct
14 Correct 235 ms 24044 KB Output is correct
15 Correct 224 ms 22916 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 118 ms 19284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 820 KB Output is correct
2 Correct 10 ms 860 KB Output is correct
3 Correct 9 ms 964 KB Output is correct
4 Correct 9 ms 2908 KB Output is correct
5 Correct 9 ms 860 KB Output is correct
6 Correct 9 ms 824 KB Output is correct
7 Correct 12 ms 2868 KB Output is correct
8 Correct 9 ms 860 KB Output is correct
9 Correct 11 ms 856 KB Output is correct
10 Correct 12 ms 856 KB Output is correct
11 Correct 8 ms 976 KB Output is correct
12 Correct 11 ms 1116 KB Output is correct
13 Correct 13 ms 1156 KB Output is correct
14 Correct 15 ms 1048 KB Output is correct
15 Correct 12 ms 1032 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 10 ms 1120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 820 KB Output is correct
2 Correct 10 ms 860 KB Output is correct
3 Correct 9 ms 964 KB Output is correct
4 Correct 9 ms 2908 KB Output is correct
5 Correct 9 ms 860 KB Output is correct
6 Correct 9 ms 824 KB Output is correct
7 Correct 12 ms 2868 KB Output is correct
8 Correct 9 ms 860 KB Output is correct
9 Correct 11 ms 856 KB Output is correct
10 Correct 12 ms 856 KB Output is correct
11 Correct 8 ms 976 KB Output is correct
12 Correct 11 ms 1116 KB Output is correct
13 Correct 13 ms 1156 KB Output is correct
14 Correct 15 ms 1048 KB Output is correct
15 Correct 12 ms 1032 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 10 ms 1120 KB Output is correct
18 Correct 273 ms 5420 KB Output is correct
19 Correct 262 ms 3156 KB Output is correct
20 Correct 304 ms 3632 KB Output is correct
21 Correct 254 ms 3412 KB Output is correct
22 Correct 275 ms 3412 KB Output is correct
23 Correct 242 ms 3412 KB Output is correct
24 Correct 251 ms 3408 KB Output is correct
25 Correct 247 ms 3408 KB Output is correct
26 Correct 232 ms 3364 KB Output is correct
27 Correct 260 ms 3232 KB Output is correct
28 Correct 213 ms 3152 KB Output is correct
29 Correct 232 ms 3204 KB Output is correct
30 Correct 224 ms 5204 KB Output is correct
31 Correct 215 ms 2900 KB Output is correct
32 Correct 219 ms 3148 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 231 ms 5272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 19824 KB Output is correct
2 Correct 103 ms 19280 KB Output is correct
3 Correct 93 ms 19480 KB Output is correct
4 Correct 94 ms 19284 KB Output is correct
5 Correct 105 ms 19536 KB Output is correct
6 Correct 94 ms 19368 KB Output is correct
7 Correct 110 ms 19356 KB Output is correct
8 Correct 100 ms 19280 KB Output is correct
9 Correct 100 ms 19280 KB Output is correct
10 Correct 114 ms 19648 KB Output is correct
11 Correct 225 ms 27324 KB Output is correct
12 Correct 231 ms 28500 KB Output is correct
13 Correct 197 ms 27220 KB Output is correct
14 Correct 237 ms 23124 KB Output is correct
15 Correct 231 ms 24404 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 103 ms 18420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 19616 KB Output is correct
2 Correct 121 ms 19628 KB Output is correct
3 Correct 133 ms 19556 KB Output is correct
4 Correct 125 ms 19620 KB Output is correct
5 Correct 130 ms 19900 KB Output is correct
6 Correct 111 ms 19308 KB Output is correct
7 Correct 125 ms 19364 KB Output is correct
8 Correct 131 ms 19480 KB Output is correct
9 Correct 115 ms 19452 KB Output is correct
10 Correct 115 ms 19284 KB Output is correct
11 Correct 235 ms 28224 KB Output is correct
12 Correct 244 ms 27472 KB Output is correct
13 Correct 223 ms 26192 KB Output is correct
14 Correct 235 ms 24044 KB Output is correct
15 Correct 224 ms 22916 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 118 ms 19284 KB Output is correct
18 Correct 10 ms 820 KB Output is correct
19 Correct 10 ms 860 KB Output is correct
20 Correct 9 ms 964 KB Output is correct
21 Correct 9 ms 2908 KB Output is correct
22 Correct 9 ms 860 KB Output is correct
23 Correct 9 ms 824 KB Output is correct
24 Correct 12 ms 2868 KB Output is correct
25 Correct 9 ms 860 KB Output is correct
26 Correct 11 ms 856 KB Output is correct
27 Correct 12 ms 856 KB Output is correct
28 Correct 8 ms 976 KB Output is correct
29 Correct 11 ms 1116 KB Output is correct
30 Correct 13 ms 1156 KB Output is correct
31 Correct 15 ms 1048 KB Output is correct
32 Correct 12 ms 1032 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 10 ms 1120 KB Output is correct
35 Correct 273 ms 5420 KB Output is correct
36 Correct 262 ms 3156 KB Output is correct
37 Correct 304 ms 3632 KB Output is correct
38 Correct 254 ms 3412 KB Output is correct
39 Correct 275 ms 3412 KB Output is correct
40 Correct 242 ms 3412 KB Output is correct
41 Correct 251 ms 3408 KB Output is correct
42 Correct 247 ms 3408 KB Output is correct
43 Correct 232 ms 3364 KB Output is correct
44 Correct 260 ms 3232 KB Output is correct
45 Correct 213 ms 3152 KB Output is correct
46 Correct 232 ms 3204 KB Output is correct
47 Correct 224 ms 5204 KB Output is correct
48 Correct 215 ms 2900 KB Output is correct
49 Correct 219 ms 3148 KB Output is correct
50 Correct 0 ms 2396 KB Output is correct
51 Correct 231 ms 5272 KB Output is correct
52 Correct 105 ms 19824 KB Output is correct
53 Correct 103 ms 19280 KB Output is correct
54 Correct 93 ms 19480 KB Output is correct
55 Correct 94 ms 19284 KB Output is correct
56 Correct 105 ms 19536 KB Output is correct
57 Correct 94 ms 19368 KB Output is correct
58 Correct 110 ms 19356 KB Output is correct
59 Correct 100 ms 19280 KB Output is correct
60 Correct 100 ms 19280 KB Output is correct
61 Correct 114 ms 19648 KB Output is correct
62 Correct 225 ms 27324 KB Output is correct
63 Correct 231 ms 28500 KB Output is correct
64 Correct 197 ms 27220 KB Output is correct
65 Correct 237 ms 23124 KB Output is correct
66 Correct 231 ms 24404 KB Output is correct
67 Correct 0 ms 2396 KB Output is correct
68 Correct 103 ms 18420 KB Output is correct
69 Correct 468 ms 22084 KB Output is correct
70 Correct 494 ms 23124 KB Output is correct
71 Correct 509 ms 22612 KB Output is correct
72 Correct 526 ms 22860 KB Output is correct
73 Correct 502 ms 23072 KB Output is correct
74 Correct 538 ms 23380 KB Output is correct
75 Correct 494 ms 23080 KB Output is correct
76 Correct 475 ms 23328 KB Output is correct
77 Correct 420 ms 22672 KB Output is correct
78 Correct 419 ms 23064 KB Output is correct
79 Correct 448 ms 31272 KB Output is correct
80 Correct 415 ms 30292 KB Output is correct
81 Correct 438 ms 30108 KB Output is correct
82 Correct 486 ms 25940 KB Output is correct
83 Correct 431 ms 25564 KB Output is correct
84 Correct 0 ms 2392 KB Output is correct
85 Correct 342 ms 21588 KB Output is correct