Submission #1103836

# Submission time Handle Problem Language Result Execution time Memory
1103836 2024-10-22T01:36:02 Z haianhnguyen08102007 Fuel Station (NOI20_fuelstation) C++17
100 / 100
489 ms 61220 KB
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
vector<pair<ll, ll> > vec;
struct node {
	ll s, e, m;
	ll mn, lz;
	node *l, *r;
	node(ll _s, ll _e): s(_s), e(_e), m((_s+_e)/2), lz(0) {
		if (s == e) {
			mn = -vec[s].first;
			return;
		}
		l = new node(s, m);
		r = new node(m+1, e);
		mn = min(l->mn, r->mn);
	}
	void prop() {
		l->update(s, m, lz);
		r->update(m+1, e, lz);
		lz = 0;
		mn = min(l->mn, r->mn);
	}
	void update(ll x, ll y, ll v) {
		if (x > y) return;
		if (x <= s && y >= e) {
			mn += v;
			lz += v;
			return;
		}
		if (lz != 0) prop();
		if (x <= m) l->update(x, y, v);
		if (y >= m+1) r->update(x, y, v);
		mn = min(l->mn, r->mn);
	}
};
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n, d, x, a, b, ans;
	vector<tuple<ll, ll, ll> > vec2;
	cin >> n >> d;
	ans = d;
	for (ll i=0; i<n; i++) {
		cin >> x >> a >> b;
		vec.emplace_back(x, i);
		vec2.emplace_back(b, a, x);
	}
	vec.emplace_back(d, n);
	vec2.emplace_back(2000000000, 0, d);
	sort(vec.begin(), vec.end());
	ll cnt = n+1;
	for (ll i=n; i>=0; i--) {
		if (i != n && vec[i].first != vec[i+1].first) cnt = i + 1;
		get<2>(vec2[vec[i].second]) = cnt;
	}
	sort(vec2.begin(), vec2.end());
	node *root = new node(0, n);
	for (ll i=0; i<n; i++) {
		root->update(get<2>(vec2[i]), n, get<1>(vec2[i]));		
	}
	ll left = 0;
	for (ll i=0; i<=n; i++) {
		root->update(0, n, get<0>(vec2[i]) - (i == 0 ? 0 : get<0>(vec2[i-1])));
		if (i < n-1 && get<0>(vec2[i]) == get<0>(vec2[i+1])) continue;
		while (get<0>(vec2[left]) != get<0>(vec2[i])) {
			root->update(get<2>(vec2[left]), n, -get<1>(vec2[left]));
			left++;
		}
		if (root->mn < 0) continue;
		ans = min(ans, get<0>(vec2[i]) - root->mn);
	}
	cout << ans;		
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 385 ms 52212 KB Output is correct
2 Correct 423 ms 60700 KB Output is correct
3 Correct 436 ms 60704 KB Output is correct
4 Correct 336 ms 60640 KB Output is correct
5 Correct 342 ms 61152 KB Output is correct
6 Correct 417 ms 59936 KB Output is correct
7 Correct 395 ms 60192 KB Output is correct
8 Correct 389 ms 60524 KB Output is correct
9 Correct 374 ms 61192 KB Output is correct
10 Correct 357 ms 59976 KB Output is correct
11 Correct 386 ms 60084 KB Output is correct
12 Correct 351 ms 60740 KB Output is correct
13 Correct 374 ms 59980 KB Output is correct
14 Correct 367 ms 60696 KB Output is correct
15 Correct 313 ms 60588 KB Output is correct
16 Correct 365 ms 61212 KB Output is correct
17 Correct 318 ms 61220 KB Output is correct
18 Correct 370 ms 60700 KB Output is correct
19 Correct 311 ms 60704 KB Output is correct
20 Correct 339 ms 60708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 9 ms 2016 KB Output is correct
3 Correct 9 ms 2248 KB Output is correct
4 Correct 10 ms 2016 KB Output is correct
5 Correct 9 ms 2232 KB Output is correct
6 Correct 11 ms 2016 KB Output is correct
7 Correct 9 ms 2016 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 9 ms 2016 KB Output is correct
15 Correct 9 ms 2016 KB Output is correct
16 Correct 9 ms 2016 KB Output is correct
17 Correct 10 ms 2016 KB Output is correct
18 Correct 9 ms 2156 KB Output is correct
19 Correct 9 ms 2016 KB Output is correct
20 Correct 9 ms 2272 KB Output is correct
21 Correct 9 ms 2272 KB Output is correct
22 Correct 10 ms 2016 KB Output is correct
23 Correct 9 ms 2016 KB Output is correct
24 Correct 9 ms 2152 KB Output is correct
25 Correct 9 ms 2016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 9 ms 2016 KB Output is correct
3 Correct 9 ms 2248 KB Output is correct
4 Correct 10 ms 2016 KB Output is correct
5 Correct 9 ms 2232 KB Output is correct
6 Correct 11 ms 2016 KB Output is correct
7 Correct 9 ms 2016 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 9 ms 2016 KB Output is correct
15 Correct 9 ms 2016 KB Output is correct
16 Correct 9 ms 2016 KB Output is correct
17 Correct 10 ms 2016 KB Output is correct
18 Correct 9 ms 2156 KB Output is correct
19 Correct 9 ms 2016 KB Output is correct
20 Correct 9 ms 2272 KB Output is correct
21 Correct 9 ms 2272 KB Output is correct
22 Correct 10 ms 2016 KB Output is correct
23 Correct 9 ms 2016 KB Output is correct
24 Correct 9 ms 2152 KB Output is correct
25 Correct 9 ms 2016 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 336 ms 56616 KB Output is correct
28 Correct 387 ms 56256 KB Output is correct
29 Correct 355 ms 56156 KB Output is correct
30 Correct 379 ms 56100 KB Output is correct
31 Correct 352 ms 56604 KB Output is correct
32 Correct 380 ms 56352 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 504 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 339 ms 56616 KB Output is correct
40 Correct 359 ms 56608 KB Output is correct
41 Correct 348 ms 56692 KB Output is correct
42 Correct 328 ms 56508 KB Output is correct
43 Correct 374 ms 56604 KB Output is correct
44 Correct 321 ms 56048 KB Output is correct
45 Correct 332 ms 55848 KB Output is correct
46 Correct 346 ms 56744 KB Output is correct
47 Correct 282 ms 58140 KB Output is correct
48 Correct 277 ms 58172 KB Output is correct
49 Correct 317 ms 55976 KB Output is correct
50 Correct 307 ms 56352 KB Output is correct
51 Correct 311 ms 56352 KB Output is correct
52 Correct 319 ms 56096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 420 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 592 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 504 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 9 ms 2016 KB Output is correct
18 Correct 9 ms 2248 KB Output is correct
19 Correct 10 ms 2016 KB Output is correct
20 Correct 9 ms 2232 KB Output is correct
21 Correct 11 ms 2016 KB Output is correct
22 Correct 9 ms 2016 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 9 ms 2016 KB Output is correct
30 Correct 9 ms 2016 KB Output is correct
31 Correct 9 ms 2016 KB Output is correct
32 Correct 10 ms 2016 KB Output is correct
33 Correct 9 ms 2156 KB Output is correct
34 Correct 9 ms 2016 KB Output is correct
35 Correct 9 ms 2272 KB Output is correct
36 Correct 9 ms 2272 KB Output is correct
37 Correct 10 ms 2016 KB Output is correct
38 Correct 9 ms 2016 KB Output is correct
39 Correct 9 ms 2152 KB Output is correct
40 Correct 9 ms 2016 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 9 ms 2348 KB Output is correct
43 Correct 10 ms 2272 KB Output is correct
44 Correct 15 ms 2272 KB Output is correct
45 Correct 12 ms 2368 KB Output is correct
46 Correct 9 ms 2272 KB Output is correct
47 Correct 12 ms 2272 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 2 ms 336 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 10 ms 2272 KB Output is correct
55 Correct 10 ms 2272 KB Output is correct
56 Correct 11 ms 2440 KB Output is correct
57 Correct 11 ms 2272 KB Output is correct
58 Correct 9 ms 2272 KB Output is correct
59 Correct 10 ms 2312 KB Output is correct
60 Correct 10 ms 2272 KB Output is correct
61 Correct 14 ms 2272 KB Output is correct
62 Correct 9 ms 2312 KB Output is correct
63 Correct 10 ms 2272 KB Output is correct
64 Correct 10 ms 2272 KB Output is correct
65 Correct 9 ms 2272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 385 ms 52212 KB Output is correct
17 Correct 423 ms 60700 KB Output is correct
18 Correct 436 ms 60704 KB Output is correct
19 Correct 336 ms 60640 KB Output is correct
20 Correct 342 ms 61152 KB Output is correct
21 Correct 417 ms 59936 KB Output is correct
22 Correct 395 ms 60192 KB Output is correct
23 Correct 389 ms 60524 KB Output is correct
24 Correct 374 ms 61192 KB Output is correct
25 Correct 357 ms 59976 KB Output is correct
26 Correct 386 ms 60084 KB Output is correct
27 Correct 351 ms 60740 KB Output is correct
28 Correct 374 ms 59980 KB Output is correct
29 Correct 367 ms 60696 KB Output is correct
30 Correct 313 ms 60588 KB Output is correct
31 Correct 365 ms 61212 KB Output is correct
32 Correct 318 ms 61220 KB Output is correct
33 Correct 370 ms 60700 KB Output is correct
34 Correct 311 ms 60704 KB Output is correct
35 Correct 339 ms 60708 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 9 ms 2016 KB Output is correct
38 Correct 9 ms 2248 KB Output is correct
39 Correct 10 ms 2016 KB Output is correct
40 Correct 9 ms 2232 KB Output is correct
41 Correct 11 ms 2016 KB Output is correct
42 Correct 9 ms 2016 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 9 ms 2016 KB Output is correct
50 Correct 9 ms 2016 KB Output is correct
51 Correct 9 ms 2016 KB Output is correct
52 Correct 10 ms 2016 KB Output is correct
53 Correct 9 ms 2156 KB Output is correct
54 Correct 9 ms 2016 KB Output is correct
55 Correct 9 ms 2272 KB Output is correct
56 Correct 9 ms 2272 KB Output is correct
57 Correct 10 ms 2016 KB Output is correct
58 Correct 9 ms 2016 KB Output is correct
59 Correct 9 ms 2152 KB Output is correct
60 Correct 9 ms 2016 KB Output is correct
61 Correct 1 ms 336 KB Output is correct
62 Correct 336 ms 56616 KB Output is correct
63 Correct 387 ms 56256 KB Output is correct
64 Correct 355 ms 56156 KB Output is correct
65 Correct 379 ms 56100 KB Output is correct
66 Correct 352 ms 56604 KB Output is correct
67 Correct 380 ms 56352 KB Output is correct
68 Correct 1 ms 336 KB Output is correct
69 Correct 1 ms 336 KB Output is correct
70 Correct 1 ms 336 KB Output is correct
71 Correct 1 ms 336 KB Output is correct
72 Correct 1 ms 504 KB Output is correct
73 Correct 1 ms 336 KB Output is correct
74 Correct 339 ms 56616 KB Output is correct
75 Correct 359 ms 56608 KB Output is correct
76 Correct 348 ms 56692 KB Output is correct
77 Correct 328 ms 56508 KB Output is correct
78 Correct 374 ms 56604 KB Output is correct
79 Correct 321 ms 56048 KB Output is correct
80 Correct 332 ms 55848 KB Output is correct
81 Correct 346 ms 56744 KB Output is correct
82 Correct 282 ms 58140 KB Output is correct
83 Correct 277 ms 58172 KB Output is correct
84 Correct 317 ms 55976 KB Output is correct
85 Correct 307 ms 56352 KB Output is correct
86 Correct 311 ms 56352 KB Output is correct
87 Correct 319 ms 56096 KB Output is correct
88 Correct 1 ms 336 KB Output is correct
89 Correct 1 ms 336 KB Output is correct
90 Correct 1 ms 336 KB Output is correct
91 Correct 1 ms 420 KB Output is correct
92 Correct 1 ms 336 KB Output is correct
93 Correct 1 ms 336 KB Output is correct
94 Correct 1 ms 336 KB Output is correct
95 Correct 1 ms 336 KB Output is correct
96 Correct 1 ms 336 KB Output is correct
97 Correct 1 ms 592 KB Output is correct
98 Correct 1 ms 336 KB Output is correct
99 Correct 1 ms 336 KB Output is correct
100 Correct 1 ms 504 KB Output is correct
101 Correct 2 ms 336 KB Output is correct
102 Correct 1 ms 336 KB Output is correct
103 Correct 1 ms 336 KB Output is correct
104 Correct 9 ms 2348 KB Output is correct
105 Correct 10 ms 2272 KB Output is correct
106 Correct 15 ms 2272 KB Output is correct
107 Correct 12 ms 2368 KB Output is correct
108 Correct 9 ms 2272 KB Output is correct
109 Correct 12 ms 2272 KB Output is correct
110 Correct 1 ms 336 KB Output is correct
111 Correct 1 ms 336 KB Output is correct
112 Correct 2 ms 336 KB Output is correct
113 Correct 1 ms 336 KB Output is correct
114 Correct 1 ms 336 KB Output is correct
115 Correct 1 ms 336 KB Output is correct
116 Correct 10 ms 2272 KB Output is correct
117 Correct 10 ms 2272 KB Output is correct
118 Correct 11 ms 2440 KB Output is correct
119 Correct 11 ms 2272 KB Output is correct
120 Correct 9 ms 2272 KB Output is correct
121 Correct 10 ms 2312 KB Output is correct
122 Correct 10 ms 2272 KB Output is correct
123 Correct 14 ms 2272 KB Output is correct
124 Correct 9 ms 2312 KB Output is correct
125 Correct 10 ms 2272 KB Output is correct
126 Correct 10 ms 2272 KB Output is correct
127 Correct 9 ms 2272 KB Output is correct
128 Correct 1 ms 336 KB Output is correct
129 Correct 367 ms 59680 KB Output is correct
130 Correct 489 ms 60264 KB Output is correct
131 Correct 485 ms 60916 KB Output is correct
132 Correct 485 ms 60448 KB Output is correct
133 Correct 465 ms 60356 KB Output is correct
134 Correct 441 ms 60956 KB Output is correct
135 Correct 1 ms 336 KB Output is correct
136 Correct 1 ms 336 KB Output is correct
137 Correct 1 ms 336 KB Output is correct
138 Correct 1 ms 336 KB Output is correct
139 Correct 1 ms 336 KB Output is correct
140 Correct 1 ms 336 KB Output is correct
141 Correct 460 ms 60988 KB Output is correct
142 Correct 464 ms 60596 KB Output is correct
143 Correct 479 ms 61104 KB Output is correct
144 Correct 468 ms 60956 KB Output is correct
145 Correct 479 ms 60960 KB Output is correct
146 Correct 401 ms 59164 KB Output is correct
147 Correct 369 ms 60004 KB Output is correct
148 Correct 416 ms 59420 KB Output is correct
149 Correct 396 ms 60488 KB Output is correct
150 Correct 340 ms 60600 KB Output is correct
151 Correct 335 ms 60700 KB Output is correct
152 Correct 349 ms 60328 KB Output is correct
153 Correct 314 ms 60376 KB Output is correct
154 Correct 311 ms 60236 KB Output is correct
155 Correct 363 ms 60444 KB Output is correct