Submission #1027592

# Submission time Handle Problem Language Result Execution time Memory
1027592 2024-07-19T07:52:31 Z Otalp Fire (BOI24_fire) C++14
40 / 100
138 ms 35008 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 + 1, (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 + 1, (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 + 1 >= 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 + 1 < e) res++;
        if(d[k].ss + 1 < 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 4696 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 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 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 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 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 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 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 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 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 4444 KB Output is correct
28 Correct 1 ms 4548 KB Output is correct
29 Correct 1 ms 4444 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 4440 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 4696 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 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 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 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 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 4444 KB Output is correct
28 Correct 1 ms 4548 KB Output is correct
29 Correct 1 ms 4444 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 4440 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 6748 KB Output is correct
40 Correct 6 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 6704 KB Output is correct
46 Correct 4 ms 6748 KB Output is correct
47 Correct 4 ms 6748 KB Output is correct
48 Correct 4 ms 6748 KB Output is correct
49 Correct 2 ms 6748 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 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 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 0 ms 4544 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 6700 KB Output is correct
17 Correct 4 ms 6748 KB Output is correct
18 Correct 4 ms 6748 KB Output is correct
19 Correct 4 ms 6748 KB Output is correct
20 Correct 67 ms 34324 KB Output is correct
21 Correct 129 ms 27504 KB Output is correct
22 Correct 131 ms 27544 KB Output is correct
23 Correct 108 ms 26484 KB Output is correct
24 Incorrect 125 ms 27584 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4440 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 3 ms 6748 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 56 ms 35008 KB Output is correct
16 Correct 108 ms 25536 KB Output is correct
17 Correct 119 ms 26044 KB Output is correct
18 Correct 138 ms 28328 KB Output is correct
19 Incorrect 121 ms 25588 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 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 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 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 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 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 4444 KB Output is correct
28 Correct 1 ms 4548 KB Output is correct
29 Correct 1 ms 4444 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 4440 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 6748 KB Output is correct
40 Correct 6 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 6704 KB Output is correct
46 Correct 4 ms 6748 KB Output is correct
47 Correct 4 ms 6748 KB Output is correct
48 Correct 4 ms 6748 KB Output is correct
49 Correct 2 ms 6748 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 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4440 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 0 ms 4544 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 6700 KB Output is correct
67 Correct 4 ms 6748 KB Output is correct
68 Correct 4 ms 6748 KB Output is correct
69 Correct 4 ms 6748 KB Output is correct
70 Correct 67 ms 34324 KB Output is correct
71 Correct 129 ms 27504 KB Output is correct
72 Correct 131 ms 27544 KB Output is correct
73 Correct 108 ms 26484 KB Output is correct
74 Incorrect 125 ms 27584 KB Output isn't correct
75 Halted 0 ms 0 KB -