Submission #890093

# Submission time Handle Problem Language Result Execution time Memory
890093 2023-12-20T14:07:20 Z vjudge1 Fuel Station (NOI20_fuelstation) C++14
100 / 100
609 ms 71696 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long

struct Node{
   int val, lazy;
   Node(int x=1e18, int y=0){
      val=x;
      lazy=y;
   }
   friend Node operator+(const Node &a, const Node &b){
      return Node(min(a.val, b.val));
   }
};

struct SegmentTree{
   int n;
   vector<Node> t;
   void init(int _n){
      n=_n;
      t.assign(4*n+1, Node());
   }
   void build(int k, int l, int r, const vector<int> &a){
      if (l==r){
         t[k].val=-a[l];
         return;
      }
      int mid=(l+r)>>1;
      build(k<<1, l, mid, a);
      build(k<<1|1, mid+1, r, a);
      t[k]=t[k<<1]+t[k<<1|1];
   }
   void apply(int k, int val){
      t[k].val+=val;
      t[k].lazy+=val;
   }
   void push(int k){
      if (t[k].lazy){
         apply(k<<1, t[k].lazy);
         apply(k<<1|1, t[k].lazy);
         t[k].lazy=0;
      }
   }
   void update(int k, int l, int r, int L, int R, int val){
      if (r<L || R<l) return;
      if (L<=l && r<=R){
         apply(k, val);
         return;
      }
      push(k);
      int mid=(l+r)>>1;
      update(k<<1, l, mid, L, R, val);
      update(k<<1|1, mid+1, r, L, R, val);
      t[k]=t[k<<1]+t[k<<1|1];
   }
   Node get(int k, int l, int r, int L, int R){
      if (r<L || R<l) return t[0];
      if (L<=l && r<=R) return t[k];
      push(k);
      int mid=(l+r)>>1;
      return get(k<<1, l, mid, L, R)+get(k<<1|1, mid+1, r, L, R);
   }
} st;

const int N=3e5+1;
int n, d, x[N], a[N], b[N];

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cin >> n >> d;
   vector<int> pos{-1, d};
   map<int, vector<int>> mp;
   for (int i=1; i<=n; ++i) cin >> x[i] >> a[i] >> b[i], pos.push_back(x[i]), mp[-b[i]].push_back(i);
   sort(pos.begin(), pos.end());
   pos.resize(unique(pos.begin(), pos.end())-pos.begin());
   int ans=d;
   st.init((int)pos.size()-1);
   st.build(1, 1, st.n, pos);
   for (auto &i:mp){
      for (int j:i.second) st.update(1, 1, st.n, lower_bound(pos.begin(), pos.end(), x[j])-pos.begin()+1, st.n, a[j]);
      if (-i.first+st.t[1].val>=0) ans=min(ans, -st.t[1].val);
   }
   cout << ans;
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4556 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 4564 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 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4556 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 176 ms 21784 KB Output is correct
2 Correct 157 ms 21684 KB Output is correct
3 Correct 163 ms 22952 KB Output is correct
4 Correct 139 ms 22304 KB Output is correct
5 Correct 133 ms 24000 KB Output is correct
6 Correct 166 ms 22320 KB Output is correct
7 Correct 160 ms 22188 KB Output is correct
8 Correct 130 ms 22588 KB Output is correct
9 Correct 165 ms 23920 KB Output is correct
10 Correct 129 ms 22444 KB Output is correct
11 Correct 157 ms 22692 KB Output is correct
12 Correct 130 ms 22664 KB Output is correct
13 Correct 162 ms 22712 KB Output is correct
14 Correct 163 ms 23932 KB Output is correct
15 Correct 128 ms 23216 KB Output is correct
16 Correct 173 ms 23060 KB Output is correct
17 Correct 132 ms 23620 KB Output is correct
18 Correct 160 ms 23292 KB Output is correct
19 Correct 129 ms 24292 KB Output is correct
20 Correct 167 ms 23456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 5 ms 4956 KB Output is correct
3 Correct 8 ms 5820 KB Output is correct
4 Correct 6 ms 5724 KB Output is correct
5 Correct 6 ms 5724 KB Output is correct
6 Correct 8 ms 6236 KB Output is correct
7 Correct 8 ms 6492 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 2 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 7 ms 5592 KB Output is correct
15 Correct 7 ms 5464 KB Output is correct
16 Correct 7 ms 5492 KB Output is correct
17 Correct 7 ms 5468 KB Output is correct
18 Correct 7 ms 5596 KB Output is correct
19 Correct 5 ms 4956 KB Output is correct
20 Correct 5 ms 5032 KB Output is correct
21 Correct 6 ms 5084 KB Output is correct
22 Correct 4 ms 5000 KB Output is correct
23 Correct 4 ms 4956 KB Output is correct
24 Correct 5 ms 4956 KB Output is correct
25 Correct 5 ms 4828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 5 ms 4956 KB Output is correct
3 Correct 8 ms 5820 KB Output is correct
4 Correct 6 ms 5724 KB Output is correct
5 Correct 6 ms 5724 KB Output is correct
6 Correct 8 ms 6236 KB Output is correct
7 Correct 8 ms 6492 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 2 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 7 ms 5592 KB Output is correct
15 Correct 7 ms 5464 KB Output is correct
16 Correct 7 ms 5492 KB Output is correct
17 Correct 7 ms 5468 KB Output is correct
18 Correct 7 ms 5596 KB Output is correct
19 Correct 5 ms 4956 KB Output is correct
20 Correct 5 ms 5032 KB Output is correct
21 Correct 6 ms 5084 KB Output is correct
22 Correct 4 ms 5000 KB Output is correct
23 Correct 4 ms 4956 KB Output is correct
24 Correct 5 ms 4956 KB Output is correct
25 Correct 5 ms 4828 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 137 ms 19564 KB Output is correct
28 Correct 187 ms 19900 KB Output is correct
29 Correct 158 ms 20352 KB Output is correct
30 Correct 160 ms 20412 KB Output is correct
31 Correct 214 ms 20980 KB Output is correct
32 Correct 207 ms 21076 KB Output is correct
33 Correct 1 ms 4440 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 4700 KB Output is correct
39 Correct 167 ms 19792 KB Output is correct
40 Correct 188 ms 21356 KB Output is correct
41 Correct 167 ms 21068 KB Output is correct
42 Correct 171 ms 21184 KB Output is correct
43 Correct 179 ms 20416 KB Output is correct
44 Correct 161 ms 20248 KB Output is correct
45 Correct 138 ms 21040 KB Output is correct
46 Correct 177 ms 21788 KB Output is correct
47 Correct 114 ms 19636 KB Output is correct
48 Correct 119 ms 21160 KB Output is correct
49 Correct 150 ms 19004 KB Output is correct
50 Correct 135 ms 18620 KB Output is correct
51 Correct 129 ms 19384 KB Output is correct
52 Correct 126 ms 19888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4556 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 4564 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 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4556 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 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 2 ms 4528 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4568 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 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 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 1 ms 4556 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 4564 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 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4556 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 5 ms 4956 KB Output is correct
18 Correct 8 ms 5820 KB Output is correct
19 Correct 6 ms 5724 KB Output is correct
20 Correct 6 ms 5724 KB Output is correct
21 Correct 8 ms 6236 KB Output is correct
22 Correct 8 ms 6492 KB Output is correct
23 Correct 1 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 2 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 7 ms 5592 KB Output is correct
30 Correct 7 ms 5464 KB Output is correct
31 Correct 7 ms 5492 KB Output is correct
32 Correct 7 ms 5468 KB Output is correct
33 Correct 7 ms 5596 KB Output is correct
34 Correct 5 ms 4956 KB Output is correct
35 Correct 5 ms 5032 KB Output is correct
36 Correct 6 ms 5084 KB Output is correct
37 Correct 4 ms 5000 KB Output is correct
38 Correct 4 ms 4956 KB Output is correct
39 Correct 5 ms 4956 KB Output is correct
40 Correct 5 ms 4828 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 5 ms 4956 KB Output is correct
43 Correct 12 ms 6812 KB Output is correct
44 Correct 10 ms 6744 KB Output is correct
45 Correct 9 ms 6744 KB Output is correct
46 Correct 12 ms 6492 KB Output is correct
47 Correct 9 ms 6632 KB Output is correct
48 Correct 1 ms 4440 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 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 9 ms 6492 KB Output is correct
55 Correct 11 ms 6484 KB Output is correct
56 Correct 10 ms 6748 KB Output is correct
57 Correct 9 ms 6748 KB Output is correct
58 Correct 9 ms 6748 KB Output is correct
59 Correct 5 ms 4956 KB Output is correct
60 Correct 5 ms 5208 KB Output is correct
61 Correct 5 ms 5084 KB Output is correct
62 Correct 6 ms 5212 KB Output is correct
63 Correct 6 ms 5168 KB Output is correct
64 Correct 7 ms 5212 KB Output is correct
65 Correct 5 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4556 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 4564 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 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4556 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 176 ms 21784 KB Output is correct
17 Correct 157 ms 21684 KB Output is correct
18 Correct 163 ms 22952 KB Output is correct
19 Correct 139 ms 22304 KB Output is correct
20 Correct 133 ms 24000 KB Output is correct
21 Correct 166 ms 22320 KB Output is correct
22 Correct 160 ms 22188 KB Output is correct
23 Correct 130 ms 22588 KB Output is correct
24 Correct 165 ms 23920 KB Output is correct
25 Correct 129 ms 22444 KB Output is correct
26 Correct 157 ms 22692 KB Output is correct
27 Correct 130 ms 22664 KB Output is correct
28 Correct 162 ms 22712 KB Output is correct
29 Correct 163 ms 23932 KB Output is correct
30 Correct 128 ms 23216 KB Output is correct
31 Correct 173 ms 23060 KB Output is correct
32 Correct 132 ms 23620 KB Output is correct
33 Correct 160 ms 23292 KB Output is correct
34 Correct 129 ms 24292 KB Output is correct
35 Correct 167 ms 23456 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 5 ms 4956 KB Output is correct
38 Correct 8 ms 5820 KB Output is correct
39 Correct 6 ms 5724 KB Output is correct
40 Correct 6 ms 5724 KB Output is correct
41 Correct 8 ms 6236 KB Output is correct
42 Correct 8 ms 6492 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 2 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 7 ms 5592 KB Output is correct
50 Correct 7 ms 5464 KB Output is correct
51 Correct 7 ms 5492 KB Output is correct
52 Correct 7 ms 5468 KB Output is correct
53 Correct 7 ms 5596 KB Output is correct
54 Correct 5 ms 4956 KB Output is correct
55 Correct 5 ms 5032 KB Output is correct
56 Correct 6 ms 5084 KB Output is correct
57 Correct 4 ms 5000 KB Output is correct
58 Correct 4 ms 4956 KB Output is correct
59 Correct 5 ms 4956 KB Output is correct
60 Correct 5 ms 4828 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 137 ms 19564 KB Output is correct
63 Correct 187 ms 19900 KB Output is correct
64 Correct 158 ms 20352 KB Output is correct
65 Correct 160 ms 20412 KB Output is correct
66 Correct 214 ms 20980 KB Output is correct
67 Correct 207 ms 21076 KB Output is correct
68 Correct 1 ms 4440 KB Output is correct
69 Correct 1 ms 4444 KB Output is correct
70 Correct 1 ms 4444 KB Output is correct
71 Correct 1 ms 4444 KB Output is correct
72 Correct 1 ms 4444 KB Output is correct
73 Correct 1 ms 4700 KB Output is correct
74 Correct 167 ms 19792 KB Output is correct
75 Correct 188 ms 21356 KB Output is correct
76 Correct 167 ms 21068 KB Output is correct
77 Correct 171 ms 21184 KB Output is correct
78 Correct 179 ms 20416 KB Output is correct
79 Correct 161 ms 20248 KB Output is correct
80 Correct 138 ms 21040 KB Output is correct
81 Correct 177 ms 21788 KB Output is correct
82 Correct 114 ms 19636 KB Output is correct
83 Correct 119 ms 21160 KB Output is correct
84 Correct 150 ms 19004 KB Output is correct
85 Correct 135 ms 18620 KB Output is correct
86 Correct 129 ms 19384 KB Output is correct
87 Correct 126 ms 19888 KB Output is correct
88 Correct 1 ms 4444 KB Output is correct
89 Correct 1 ms 4444 KB Output is correct
90 Correct 1 ms 4440 KB Output is correct
91 Correct 2 ms 4528 KB Output is correct
92 Correct 1 ms 4444 KB Output is correct
93 Correct 1 ms 4444 KB Output is correct
94 Correct 1 ms 4444 KB Output is correct
95 Correct 1 ms 4568 KB Output is correct
96 Correct 1 ms 4444 KB Output is correct
97 Correct 1 ms 4444 KB Output is correct
98 Correct 1 ms 4444 KB Output is correct
99 Correct 1 ms 4444 KB Output is correct
100 Correct 1 ms 4444 KB Output is correct
101 Correct 1 ms 4444 KB Output is correct
102 Correct 1 ms 4444 KB Output is correct
103 Correct 1 ms 4444 KB Output is correct
104 Correct 5 ms 4956 KB Output is correct
105 Correct 12 ms 6812 KB Output is correct
106 Correct 10 ms 6744 KB Output is correct
107 Correct 9 ms 6744 KB Output is correct
108 Correct 12 ms 6492 KB Output is correct
109 Correct 9 ms 6632 KB Output is correct
110 Correct 1 ms 4440 KB Output is correct
111 Correct 1 ms 4444 KB Output is correct
112 Correct 1 ms 4444 KB Output is correct
113 Correct 1 ms 4444 KB Output is correct
114 Correct 1 ms 4444 KB Output is correct
115 Correct 1 ms 4444 KB Output is correct
116 Correct 9 ms 6492 KB Output is correct
117 Correct 11 ms 6484 KB Output is correct
118 Correct 10 ms 6748 KB Output is correct
119 Correct 9 ms 6748 KB Output is correct
120 Correct 9 ms 6748 KB Output is correct
121 Correct 5 ms 4956 KB Output is correct
122 Correct 5 ms 5208 KB Output is correct
123 Correct 5 ms 5084 KB Output is correct
124 Correct 6 ms 5212 KB Output is correct
125 Correct 6 ms 5168 KB Output is correct
126 Correct 7 ms 5212 KB Output is correct
127 Correct 5 ms 5212 KB Output is correct
128 Correct 1 ms 4440 KB Output is correct
129 Correct 231 ms 24544 KB Output is correct
130 Correct 557 ms 70580 KB Output is correct
131 Correct 516 ms 70072 KB Output is correct
132 Correct 553 ms 70488 KB Output is correct
133 Correct 609 ms 71096 KB Output is correct
134 Correct 500 ms 70576 KB Output is correct
135 Correct 1 ms 4444 KB Output is correct
136 Correct 2 ms 4444 KB Output is correct
137 Correct 1 ms 4440 KB Output is correct
138 Correct 1 ms 4444 KB Output is correct
139 Correct 1 ms 4444 KB Output is correct
140 Correct 1 ms 4556 KB Output is correct
141 Correct 546 ms 70624 KB Output is correct
142 Correct 567 ms 69976 KB Output is correct
143 Correct 512 ms 71228 KB Output is correct
144 Correct 543 ms 71696 KB Output is correct
145 Correct 543 ms 71468 KB Output is correct
146 Correct 411 ms 67252 KB Output is correct
147 Correct 430 ms 69064 KB Output is correct
148 Correct 445 ms 68956 KB Output is correct
149 Correct 226 ms 25280 KB Output is correct
150 Correct 149 ms 23908 KB Output is correct
151 Correct 135 ms 23324 KB Output is correct
152 Correct 201 ms 24500 KB Output is correct
153 Correct 195 ms 24188 KB Output is correct
154 Correct 159 ms 24252 KB Output is correct
155 Correct 229 ms 23992 KB Output is correct