답안 #603239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603239 2022-07-23T17:57:48 Z peuch Event Hopping (BOI22_events) C++17
100 / 100
254 ms 16672 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 10;
const int MAXK = 22;

int n, q;

struct interval{
    int l, r, id;
    interval (int _l = 0, int _r = 0){
        l = _l;
        r = _r;
        id = 0;
    }
    void scan(int _id){
        scanf("%d %d", &l, &r);
        id = _id;
    }
    bool operator < (interval x){
        if(r == x.r) return l < x.l;
        return r < x.r;
    }
}v[MAXN], ori[MAXN];

int dp[MAXN][MAXK];

int getDP(int i, int j){
    if(dp[i][j] != 0) return dp[i][j];
    return dp[i][j] = getDP(getDP(i, j - 1), j - 1);
}

int main(){
    scanf("%d %d", &n, &q);
    for(int i = 1; i <= n; i++){
        v[i].scan(i);
        ori[i] = v[i];
    }

    sort(v + 1, v + 1 + n);

    vector<interval > pilha;
    for(int i = 1; i <= n; i++){
        while(!pilha.empty() && pilha.back().l >= v[i].l)
            pilha.pop_back();
        pilha.push_back(v[i]);
        int k = lower_bound(pilha.begin(), pilha.end(), interval(-1, v[i].l)) - pilha.begin();
        dp[v[i].id][0] = pilha[k].id;
    }

    for(int i = 1; i <= q; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        if(a == b){
            printf("0\n");
            continue;
        }
        if(ori[b].r < ori[a].r){
            printf("impossible\n");
            continue;
        }
        if(ori[a].r >= ori[b].l && ori[a].r <= ori[b].r){
            printf("1\n");
            continue;
        }
        int ans = 0;
        for(int k = MAXK - 1; k >= 0; k--){
            int viz = getDP(b, k);
            if(ori[viz].l <= ori[a].r) continue;
            b = viz;
            ans += (1 << k);
        }
        if(getDP(b, 0) == b){
            printf("impossible\n");
            continue;
        }
        ans += 2;
        printf("%d\n", ans);
    }
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
events.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
events.cpp: In member function 'void interval::scan(int)':
events.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%d %d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~
events.cpp: In function 'int main()':
events.cpp:29:15: warning: array subscript -1 is below array bounds of 'int [22]' [-Warray-bounds]
   29 |     if(dp[i][j] != 0) return dp[i][j];
      |        ~~~~~~~^
events.cpp:30:19: warning: array subscript -1 is below array bounds of 'int [22]' [-Warray-bounds]
   30 |     return dp[i][j] = getDP(getDP(i, j - 1), j - 1);
      |            ~~~~~~~^
events.cpp:29:15: warning: array subscript -1 is below array bounds of 'int [22]' [-Warray-bounds]
   29 |     if(dp[i][j] != 0) return dp[i][j];
      |        ~~~~~~~^
events.cpp:30:19: warning: array subscript -1 is below array bounds of 'int [22]' [-Warray-bounds]
   30 |     return dp[i][j] = getDP(getDP(i, j - 1), j - 1);
      |            ~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 76 ms 13124 KB Output is correct
3 Correct 170 ms 13116 KB Output is correct
4 Correct 207 ms 13072 KB Output is correct
5 Correct 143 ms 13588 KB Output is correct
6 Correct 150 ms 13292 KB Output is correct
7 Correct 148 ms 13244 KB Output is correct
8 Correct 81 ms 13896 KB Output is correct
9 Correct 77 ms 13816 KB Output is correct
10 Correct 200 ms 13676 KB Output is correct
11 Correct 120 ms 13264 KB Output is correct
12 Correct 58 ms 13124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2664 KB Output is correct
13 Correct 2 ms 2664 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 2 ms 2772 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 47 ms 4480 KB Output is correct
20 Correct 45 ms 4708 KB Output is correct
21 Correct 42 ms 4976 KB Output is correct
22 Correct 32 ms 4812 KB Output is correct
23 Correct 28 ms 4676 KB Output is correct
24 Correct 29 ms 4776 KB Output is correct
25 Correct 44 ms 4532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2760 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2772 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 86 ms 13116 KB Output is correct
20 Correct 83 ms 13224 KB Output is correct
21 Correct 39 ms 12360 KB Output is correct
22 Correct 44 ms 13280 KB Output is correct
23 Correct 40 ms 14488 KB Output is correct
24 Correct 47 ms 14500 KB Output is correct
25 Correct 25 ms 12420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 13124 KB Output is correct
2 Correct 146 ms 13088 KB Output is correct
3 Correct 237 ms 13052 KB Output is correct
4 Correct 74 ms 14136 KB Output is correct
5 Correct 198 ms 14024 KB Output is correct
6 Correct 159 ms 14776 KB Output is correct
7 Correct 153 ms 16128 KB Output is correct
8 Correct 94 ms 16300 KB Output is correct
9 Correct 37 ms 14792 KB Output is correct
10 Correct 97 ms 15864 KB Output is correct
11 Correct 81 ms 15692 KB Output is correct
12 Correct 116 ms 15808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 76 ms 13124 KB Output is correct
3 Correct 170 ms 13116 KB Output is correct
4 Correct 207 ms 13072 KB Output is correct
5 Correct 143 ms 13588 KB Output is correct
6 Correct 150 ms 13292 KB Output is correct
7 Correct 148 ms 13244 KB Output is correct
8 Correct 81 ms 13896 KB Output is correct
9 Correct 77 ms 13816 KB Output is correct
10 Correct 200 ms 13676 KB Output is correct
11 Correct 120 ms 13264 KB Output is correct
12 Correct 58 ms 13124 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2664 KB Output is correct
25 Correct 2 ms 2664 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 3 ms 2644 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 47 ms 4480 KB Output is correct
32 Correct 45 ms 4708 KB Output is correct
33 Correct 42 ms 4976 KB Output is correct
34 Correct 32 ms 4812 KB Output is correct
35 Correct 28 ms 4676 KB Output is correct
36 Correct 29 ms 4776 KB Output is correct
37 Correct 44 ms 4532 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2772 KB Output is correct
41 Correct 2 ms 2772 KB Output is correct
42 Correct 2 ms 2760 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2772 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 86 ms 13116 KB Output is correct
48 Correct 83 ms 13224 KB Output is correct
49 Correct 39 ms 12360 KB Output is correct
50 Correct 44 ms 13280 KB Output is correct
51 Correct 40 ms 14488 KB Output is correct
52 Correct 47 ms 14500 KB Output is correct
53 Correct 25 ms 12420 KB Output is correct
54 Correct 81 ms 13124 KB Output is correct
55 Correct 146 ms 13088 KB Output is correct
56 Correct 237 ms 13052 KB Output is correct
57 Correct 74 ms 14136 KB Output is correct
58 Correct 198 ms 14024 KB Output is correct
59 Correct 159 ms 14776 KB Output is correct
60 Correct 153 ms 16128 KB Output is correct
61 Correct 94 ms 16300 KB Output is correct
62 Correct 37 ms 14792 KB Output is correct
63 Correct 97 ms 15864 KB Output is correct
64 Correct 81 ms 15692 KB Output is correct
65 Correct 116 ms 15808 KB Output is correct
66 Correct 1 ms 2644 KB Output is correct
67 Correct 82 ms 16112 KB Output is correct
68 Correct 139 ms 16188 KB Output is correct
69 Correct 254 ms 16152 KB Output is correct
70 Correct 141 ms 16192 KB Output is correct
71 Correct 125 ms 16056 KB Output is correct
72 Correct 148 ms 16020 KB Output is correct
73 Correct 72 ms 16648 KB Output is correct
74 Correct 73 ms 16672 KB Output is correct
75 Correct 187 ms 16576 KB Output is correct
76 Correct 125 ms 16152 KB Output is correct
77 Correct 61 ms 15308 KB Output is correct
78 Correct 1 ms 2644 KB Output is correct
79 Correct 2 ms 2772 KB Output is correct
80 Correct 2 ms 2772 KB Output is correct
81 Correct 2 ms 2644 KB Output is correct
82 Correct 2 ms 2644 KB Output is correct
83 Correct 2 ms 2668 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 2 ms 2660 KB Output is correct
86 Correct 46 ms 4572 KB Output is correct
87 Correct 41 ms 4672 KB Output is correct
88 Correct 39 ms 4944 KB Output is correct
89 Correct 30 ms 4804 KB Output is correct
90 Correct 30 ms 4664 KB Output is correct
91 Correct 37 ms 4832 KB Output is correct
92 Correct 39 ms 4448 KB Output is correct
93 Correct 65 ms 14844 KB Output is correct
94 Correct 59 ms 14004 KB Output is correct
95 Correct 44 ms 12980 KB Output is correct
96 Correct 58 ms 14028 KB Output is correct
97 Correct 43 ms 14760 KB Output is correct
98 Correct 39 ms 14744 KB Output is correct
99 Correct 25 ms 12484 KB Output is correct
100 Correct 147 ms 16288 KB Output is correct
101 Correct 164 ms 16316 KB Output is correct
102 Correct 97 ms 16356 KB Output is correct
103 Correct 97 ms 15860 KB Output is correct
104 Correct 87 ms 15564 KB Output is correct
105 Correct 108 ms 15960 KB Output is correct
106 Correct 128 ms 15324 KB Output is correct
107 Correct 185 ms 15676 KB Output is correct
108 Correct 78 ms 14916 KB Output is correct
109 Correct 73 ms 14972 KB Output is correct
110 Correct 66 ms 14924 KB Output is correct
111 Correct 69 ms 15028 KB Output is correct