답안 #595633

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
595633 2022-07-13T22:27:33 Z definitelynotmee Event Hopping (BOI22_events) C++
100 / 100
154 ms 14376 KB
#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
const int INF = 1<<30;

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int n, q;
    cin >> n >> q;
    vector<pii> v(n);
    for(pii& i : v){
        cin >> i.ff >> i.ss;
        i.ff = INF-i.ff;
        i.ss = INF-i.ss;
        swap(i.ff,i.ss);
    }
    // cout << "----------\n";
    // for(pii i : v)
    //     cout << i.ff << ' ' << i.ss << '\n';
    // cout << "----------\n";
    vector<int>o(n);
    iota(all(o),0);
    sort(all(o),[&](int a, int b){
        return v[a] > v[b];
    });

    vector<int> jmp(n);
    vector<int> st;

    for(int i : o){
        int ini = 0, fim = st.size();
        while(ini!=fim){
            int m = (ini+fim)>>1;
            if(v[st[m]].ff <= v[i].ss)
                fim = m;
            else ini = m+1;
        }
        if(ini == st.size()){
            jmp[i] = i;
        } else jmp[i] = st[ini];
        
        while(!st.empty() && v[st.back()].ss <= v[i].ss)
            st.pop_back();
        if(st.empty() || v[st.back()].ff > v[i].ff)
            st.push_back(i);
        // cout << i << ":\n";
        // for(int i : st)
        //     cout << i << ' ';
        // cout << '\n';
    }

    matrix<int> lift(20,vector<int>(n));
    for(int i = 0; i < n; i++){
        lift[0][i] = jmp[i]; 
        // cout << jmp[i] << ' ';
    }
    // cout << '\n';
    for(int i = 1; i < 20; i++){
        for(int j = 0; j < n; j++){
            lift[i][j] = lift[i-1][lift[i-1][j]];
        }
    }
    
    while(q--){
        int a, b;
        cin >> a >> b;
        a--, b--;
        swap(a,b);
        if(v[a].ff > v[b].ff){
            cout << "impossible\n";
            continue;
        }
        if(a==b){
            cout << 0 << '\n';
            continue;
        }
        if(v[a].ss >= v[b].ff){
            cout << 1 << '\n';
            continue;
        }
        int ct = 2;
        for(int i = 19; i >= 0; i--){
            if(v[lift[i][a]].ss < v[b].ff)
                ct+=1<<i, a = lift[i][a];
        }
        a = lift[0][a];
        if(v[a].ss >= v[b].ff){
            cout << ct << '\n';
        } else {
            cout << "impossible\n";
        }
    }

}

Compilation message

events.cpp: In function 'int main()':
events.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if(ini == st.size()){
      |            ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 62 ms 10824 KB Output is correct
3 Correct 78 ms 10772 KB Output is correct
4 Correct 129 ms 10844 KB Output is correct
5 Correct 84 ms 10796 KB Output is correct
6 Correct 93 ms 10948 KB Output is correct
7 Correct 84 ms 10768 KB Output is correct
8 Correct 99 ms 11360 KB Output is correct
9 Correct 95 ms 11372 KB Output is correct
10 Correct 99 ms 11300 KB Output is correct
11 Correct 86 ms 11024 KB Output is correct
12 Correct 56 ms 11076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 31 ms 1292 KB Output is correct
20 Correct 27 ms 1224 KB Output is correct
21 Correct 30 ms 1484 KB Output is correct
22 Correct 25 ms 1720 KB Output is correct
23 Correct 22 ms 1364 KB Output is correct
24 Correct 21 ms 1440 KB Output is correct
25 Correct 32 ms 1208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 38 ms 10580 KB Output is correct
20 Correct 33 ms 10580 KB Output is correct
21 Correct 40 ms 10052 KB Output is correct
22 Correct 37 ms 10480 KB Output is correct
23 Correct 36 ms 10572 KB Output is correct
24 Correct 55 ms 10632 KB Output is correct
25 Correct 24 ms 10088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 10824 KB Output is correct
2 Correct 77 ms 10824 KB Output is correct
3 Correct 119 ms 10852 KB Output is correct
4 Correct 92 ms 11288 KB Output is correct
5 Correct 102 ms 11200 KB Output is correct
6 Correct 82 ms 10956 KB Output is correct
7 Correct 113 ms 10976 KB Output is correct
8 Correct 109 ms 11060 KB Output is correct
9 Correct 40 ms 10572 KB Output is correct
10 Correct 109 ms 10596 KB Output is correct
11 Correct 74 ms 10588 KB Output is correct
12 Correct 86 ms 10568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 62 ms 10824 KB Output is correct
3 Correct 78 ms 10772 KB Output is correct
4 Correct 129 ms 10844 KB Output is correct
5 Correct 84 ms 10796 KB Output is correct
6 Correct 93 ms 10948 KB Output is correct
7 Correct 84 ms 10768 KB Output is correct
8 Correct 99 ms 11360 KB Output is correct
9 Correct 95 ms 11372 KB Output is correct
10 Correct 99 ms 11300 KB Output is correct
11 Correct 86 ms 11024 KB Output is correct
12 Correct 56 ms 11076 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 31 ms 1292 KB Output is correct
32 Correct 27 ms 1224 KB Output is correct
33 Correct 30 ms 1484 KB Output is correct
34 Correct 25 ms 1720 KB Output is correct
35 Correct 22 ms 1364 KB Output is correct
36 Correct 21 ms 1440 KB Output is correct
37 Correct 32 ms 1208 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 38 ms 10580 KB Output is correct
48 Correct 33 ms 10580 KB Output is correct
49 Correct 40 ms 10052 KB Output is correct
50 Correct 37 ms 10480 KB Output is correct
51 Correct 36 ms 10572 KB Output is correct
52 Correct 55 ms 10632 KB Output is correct
53 Correct 24 ms 10088 KB Output is correct
54 Correct 78 ms 10824 KB Output is correct
55 Correct 77 ms 10824 KB Output is correct
56 Correct 119 ms 10852 KB Output is correct
57 Correct 92 ms 11288 KB Output is correct
58 Correct 102 ms 11200 KB Output is correct
59 Correct 82 ms 10956 KB Output is correct
60 Correct 113 ms 10976 KB Output is correct
61 Correct 109 ms 11060 KB Output is correct
62 Correct 40 ms 10572 KB Output is correct
63 Correct 109 ms 10596 KB Output is correct
64 Correct 74 ms 10588 KB Output is correct
65 Correct 86 ms 10568 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 69 ms 13888 KB Output is correct
68 Correct 101 ms 13856 KB Output is correct
69 Correct 151 ms 13800 KB Output is correct
70 Correct 124 ms 13856 KB Output is correct
71 Correct 107 ms 13820 KB Output is correct
72 Correct 91 ms 13868 KB Output is correct
73 Correct 101 ms 14268 KB Output is correct
74 Correct 154 ms 14376 KB Output is correct
75 Correct 91 ms 14232 KB Output is correct
76 Correct 94 ms 14088 KB Output is correct
77 Correct 59 ms 13384 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 432 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 32 ms 2280 KB Output is correct
87 Correct 38 ms 2268 KB Output is correct
88 Correct 30 ms 2504 KB Output is correct
89 Correct 25 ms 2508 KB Output is correct
90 Correct 22 ms 2428 KB Output is correct
91 Correct 21 ms 2388 KB Output is correct
92 Correct 27 ms 2120 KB Output is correct
93 Correct 38 ms 12516 KB Output is correct
94 Correct 35 ms 11708 KB Output is correct
95 Correct 38 ms 11956 KB Output is correct
96 Correct 46 ms 12408 KB Output is correct
97 Correct 37 ms 12472 KB Output is correct
98 Correct 38 ms 12572 KB Output is correct
99 Correct 26 ms 11340 KB Output is correct
100 Correct 101 ms 13976 KB Output is correct
101 Correct 82 ms 13940 KB Output is correct
102 Correct 76 ms 14068 KB Output is correct
103 Correct 78 ms 13628 KB Output is correct
104 Correct 76 ms 13252 KB Output is correct
105 Correct 76 ms 13700 KB Output is correct
106 Correct 80 ms 13252 KB Output is correct
107 Correct 97 ms 13328 KB Output is correct
108 Correct 90 ms 13496 KB Output is correct
109 Correct 75 ms 13364 KB Output is correct
110 Correct 62 ms 13404 KB Output is correct
111 Correct 61 ms 13372 KB Output is correct