답안 #999244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999244 2024-06-15T08:38:02 Z AlperenT_ Fire (BOI24_fire) C++17
100 / 100
140 ms 38260 KB
#include <bits/stdc++.h>
 

#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double 
#define ll long long 
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= b;i++)
#define per(i, a , b) for(int i=a;i >= b;i--)
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 5e5 + 10  ,  N = 1e5 +1 , lg = 20 , maxq = 202 , sq = 333   , inf = 2e9 +100 , maxk = 2022 , mod = 1e9 + 1 ;
int n  , m , nx[maxn][lg+1] ;
vector <pii> v1 , v2 ;
vector <int> cm ;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);   
  cin >> n >> m ;
  rep(i ,1 ,n){
    int l ,r ;
    cin >> l >>r ;
    if(l > r)r += m ;
    v1.pb({l,-r});
  } 
  sort(all(v1)) ;
  rep(i , 0, sz(v1)-1){
    if(sz(v2)!=0 && v2.back().S >= -v1[i].S){
      continue ;
    }
    v2.pb({v1[i].F , -v1[i].S}) ;
  }
  for(auto [l,r] : v2){
    cm.pb(l);
    cm.pb(r) ;
  }
  sort(all(cm)) ;
  cm.resize(unique(all(cm)) - cm.begin()) ;
  rep(i , 0 ,sz(cm)-1){
    int id = lower_bound(all(v2) , (pii){cm[i]+1 , -inf}) - v2.begin() - 1;
    if(id==-1 || v2[id].S <= cm[i]){
      nx[i][0] = -1 ;
      continue ;
    }
    nx[i][0] = lower_bound(all(cm) , v2[id].S) - cm.begin() ;   
  }
  rep(j , 1, lg){
    rep(i ,0 ,sz(cm)-1){
      if(nx[i][j-1] == -1){
        nx[i][j] = -1;
        continue ;
      }
      nx[i][j] = nx[nx[i][j-1]][j-1] ; 
    }
  }
  int mn = inf ;
  rep(i , 0, sz(cm)-1){
    int ans =1 , v = i;
    per( j, lg , 0){
      if(nx[v][j] == -1 || cm[nx[v][j]]-cm[i] >= m){
        continue ;
      }
      v=  nx[v][j] ;
      ans += (1<<j) ;
    }
    if(nx[v][0] == -1)continue ;
    mn = min(mn , ans); 
  }
  if(mn == inf){
    cout << "-1\n";
  }else{
    cout << mn << "\n" ;
  }
}
/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 408 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 408 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 532 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 408 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 532 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 4 ms 2652 KB Output is correct
41 Correct 3 ms 2648 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 4 ms 2652 KB Output is correct
45 Correct 2 ms 2828 KB Output is correct
46 Correct 4 ms 2652 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 3 ms 2648 KB Output is correct
50 Correct 3 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 432 KB Output is correct
15 Correct 4 ms 2652 KB Output is correct
16 Correct 2 ms 2892 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 20 ms 2520 KB Output is correct
21 Correct 51 ms 6848 KB Output is correct
22 Correct 49 ms 6856 KB Output is correct
23 Correct 112 ms 21872 KB Output is correct
24 Correct 130 ms 31396 KB Output is correct
25 Correct 51 ms 2532 KB Output is correct
26 Correct 99 ms 17100 KB Output is correct
27 Correct 112 ms 21728 KB Output is correct
28 Correct 44 ms 4516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 2648 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2892 KB Output is correct
15 Correct 23 ms 2520 KB Output is correct
16 Correct 86 ms 21712 KB Output is correct
17 Correct 113 ms 38260 KB Output is correct
18 Correct 119 ms 38096 KB Output is correct
19 Correct 129 ms 38244 KB Output is correct
20 Correct 91 ms 21680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 408 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 532 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 4 ms 2652 KB Output is correct
41 Correct 3 ms 2648 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 4 ms 2652 KB Output is correct
45 Correct 2 ms 2828 KB Output is correct
46 Correct 4 ms 2652 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 3 ms 2648 KB Output is correct
50 Correct 3 ms 2648 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 432 KB Output is correct
65 Correct 4 ms 2652 KB Output is correct
66 Correct 2 ms 2892 KB Output is correct
67 Correct 2 ms 348 KB Output is correct
68 Correct 2 ms 2652 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 20 ms 2520 KB Output is correct
71 Correct 51 ms 6848 KB Output is correct
72 Correct 49 ms 6856 KB Output is correct
73 Correct 112 ms 21872 KB Output is correct
74 Correct 130 ms 31396 KB Output is correct
75 Correct 51 ms 2532 KB Output is correct
76 Correct 99 ms 17100 KB Output is correct
77 Correct 112 ms 21728 KB Output is correct
78 Correct 44 ms 4516 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 0 ms 344 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 1 ms 344 KB Output is correct
83 Correct 1 ms 344 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 0 ms 348 KB Output is correct
86 Correct 1 ms 348 KB Output is correct
87 Correct 0 ms 348 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Correct 4 ms 2648 KB Output is correct
91 Correct 2 ms 2652 KB Output is correct
92 Correct 2 ms 2892 KB Output is correct
93 Correct 23 ms 2520 KB Output is correct
94 Correct 86 ms 21712 KB Output is correct
95 Correct 113 ms 38260 KB Output is correct
96 Correct 119 ms 38096 KB Output is correct
97 Correct 129 ms 38244 KB Output is correct
98 Correct 91 ms 21680 KB Output is correct
99 Correct 64 ms 13764 KB Output is correct
100 Correct 46 ms 6728 KB Output is correct
101 Correct 136 ms 38208 KB Output is correct
102 Correct 140 ms 31432 KB Output is correct
103 Correct 107 ms 21872 KB Output is correct
104 Correct 54 ms 6996 KB Output is correct
105 Correct 92 ms 21116 KB Output is correct