답안 #255325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255325 2020-07-31T17:32:10 Z model_code Fuel Station (NOI20_fuelstation) C++17
100 / 100
889 ms 49868 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;		
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 617 ms 49612 KB Output is correct
2 Correct 624 ms 49676 KB Output is correct
3 Correct 707 ms 49720 KB Output is correct
4 Correct 501 ms 49596 KB Output is correct
5 Correct 494 ms 49724 KB Output is correct
6 Correct 691 ms 49740 KB Output is correct
7 Correct 649 ms 49744 KB Output is correct
8 Correct 504 ms 49740 KB Output is correct
9 Correct 672 ms 49624 KB Output is correct
10 Correct 486 ms 49616 KB Output is correct
11 Correct 795 ms 49612 KB Output is correct
12 Correct 575 ms 49616 KB Output is correct
13 Correct 766 ms 49744 KB Output is correct
14 Correct 730 ms 49696 KB Output is correct
15 Correct 530 ms 49644 KB Output is correct
16 Correct 741 ms 49720 KB Output is correct
17 Correct 507 ms 49608 KB Output is correct
18 Correct 675 ms 49616 KB Output is correct
19 Correct 528 ms 49632 KB Output is correct
20 Correct 733 ms 49868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 11 ms 2080 KB Output is correct
3 Correct 11 ms 2080 KB Output is correct
4 Correct 11 ms 2080 KB Output is correct
5 Correct 13 ms 2080 KB Output is correct
6 Correct 11 ms 2080 KB Output is correct
7 Correct 12 ms 2080 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 11 ms 2080 KB Output is correct
15 Correct 11 ms 2080 KB Output is correct
16 Correct 11 ms 2080 KB Output is correct
17 Correct 12 ms 2080 KB Output is correct
18 Correct 12 ms 2080 KB Output is correct
19 Correct 13 ms 2080 KB Output is correct
20 Correct 13 ms 2080 KB Output is correct
21 Correct 15 ms 2080 KB Output is correct
22 Correct 14 ms 2080 KB Output is correct
23 Correct 11 ms 2080 KB Output is correct
24 Correct 11 ms 2080 KB Output is correct
25 Correct 14 ms 2080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 11 ms 2080 KB Output is correct
3 Correct 11 ms 2080 KB Output is correct
4 Correct 11 ms 2080 KB Output is correct
5 Correct 13 ms 2080 KB Output is correct
6 Correct 11 ms 2080 KB Output is correct
7 Correct 12 ms 2080 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 11 ms 2080 KB Output is correct
15 Correct 11 ms 2080 KB Output is correct
16 Correct 11 ms 2080 KB Output is correct
17 Correct 12 ms 2080 KB Output is correct
18 Correct 12 ms 2080 KB Output is correct
19 Correct 13 ms 2080 KB Output is correct
20 Correct 13 ms 2080 KB Output is correct
21 Correct 15 ms 2080 KB Output is correct
22 Correct 14 ms 2080 KB Output is correct
23 Correct 11 ms 2080 KB Output is correct
24 Correct 11 ms 2080 KB Output is correct
25 Correct 14 ms 2080 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 587 ms 49744 KB Output is correct
28 Correct 772 ms 49716 KB Output is correct
29 Correct 692 ms 49620 KB Output is correct
30 Correct 601 ms 49744 KB Output is correct
31 Correct 671 ms 49708 KB Output is correct
32 Correct 704 ms 49664 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 324 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 499 ms 49740 KB Output is correct
40 Correct 552 ms 49608 KB Output is correct
41 Correct 497 ms 49608 KB Output is correct
42 Correct 524 ms 49724 KB Output is correct
43 Correct 691 ms 49644 KB Output is correct
44 Correct 623 ms 49684 KB Output is correct
45 Correct 693 ms 49616 KB Output is correct
46 Correct 487 ms 49616 KB Output is correct
47 Correct 459 ms 49744 KB Output is correct
48 Correct 446 ms 49616 KB Output is correct
49 Correct 538 ms 49716 KB Output is correct
50 Correct 519 ms 49612 KB Output is correct
51 Correct 478 ms 49724 KB Output is correct
52 Correct 480 ms 49616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 11 ms 2080 KB Output is correct
18 Correct 11 ms 2080 KB Output is correct
19 Correct 11 ms 2080 KB Output is correct
20 Correct 13 ms 2080 KB Output is correct
21 Correct 11 ms 2080 KB Output is correct
22 Correct 12 ms 2080 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 11 ms 2080 KB Output is correct
30 Correct 11 ms 2080 KB Output is correct
31 Correct 11 ms 2080 KB Output is correct
32 Correct 12 ms 2080 KB Output is correct
33 Correct 12 ms 2080 KB Output is correct
34 Correct 13 ms 2080 KB Output is correct
35 Correct 13 ms 2080 KB Output is correct
36 Correct 15 ms 2080 KB Output is correct
37 Correct 14 ms 2080 KB Output is correct
38 Correct 11 ms 2080 KB Output is correct
39 Correct 11 ms 2080 KB Output is correct
40 Correct 14 ms 2080 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 15 ms 2080 KB Output is correct
43 Correct 17 ms 2080 KB Output is correct
44 Correct 12 ms 2080 KB Output is correct
45 Correct 13 ms 2080 KB Output is correct
46 Correct 15 ms 2080 KB Output is correct
47 Correct 17 ms 2080 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 13 ms 2080 KB Output is correct
55 Correct 15 ms 2080 KB Output is correct
56 Correct 12 ms 2080 KB Output is correct
57 Correct 12 ms 2080 KB Output is correct
58 Correct 13 ms 2080 KB Output is correct
59 Correct 14 ms 2140 KB Output is correct
60 Correct 13 ms 2080 KB Output is correct
61 Correct 14 ms 2080 KB Output is correct
62 Correct 15 ms 2080 KB Output is correct
63 Correct 12 ms 2080 KB Output is correct
64 Correct 12 ms 2080 KB Output is correct
65 Correct 16 ms 2080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 617 ms 49612 KB Output is correct
17 Correct 624 ms 49676 KB Output is correct
18 Correct 707 ms 49720 KB Output is correct
19 Correct 501 ms 49596 KB Output is correct
20 Correct 494 ms 49724 KB Output is correct
21 Correct 691 ms 49740 KB Output is correct
22 Correct 649 ms 49744 KB Output is correct
23 Correct 504 ms 49740 KB Output is correct
24 Correct 672 ms 49624 KB Output is correct
25 Correct 486 ms 49616 KB Output is correct
26 Correct 795 ms 49612 KB Output is correct
27 Correct 575 ms 49616 KB Output is correct
28 Correct 766 ms 49744 KB Output is correct
29 Correct 730 ms 49696 KB Output is correct
30 Correct 530 ms 49644 KB Output is correct
31 Correct 741 ms 49720 KB Output is correct
32 Correct 507 ms 49608 KB Output is correct
33 Correct 675 ms 49616 KB Output is correct
34 Correct 528 ms 49632 KB Output is correct
35 Correct 733 ms 49868 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 11 ms 2080 KB Output is correct
38 Correct 11 ms 2080 KB Output is correct
39 Correct 11 ms 2080 KB Output is correct
40 Correct 13 ms 2080 KB Output is correct
41 Correct 11 ms 2080 KB Output is correct
42 Correct 12 ms 2080 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 11 ms 2080 KB Output is correct
50 Correct 11 ms 2080 KB Output is correct
51 Correct 11 ms 2080 KB Output is correct
52 Correct 12 ms 2080 KB Output is correct
53 Correct 12 ms 2080 KB Output is correct
54 Correct 13 ms 2080 KB Output is correct
55 Correct 13 ms 2080 KB Output is correct
56 Correct 15 ms 2080 KB Output is correct
57 Correct 14 ms 2080 KB Output is correct
58 Correct 11 ms 2080 KB Output is correct
59 Correct 11 ms 2080 KB Output is correct
60 Correct 14 ms 2080 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 587 ms 49744 KB Output is correct
63 Correct 772 ms 49716 KB Output is correct
64 Correct 692 ms 49620 KB Output is correct
65 Correct 601 ms 49744 KB Output is correct
66 Correct 671 ms 49708 KB Output is correct
67 Correct 704 ms 49664 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 0 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 0 ms 324 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 499 ms 49740 KB Output is correct
75 Correct 552 ms 49608 KB Output is correct
76 Correct 497 ms 49608 KB Output is correct
77 Correct 524 ms 49724 KB Output is correct
78 Correct 691 ms 49644 KB Output is correct
79 Correct 623 ms 49684 KB Output is correct
80 Correct 693 ms 49616 KB Output is correct
81 Correct 487 ms 49616 KB Output is correct
82 Correct 459 ms 49744 KB Output is correct
83 Correct 446 ms 49616 KB Output is correct
84 Correct 538 ms 49716 KB Output is correct
85 Correct 519 ms 49612 KB Output is correct
86 Correct 478 ms 49724 KB Output is correct
87 Correct 480 ms 49616 KB Output is correct
88 Correct 1 ms 384 KB Output is correct
89 Correct 0 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 1 ms 384 KB Output is correct
93 Correct 0 ms 384 KB Output is correct
94 Correct 0 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 1 ms 384 KB Output is correct
98 Correct 0 ms 384 KB Output is correct
99 Correct 0 ms 384 KB Output is correct
100 Correct 1 ms 384 KB Output is correct
101 Correct 1 ms 384 KB Output is correct
102 Correct 1 ms 384 KB Output is correct
103 Correct 1 ms 384 KB Output is correct
104 Correct 15 ms 2080 KB Output is correct
105 Correct 17 ms 2080 KB Output is correct
106 Correct 12 ms 2080 KB Output is correct
107 Correct 13 ms 2080 KB Output is correct
108 Correct 15 ms 2080 KB Output is correct
109 Correct 17 ms 2080 KB Output is correct
110 Correct 0 ms 384 KB Output is correct
111 Correct 1 ms 384 KB Output is correct
112 Correct 0 ms 384 KB Output is correct
113 Correct 1 ms 384 KB Output is correct
114 Correct 1 ms 384 KB Output is correct
115 Correct 1 ms 384 KB Output is correct
116 Correct 13 ms 2080 KB Output is correct
117 Correct 15 ms 2080 KB Output is correct
118 Correct 12 ms 2080 KB Output is correct
119 Correct 12 ms 2080 KB Output is correct
120 Correct 13 ms 2080 KB Output is correct
121 Correct 14 ms 2140 KB Output is correct
122 Correct 13 ms 2080 KB Output is correct
123 Correct 14 ms 2080 KB Output is correct
124 Correct 15 ms 2080 KB Output is correct
125 Correct 12 ms 2080 KB Output is correct
126 Correct 12 ms 2080 KB Output is correct
127 Correct 16 ms 2080 KB Output is correct
128 Correct 0 ms 384 KB Output is correct
129 Correct 715 ms 49728 KB Output is correct
130 Correct 712 ms 49612 KB Output is correct
131 Correct 860 ms 49712 KB Output is correct
132 Correct 705 ms 49716 KB Output is correct
133 Correct 749 ms 49684 KB Output is correct
134 Correct 849 ms 49716 KB Output is correct
135 Correct 0 ms 384 KB Output is correct
136 Correct 2 ms 384 KB Output is correct
137 Correct 1 ms 384 KB Output is correct
138 Correct 1 ms 384 KB Output is correct
139 Correct 1 ms 384 KB Output is correct
140 Correct 1 ms 384 KB Output is correct
141 Correct 704 ms 49728 KB Output is correct
142 Correct 738 ms 49728 KB Output is correct
143 Correct 812 ms 49720 KB Output is correct
144 Correct 743 ms 49616 KB Output is correct
145 Correct 818 ms 49616 KB Output is correct
146 Correct 679 ms 49652 KB Output is correct
147 Correct 827 ms 49720 KB Output is correct
148 Correct 627 ms 49716 KB Output is correct
149 Correct 889 ms 49720 KB Output is correct
150 Correct 679 ms 49616 KB Output is correct
151 Correct 489 ms 49664 KB Output is correct
152 Correct 679 ms 49608 KB Output is correct
153 Correct 495 ms 49716 KB Output is correct
154 Correct 512 ms 49688 KB Output is correct
155 Correct 670 ms 49640 KB Output is correct