답안 #952694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952694 2024-03-24T14:52:25 Z Mohamed_Kachef06 Fuel Station (NOI20_fuelstation) C++17
100 / 100
501 ms 48340 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 

#define lc 2*p
#define rc 2*p+1
struct SegmentTree{
    vector<int> seg , lazy;
    int m;
    void init(int n){
        m = 1<<(__lg(n-1)+1);
        seg.resize(2*m); lazy.resize(2*m);
    }
    void propagate(int s,  int e , int p){
        if (s == e) return ;
        lazy[2*p]+=lazy[p];
        lazy[2*p+1] += lazy[p];
        seg[2*p] += lazy[p];
        seg[rc] += lazy[p]; 
        lazy[p] = 0;
    }
    void update(int l , int r , int val , int s , int e , int p){
        propagate(s , e , p);
        if (l > e || r < s) return ;
        else if (l <= s && r >= e){
            seg[p]+=val;
            lazy[p] += val; 
            return; 
        }
        update(l , r , val , s , (s+e)/2, 2*p); update(l, r , val , (s+e)/2+1 , e , 2*p+1);
        seg[p] = min(seg[lc] , seg[rc]);
    }
    int get(int l , int r , int s , int e , int p){
        propagate(s , e , p);
        if (l > e || r < s) return 1e18;
        else if (l <= s && r >= e) return seg[p]; 
        return min(get(l , r , s , (s+e)/2 , lc) , get(l , r , (s+e)/2 + 1 , e , 2*p+1));  
    }
    void update(int l , int r , int val){
        update(l , r , val ,1 , m ,1);
    }
    int get(int l , int r){
        return get(l , r ,1 , m , 1);
    }
};



SegmentTree st;

void doWork(){
    int n , d;
    cin >> n >> d;
    vector<array<int , 3>> v(n+1); 
    vector<array<int , 3>> u(n); 
    int arr[n+1] = {};
    // arr[i] = cost to go from i to i+1
    st.init(n+10); 
    for (int i=  1 ; i <= n ; i++){
        for (int j = 0 ; j < 3 ; j++){
            cin >> v[i][j]; 
        }
    }
    v.push_back({d , 0 , 0});
    sort(v.begin() , v.end());

    for (int i = 1 ; i <= n ; i++){
        u[i-1] = {v[i][2] , v[i][1] , i}; 
    }
    u.push_back({(int)1e18 , 0 , 0});
    sort(u.begin() , u.end() , greater<>());

    for (int i = 1 ; i <= n+1 ; i++){
        st.update(i , i , -v[i][0]); 
    }
    //cout << st.get(1 , n+2)  << ' ' ;
    int ans = 1e18;
    int id = 0;
    for (int i = 0 ; i <= n ; i++){
        while (id <= n && u[id][0] >= u[i][0]) {  st.update(u[id][2] + 1  , n+1 , u[id][1]); id++;}
        int mx = -st.get(1 , n+1); 
        // cout << mx << ' ' << u[i][0] << '\n';
        // cout << '\n';
        //cout << mx << ' ' ;
        if (mx <= u[i][0]) ans = min(ans , mx);
    }
    cout << ans; 
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    doWork(); 
}

Compilation message

FuelStation.cpp: In function 'void doWork()':
FuelStation.cpp:56:9: warning: unused variable 'arr' [-Wunused-variable]
   56 |     int arr[n+1] = {};
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 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 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 41972 KB Output is correct
2 Correct 444 ms 47528 KB Output is correct
3 Correct 474 ms 46040 KB Output is correct
4 Correct 456 ms 47572 KB Output is correct
5 Correct 446 ms 47032 KB Output is correct
6 Correct 448 ms 46548 KB Output is correct
7 Correct 454 ms 45768 KB Output is correct
8 Correct 457 ms 47324 KB Output is correct
9 Correct 486 ms 47380 KB Output is correct
10 Correct 434 ms 46756 KB Output is correct
11 Correct 453 ms 45724 KB Output is correct
12 Correct 434 ms 47060 KB Output is correct
13 Correct 441 ms 45780 KB Output is correct
14 Correct 454 ms 47716 KB Output is correct
15 Correct 454 ms 45016 KB Output is correct
16 Correct 451 ms 48092 KB Output is correct
17 Correct 501 ms 48340 KB Output is correct
18 Correct 472 ms 46812 KB Output is correct
19 Correct 446 ms 46680 KB Output is correct
20 Correct 464 ms 46160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 11 ms 1648 KB Output is correct
3 Correct 11 ms 1648 KB Output is correct
4 Correct 11 ms 1648 KB Output is correct
5 Correct 12 ms 1648 KB Output is correct
6 Correct 10 ms 1672 KB Output is correct
7 Correct 11 ms 1628 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 11 ms 1648 KB Output is correct
15 Correct 11 ms 1648 KB Output is correct
16 Correct 11 ms 1644 KB Output is correct
17 Correct 11 ms 1648 KB Output is correct
18 Correct 11 ms 1648 KB Output is correct
19 Correct 11 ms 1900 KB Output is correct
20 Correct 11 ms 1648 KB Output is correct
21 Correct 12 ms 1628 KB Output is correct
22 Correct 11 ms 1648 KB Output is correct
23 Correct 11 ms 1648 KB Output is correct
24 Correct 11 ms 1648 KB Output is correct
25 Correct 11 ms 1648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 11 ms 1648 KB Output is correct
3 Correct 11 ms 1648 KB Output is correct
4 Correct 11 ms 1648 KB Output is correct
5 Correct 12 ms 1648 KB Output is correct
6 Correct 10 ms 1672 KB Output is correct
7 Correct 11 ms 1628 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 11 ms 1648 KB Output is correct
15 Correct 11 ms 1648 KB Output is correct
16 Correct 11 ms 1644 KB Output is correct
17 Correct 11 ms 1648 KB Output is correct
18 Correct 11 ms 1648 KB Output is correct
19 Correct 11 ms 1900 KB Output is correct
20 Correct 11 ms 1648 KB Output is correct
21 Correct 12 ms 1628 KB Output is correct
22 Correct 11 ms 1648 KB Output is correct
23 Correct 11 ms 1648 KB Output is correct
24 Correct 11 ms 1648 KB Output is correct
25 Correct 11 ms 1648 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 467 ms 40620 KB Output is correct
28 Correct 429 ms 46348 KB Output is correct
29 Correct 431 ms 45780 KB Output is correct
30 Correct 427 ms 44196 KB Output is correct
31 Correct 453 ms 44756 KB Output is correct
32 Correct 422 ms 43308 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 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 0 ms 348 KB Output is correct
39 Correct 437 ms 45976 KB Output is correct
40 Correct 436 ms 45412 KB Output is correct
41 Correct 432 ms 43244 KB Output is correct
42 Correct 438 ms 45816 KB Output is correct
43 Correct 426 ms 43412 KB Output is correct
44 Correct 418 ms 42880 KB Output is correct
45 Correct 433 ms 42908 KB Output is correct
46 Correct 432 ms 46132 KB Output is correct
47 Correct 439 ms 45668 KB Output is correct
48 Correct 446 ms 45736 KB Output is correct
49 Correct 428 ms 44092 KB Output is correct
50 Correct 450 ms 44868 KB Output is correct
51 Correct 426 ms 44504 KB Output is correct
52 Correct 432 ms 44248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 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 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 388 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 364 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 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 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 11 ms 1648 KB Output is correct
18 Correct 11 ms 1648 KB Output is correct
19 Correct 11 ms 1648 KB Output is correct
20 Correct 12 ms 1648 KB Output is correct
21 Correct 10 ms 1672 KB Output is correct
22 Correct 11 ms 1628 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 11 ms 1648 KB Output is correct
30 Correct 11 ms 1648 KB Output is correct
31 Correct 11 ms 1644 KB Output is correct
32 Correct 11 ms 1648 KB Output is correct
33 Correct 11 ms 1648 KB Output is correct
34 Correct 11 ms 1900 KB Output is correct
35 Correct 11 ms 1648 KB Output is correct
36 Correct 12 ms 1628 KB Output is correct
37 Correct 11 ms 1648 KB Output is correct
38 Correct 11 ms 1648 KB Output is correct
39 Correct 11 ms 1648 KB Output is correct
40 Correct 11 ms 1648 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 12 ms 1648 KB Output is correct
43 Correct 11 ms 1644 KB Output is correct
44 Correct 12 ms 1648 KB Output is correct
45 Correct 11 ms 1648 KB Output is correct
46 Correct 15 ms 1648 KB Output is correct
47 Correct 12 ms 1648 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 11 ms 1648 KB Output is correct
55 Correct 11 ms 1648 KB Output is correct
56 Correct 12 ms 1644 KB Output is correct
57 Correct 11 ms 1644 KB Output is correct
58 Correct 12 ms 1648 KB Output is correct
59 Correct 12 ms 1644 KB Output is correct
60 Correct 12 ms 1648 KB Output is correct
61 Correct 12 ms 1648 KB Output is correct
62 Correct 12 ms 1648 KB Output is correct
63 Correct 12 ms 1648 KB Output is correct
64 Correct 13 ms 1644 KB Output is correct
65 Correct 12 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 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 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 455 ms 41972 KB Output is correct
17 Correct 444 ms 47528 KB Output is correct
18 Correct 474 ms 46040 KB Output is correct
19 Correct 456 ms 47572 KB Output is correct
20 Correct 446 ms 47032 KB Output is correct
21 Correct 448 ms 46548 KB Output is correct
22 Correct 454 ms 45768 KB Output is correct
23 Correct 457 ms 47324 KB Output is correct
24 Correct 486 ms 47380 KB Output is correct
25 Correct 434 ms 46756 KB Output is correct
26 Correct 453 ms 45724 KB Output is correct
27 Correct 434 ms 47060 KB Output is correct
28 Correct 441 ms 45780 KB Output is correct
29 Correct 454 ms 47716 KB Output is correct
30 Correct 454 ms 45016 KB Output is correct
31 Correct 451 ms 48092 KB Output is correct
32 Correct 501 ms 48340 KB Output is correct
33 Correct 472 ms 46812 KB Output is correct
34 Correct 446 ms 46680 KB Output is correct
35 Correct 464 ms 46160 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 11 ms 1648 KB Output is correct
38 Correct 11 ms 1648 KB Output is correct
39 Correct 11 ms 1648 KB Output is correct
40 Correct 12 ms 1648 KB Output is correct
41 Correct 10 ms 1672 KB Output is correct
42 Correct 11 ms 1628 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 11 ms 1648 KB Output is correct
50 Correct 11 ms 1648 KB Output is correct
51 Correct 11 ms 1644 KB Output is correct
52 Correct 11 ms 1648 KB Output is correct
53 Correct 11 ms 1648 KB Output is correct
54 Correct 11 ms 1900 KB Output is correct
55 Correct 11 ms 1648 KB Output is correct
56 Correct 12 ms 1628 KB Output is correct
57 Correct 11 ms 1648 KB Output is correct
58 Correct 11 ms 1648 KB Output is correct
59 Correct 11 ms 1648 KB Output is correct
60 Correct 11 ms 1648 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 467 ms 40620 KB Output is correct
63 Correct 429 ms 46348 KB Output is correct
64 Correct 431 ms 45780 KB Output is correct
65 Correct 427 ms 44196 KB Output is correct
66 Correct 453 ms 44756 KB Output is correct
67 Correct 422 ms 43308 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 437 ms 45976 KB Output is correct
75 Correct 436 ms 45412 KB Output is correct
76 Correct 432 ms 43244 KB Output is correct
77 Correct 438 ms 45816 KB Output is correct
78 Correct 426 ms 43412 KB Output is correct
79 Correct 418 ms 42880 KB Output is correct
80 Correct 433 ms 42908 KB Output is correct
81 Correct 432 ms 46132 KB Output is correct
82 Correct 439 ms 45668 KB Output is correct
83 Correct 446 ms 45736 KB Output is correct
84 Correct 428 ms 44092 KB Output is correct
85 Correct 450 ms 44868 KB Output is correct
86 Correct 426 ms 44504 KB Output is correct
87 Correct 432 ms 44248 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Correct 1 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 0 ms 348 KB Output is correct
93 Correct 1 ms 388 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 0 ms 344 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 364 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 348 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 1 ms 348 KB Output is correct
103 Correct 0 ms 344 KB Output is correct
104 Correct 12 ms 1648 KB Output is correct
105 Correct 11 ms 1644 KB Output is correct
106 Correct 12 ms 1648 KB Output is correct
107 Correct 11 ms 1648 KB Output is correct
108 Correct 15 ms 1648 KB Output is correct
109 Correct 12 ms 1648 KB Output is correct
110 Correct 0 ms 344 KB Output is correct
111 Correct 1 ms 348 KB Output is correct
112 Correct 0 ms 348 KB Output is correct
113 Correct 0 ms 348 KB Output is correct
114 Correct 0 ms 348 KB Output is correct
115 Correct 0 ms 348 KB Output is correct
116 Correct 11 ms 1648 KB Output is correct
117 Correct 11 ms 1648 KB Output is correct
118 Correct 12 ms 1644 KB Output is correct
119 Correct 11 ms 1644 KB Output is correct
120 Correct 12 ms 1648 KB Output is correct
121 Correct 12 ms 1644 KB Output is correct
122 Correct 12 ms 1648 KB Output is correct
123 Correct 12 ms 1648 KB Output is correct
124 Correct 12 ms 1648 KB Output is correct
125 Correct 12 ms 1648 KB Output is correct
126 Correct 13 ms 1644 KB Output is correct
127 Correct 12 ms 1628 KB Output is correct
128 Correct 0 ms 348 KB Output is correct
129 Correct 467 ms 45540 KB Output is correct
130 Correct 433 ms 44964 KB Output is correct
131 Correct 438 ms 45412 KB Output is correct
132 Correct 476 ms 45800 KB Output is correct
133 Correct 453 ms 47572 KB Output is correct
134 Correct 454 ms 47064 KB Output is correct
135 Correct 0 ms 348 KB Output is correct
136 Correct 1 ms 456 KB Output is correct
137 Correct 0 ms 348 KB Output is correct
138 Correct 0 ms 348 KB Output is correct
139 Correct 0 ms 456 KB Output is correct
140 Correct 0 ms 348 KB Output is correct
141 Correct 441 ms 47320 KB Output is correct
142 Correct 447 ms 47832 KB Output is correct
143 Correct 436 ms 46748 KB Output is correct
144 Correct 444 ms 48336 KB Output is correct
145 Correct 440 ms 46708 KB Output is correct
146 Correct 419 ms 45780 KB Output is correct
147 Correct 427 ms 44704 KB Output is correct
148 Correct 420 ms 46044 KB Output is correct
149 Correct 447 ms 45224 KB Output is correct
150 Correct 439 ms 46808 KB Output is correct
151 Correct 437 ms 46040 KB Output is correct
152 Correct 446 ms 46804 KB Output is correct
153 Correct 447 ms 45164 KB Output is correct
154 Correct 454 ms 48088 KB Output is correct
155 Correct 460 ms 48264 KB Output is correct