Submission #1027616

# Submission time Handle Problem Language Result Execution time Memory
1027616 2024-07-19T08:00:15 Z Otalp Fire (BOI24_fire) C++14
100 / 100
183 ms 34072 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

pii a[200100];
pii pref[400100];
int jmp[400100][20];

void solve(){
    int n, m;
    cin>>n>>m;
    int ok = 0;
    vector<int> q;
    vector<pii> d;
    for(int i=1; i<=n; i++){
        cin>>a[i].ff>>a[i].ss;
        if(a[i].ff > a[i].ss){
            q.pb(i);
            d.pb({0, a[i].ss});
            d.pb({a[i].ff, m});
        }
        else{
            d.pb(a[i]);
        }
    }   
    sort(d.begin(), d.end());
    pref[0] = {d[0].ss, 0};
    for(int i=1; i<d.size(); i++){
        pref[i] = max(pref[i-1], {d[i].ss, i});
    }
    for(int i=0; i<d.size(); i++){
        int g = lower_bound(d.begin(), d.end(), mp(d[i].ss, (int)1e9 + 1)) - d.begin() - 1;
        jmp[i][0] = pref[g].ss;
    }
    for(int k=1; k<20; k++){
        for(int i=0; i<d.size(); i++){
            jmp[i][k] = jmp[jmp[i][k-1]][k-1];
        }
    }
    int ans = 1e9;
    for(int j: q){
        int s=a[j].ss, e=a[j].ff;
        int g = lower_bound(d.begin(), d.end(), mp(a[j].ss, (int)1e9 + 1)) - d.begin() - 1;
        g = pref[g].ss;
        int res = 2;
        for(int i=19; i>=0; i--){
            int k = jmp[g][i];
            if(d[k].ss >= e) continue;
            g = jmp[g][i];
            res += (1 << i);
        }
        int k = jmp[g][0];
        //cout<<d[k].ff<<' '<<d[k].ss<<'\n';
        if(d[g].ss < e) res++;
        if(d[k].ss < e){
            res = 1e9;
        }
        ans = min(ans, res);
    }
    if(ans == 1e9) cout<<-1;
    else cout<<ans;
                
                




}

signed main(){
    solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i=1; i<d.size(); i++){
      |                  ~^~~~~~~~~
Main.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0; i<d.size(); i++){
      |                  ~^~~~~~~~~
Main.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for(int i=0; i<d.size(); i++){
      |                      ~^~~~~~~~~
Main.cpp:47:13: warning: unused variable 's' [-Wunused-variable]
   47 |         int s=a[j].ss, e=a[j].ff;
      |             ^
Main.cpp:17:9: warning: unused variable 'ok' [-Wunused-variable]
   17 |     int ok = 0;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 4 ms 6744 KB Output is correct
40 Correct 4 ms 6748 KB Output is correct
41 Correct 4 ms 6748 KB Output is correct
42 Correct 3 ms 6748 KB Output is correct
43 Correct 4 ms 6748 KB Output is correct
44 Correct 4 ms 6748 KB Output is correct
45 Correct 4 ms 6744 KB Output is correct
46 Correct 4 ms 6744 KB Output is correct
47 Correct 4 ms 6748 KB Output is correct
48 Correct 6 ms 6748 KB Output is correct
49 Correct 3 ms 6744 KB Output is correct
50 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4536 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 4 ms 6748 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 4 ms 6876 KB Output is correct
18 Correct 4 ms 6748 KB Output is correct
19 Correct 4 ms 6748 KB Output is correct
20 Correct 68 ms 33468 KB Output is correct
21 Correct 129 ms 23764 KB Output is correct
22 Correct 129 ms 23612 KB Output is correct
23 Correct 115 ms 23684 KB Output is correct
24 Correct 137 ms 23740 KB Output is correct
25 Correct 130 ms 28348 KB Output is correct
26 Correct 132 ms 23704 KB Output is correct
27 Correct 133 ms 23524 KB Output is correct
28 Correct 128 ms 23688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 8 ms 6744 KB Output is correct
13 Correct 4 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 109 ms 34072 KB Output is correct
16 Correct 124 ms 23748 KB Output is correct
17 Correct 153 ms 23740 KB Output is correct
18 Correct 154 ms 25848 KB Output is correct
19 Correct 156 ms 23748 KB Output is correct
20 Correct 121 ms 25376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 4 ms 6744 KB Output is correct
40 Correct 4 ms 6748 KB Output is correct
41 Correct 4 ms 6748 KB Output is correct
42 Correct 3 ms 6748 KB Output is correct
43 Correct 4 ms 6748 KB Output is correct
44 Correct 4 ms 6748 KB Output is correct
45 Correct 4 ms 6744 KB Output is correct
46 Correct 4 ms 6744 KB Output is correct
47 Correct 4 ms 6748 KB Output is correct
48 Correct 6 ms 6748 KB Output is correct
49 Correct 3 ms 6744 KB Output is correct
50 Correct 3 ms 6748 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4440 KB Output is correct
53 Correct 1 ms 4440 KB Output is correct
54 Correct 0 ms 4444 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 0 ms 4444 KB Output is correct
57 Correct 1 ms 4536 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 1 ms 4444 KB Output is correct
64 Correct 1 ms 4444 KB Output is correct
65 Correct 4 ms 6748 KB Output is correct
66 Correct 3 ms 6748 KB Output is correct
67 Correct 4 ms 6876 KB Output is correct
68 Correct 4 ms 6748 KB Output is correct
69 Correct 4 ms 6748 KB Output is correct
70 Correct 68 ms 33468 KB Output is correct
71 Correct 129 ms 23764 KB Output is correct
72 Correct 129 ms 23612 KB Output is correct
73 Correct 115 ms 23684 KB Output is correct
74 Correct 137 ms 23740 KB Output is correct
75 Correct 130 ms 28348 KB Output is correct
76 Correct 132 ms 23704 KB Output is correct
77 Correct 133 ms 23524 KB Output is correct
78 Correct 128 ms 23688 KB Output is correct
79 Correct 1 ms 4440 KB Output is correct
80 Correct 1 ms 4444 KB Output is correct
81 Correct 1 ms 4444 KB Output is correct
82 Correct 1 ms 4444 KB Output is correct
83 Correct 1 ms 4444 KB Output is correct
84 Correct 1 ms 4444 KB Output is correct
85 Correct 1 ms 4444 KB Output is correct
86 Correct 1 ms 4444 KB Output is correct
87 Correct 1 ms 4444 KB Output is correct
88 Correct 1 ms 4444 KB Output is correct
89 Correct 1 ms 4444 KB Output is correct
90 Correct 8 ms 6744 KB Output is correct
91 Correct 4 ms 6748 KB Output is correct
92 Correct 3 ms 6748 KB Output is correct
93 Correct 109 ms 34072 KB Output is correct
94 Correct 124 ms 23748 KB Output is correct
95 Correct 153 ms 23740 KB Output is correct
96 Correct 154 ms 25848 KB Output is correct
97 Correct 156 ms 23748 KB Output is correct
98 Correct 121 ms 25376 KB Output is correct
99 Correct 142 ms 27584 KB Output is correct
100 Correct 183 ms 27884 KB Output is correct
101 Correct 150 ms 27532 KB Output is correct
102 Correct 148 ms 27492 KB Output is correct
103 Correct 143 ms 27436 KB Output is correct
104 Correct 137 ms 27492 KB Output is correct
105 Correct 105 ms 26340 KB Output is correct