답안 #333010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333010 2020-12-04T08:51:40 Z Cantfindme Fuel Station (NOI20_fuelstation) C++17
100 / 100
728 ms 56336 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 300010;
typedef pair<int,pi> pii;
#define p(x,y,z) pii(x,pi(y,z))

const int INF = LLONG_MAX/2;

int n,d;
vector <pii> v; //Bi, pos, Ai
vector <int> posv;

struct node {
	int s,m,e,v, lazy;
	node *l, *r;
	node(int _s, int _e) {
		s = _s; e = _e; m = (s+e)/2;
		v = lazy = 0;
		if (s != e) {
			l = new node(s,m);
			r = new node(m+1,e);
		}
	}
	
	void push() {
		if (lazy == 0) return;
		v += lazy;
		if (s != e) {
			l -> lazy += lazy;
			r -> lazy += lazy;
		}
		lazy = 0;
	}
	
	void up(int x, int y, int newv) {
		if (s == x and e == y) lazy += newv;
		else {
			if (x > m) r -> up(x,y,newv);
			else if (y <= m) l -> up(x,y,newv);
			else l -> up(x,m,newv), r -> up(m+1,y,newv);
			l -> push(); 
			r -> push();
			v = min(l -> v, r -> v);
		}
	}
	
	int rmq() {
		push();
		return v;
	}
}*root;

int32_t main() {
	FAST
	cin >> n >> d;
	for (int i =0;i<n;i++) {
		int pos,a,b; cin >> pos >> a >> b;
		v.push_back(p(b,pos,a));
		posv.push_back(pos);
	}
	v.push_back(p(d,d,0));
	posv.push_back(d);
	root = new node(0,n);
	//cout << "HELLO\n";
	
	sort(v.rbegin(),v.rend());
	sort(posv.begin(),posv.end());
	
	for (int i =0;i<=n;i++) {
		//cout << i << "\n";
		root -> up(i,i,-posv[i]);
	}
	
	int prevf = 0;
	int ans = INF;
	for (int i =0;i<(int)v.size();i++) {
		int curf = v[i].f, x = v[i].s.f, ai = v[i].s.s;
		
		//cout << "NEW: " << curf << " " << x << " " << ai << "\n";
		root -> up(0ll,n, (curf - prevf));
		int indx = lower_bound(posv.begin(),posv.end(),x) - posv.begin();
		
		if (indx+1 <= n) root -> up(indx+1,n,ai);
		
		int extra = root -> rmq();
		if (extra >= 0) {
			ans = min(ans, curf - extra); 
		}
	
		prevf = curf;
	}
	cout << ans;
}





# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 347 ms 55712 KB Output is correct
2 Correct 343 ms 55680 KB Output is correct
3 Correct 341 ms 55680 KB Output is correct
4 Correct 332 ms 55832 KB Output is correct
5 Correct 326 ms 56336 KB Output is correct
6 Correct 355 ms 55316 KB Output is correct
7 Correct 346 ms 55168 KB Output is correct
8 Correct 324 ms 55680 KB Output is correct
9 Correct 342 ms 56320 KB Output is correct
10 Correct 325 ms 55168 KB Output is correct
11 Correct 339 ms 55296 KB Output is correct
12 Correct 322 ms 55808 KB Output is correct
13 Correct 341 ms 55172 KB Output is correct
14 Correct 336 ms 55808 KB Output is correct
15 Correct 337 ms 55808 KB Output is correct
16 Correct 336 ms 56320 KB Output is correct
17 Correct 329 ms 56320 KB Output is correct
18 Correct 340 ms 55828 KB Output is correct
19 Correct 337 ms 55808 KB Output is correct
20 Correct 338 ms 55812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 11 ms 2088 KB Output is correct
3 Correct 13 ms 2088 KB Output is correct
4 Correct 12 ms 2088 KB Output is correct
5 Correct 12 ms 2088 KB Output is correct
6 Correct 13 ms 2088 KB Output is correct
7 Correct 86 ms 2088 KB Output is correct
8 Correct 34 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 35 ms 364 KB Output is correct
13 Correct 34 ms 364 KB Output is correct
14 Correct 75 ms 2088 KB Output is correct
15 Correct 79 ms 2108 KB Output is correct
16 Correct 13 ms 2100 KB Output is correct
17 Correct 46 ms 2108 KB Output is correct
18 Correct 12 ms 2088 KB Output is correct
19 Correct 11 ms 2216 KB Output is correct
20 Correct 10 ms 2088 KB Output is correct
21 Correct 10 ms 2088 KB Output is correct
22 Correct 10 ms 2088 KB Output is correct
23 Correct 10 ms 2088 KB Output is correct
24 Correct 11 ms 2088 KB Output is correct
25 Correct 11 ms 2088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 11 ms 2088 KB Output is correct
3 Correct 13 ms 2088 KB Output is correct
4 Correct 12 ms 2088 KB Output is correct
5 Correct 12 ms 2088 KB Output is correct
6 Correct 13 ms 2088 KB Output is correct
7 Correct 86 ms 2088 KB Output is correct
8 Correct 34 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 35 ms 364 KB Output is correct
13 Correct 34 ms 364 KB Output is correct
14 Correct 75 ms 2088 KB Output is correct
15 Correct 79 ms 2108 KB Output is correct
16 Correct 13 ms 2100 KB Output is correct
17 Correct 46 ms 2108 KB Output is correct
18 Correct 12 ms 2088 KB Output is correct
19 Correct 11 ms 2216 KB Output is correct
20 Correct 10 ms 2088 KB Output is correct
21 Correct 10 ms 2088 KB Output is correct
22 Correct 10 ms 2088 KB Output is correct
23 Correct 10 ms 2088 KB Output is correct
24 Correct 11 ms 2088 KB Output is correct
25 Correct 11 ms 2088 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 503 ms 51584 KB Output is correct
28 Correct 630 ms 51328 KB Output is correct
29 Correct 600 ms 51072 KB Output is correct
30 Correct 603 ms 51200 KB Output is correct
31 Correct 669 ms 51672 KB Output is correct
32 Correct 661 ms 51328 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 543 ms 51888 KB Output is correct
40 Correct 616 ms 51732 KB Output is correct
41 Correct 570 ms 51712 KB Output is correct
42 Correct 524 ms 51584 KB Output is correct
43 Correct 636 ms 51712 KB Output is correct
44 Correct 428 ms 51200 KB Output is correct
45 Correct 300 ms 50816 KB Output is correct
46 Correct 530 ms 51712 KB Output is correct
47 Correct 312 ms 53120 KB Output is correct
48 Correct 310 ms 53120 KB Output is correct
49 Correct 544 ms 50944 KB Output is correct
50 Correct 452 ms 51328 KB Output is correct
51 Correct 475 ms 51328 KB Output is correct
52 Correct 431 ms 51232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 34 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 34 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 11 ms 2088 KB Output is correct
18 Correct 13 ms 2088 KB Output is correct
19 Correct 12 ms 2088 KB Output is correct
20 Correct 12 ms 2088 KB Output is correct
21 Correct 13 ms 2088 KB Output is correct
22 Correct 86 ms 2088 KB Output is correct
23 Correct 34 ms 384 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 35 ms 364 KB Output is correct
28 Correct 34 ms 364 KB Output is correct
29 Correct 75 ms 2088 KB Output is correct
30 Correct 79 ms 2108 KB Output is correct
31 Correct 13 ms 2100 KB Output is correct
32 Correct 46 ms 2108 KB Output is correct
33 Correct 12 ms 2088 KB Output is correct
34 Correct 11 ms 2216 KB Output is correct
35 Correct 10 ms 2088 KB Output is correct
36 Correct 10 ms 2088 KB Output is correct
37 Correct 10 ms 2088 KB Output is correct
38 Correct 10 ms 2088 KB Output is correct
39 Correct 11 ms 2088 KB Output is correct
40 Correct 11 ms 2088 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 44 ms 2088 KB Output is correct
43 Correct 47 ms 2088 KB Output is correct
44 Correct 13 ms 2236 KB Output is correct
45 Correct 13 ms 2216 KB Output is correct
46 Correct 47 ms 2216 KB Output is correct
47 Correct 13 ms 2216 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 35 ms 364 KB Output is correct
53 Correct 34 ms 364 KB Output is correct
54 Correct 45 ms 2216 KB Output is correct
55 Correct 13 ms 2216 KB Output is correct
56 Correct 13 ms 2216 KB Output is correct
57 Correct 14 ms 2216 KB Output is correct
58 Correct 13 ms 2216 KB Output is correct
59 Correct 11 ms 2088 KB Output is correct
60 Correct 10 ms 2216 KB Output is correct
61 Correct 11 ms 2216 KB Output is correct
62 Correct 46 ms 2216 KB Output is correct
63 Correct 12 ms 2236 KB Output is correct
64 Correct 13 ms 2216 KB Output is correct
65 Correct 46 ms 2088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 347 ms 55712 KB Output is correct
17 Correct 343 ms 55680 KB Output is correct
18 Correct 341 ms 55680 KB Output is correct
19 Correct 332 ms 55832 KB Output is correct
20 Correct 326 ms 56336 KB Output is correct
21 Correct 355 ms 55316 KB Output is correct
22 Correct 346 ms 55168 KB Output is correct
23 Correct 324 ms 55680 KB Output is correct
24 Correct 342 ms 56320 KB Output is correct
25 Correct 325 ms 55168 KB Output is correct
26 Correct 339 ms 55296 KB Output is correct
27 Correct 322 ms 55808 KB Output is correct
28 Correct 341 ms 55172 KB Output is correct
29 Correct 336 ms 55808 KB Output is correct
30 Correct 337 ms 55808 KB Output is correct
31 Correct 336 ms 56320 KB Output is correct
32 Correct 329 ms 56320 KB Output is correct
33 Correct 340 ms 55828 KB Output is correct
34 Correct 337 ms 55808 KB Output is correct
35 Correct 338 ms 55812 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 11 ms 2088 KB Output is correct
38 Correct 13 ms 2088 KB Output is correct
39 Correct 12 ms 2088 KB Output is correct
40 Correct 12 ms 2088 KB Output is correct
41 Correct 13 ms 2088 KB Output is correct
42 Correct 86 ms 2088 KB Output is correct
43 Correct 34 ms 384 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 35 ms 364 KB Output is correct
48 Correct 34 ms 364 KB Output is correct
49 Correct 75 ms 2088 KB Output is correct
50 Correct 79 ms 2108 KB Output is correct
51 Correct 13 ms 2100 KB Output is correct
52 Correct 46 ms 2108 KB Output is correct
53 Correct 12 ms 2088 KB Output is correct
54 Correct 11 ms 2216 KB Output is correct
55 Correct 10 ms 2088 KB Output is correct
56 Correct 10 ms 2088 KB Output is correct
57 Correct 10 ms 2088 KB Output is correct
58 Correct 10 ms 2088 KB Output is correct
59 Correct 11 ms 2088 KB Output is correct
60 Correct 11 ms 2088 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 503 ms 51584 KB Output is correct
63 Correct 630 ms 51328 KB Output is correct
64 Correct 600 ms 51072 KB Output is correct
65 Correct 603 ms 51200 KB Output is correct
66 Correct 669 ms 51672 KB Output is correct
67 Correct 661 ms 51328 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 1 ms 364 KB Output is correct
74 Correct 543 ms 51888 KB Output is correct
75 Correct 616 ms 51732 KB Output is correct
76 Correct 570 ms 51712 KB Output is correct
77 Correct 524 ms 51584 KB Output is correct
78 Correct 636 ms 51712 KB Output is correct
79 Correct 428 ms 51200 KB Output is correct
80 Correct 300 ms 50816 KB Output is correct
81 Correct 530 ms 51712 KB Output is correct
82 Correct 312 ms 53120 KB Output is correct
83 Correct 310 ms 53120 KB Output is correct
84 Correct 544 ms 50944 KB Output is correct
85 Correct 452 ms 51328 KB Output is correct
86 Correct 475 ms 51328 KB Output is correct
87 Correct 431 ms 51232 KB Output is correct
88 Correct 1 ms 364 KB Output is correct
89 Correct 1 ms 364 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 34 ms 364 KB Output is correct
93 Correct 1 ms 364 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 1 ms 364 KB Output is correct
98 Correct 1 ms 364 KB Output is correct
99 Correct 1 ms 364 KB Output is correct
100 Correct 1 ms 364 KB Output is correct
101 Correct 1 ms 364 KB Output is correct
102 Correct 34 ms 492 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 44 ms 2088 KB Output is correct
105 Correct 47 ms 2088 KB Output is correct
106 Correct 13 ms 2236 KB Output is correct
107 Correct 13 ms 2216 KB Output is correct
108 Correct 47 ms 2216 KB Output is correct
109 Correct 13 ms 2216 KB Output is correct
110 Correct 1 ms 364 KB Output is correct
111 Correct 1 ms 364 KB Output is correct
112 Correct 1 ms 364 KB Output is correct
113 Correct 1 ms 364 KB Output is correct
114 Correct 35 ms 364 KB Output is correct
115 Correct 34 ms 364 KB Output is correct
116 Correct 45 ms 2216 KB Output is correct
117 Correct 13 ms 2216 KB Output is correct
118 Correct 13 ms 2216 KB Output is correct
119 Correct 14 ms 2216 KB Output is correct
120 Correct 13 ms 2216 KB Output is correct
121 Correct 11 ms 2088 KB Output is correct
122 Correct 10 ms 2216 KB Output is correct
123 Correct 11 ms 2216 KB Output is correct
124 Correct 46 ms 2216 KB Output is correct
125 Correct 12 ms 2236 KB Output is correct
126 Correct 13 ms 2216 KB Output is correct
127 Correct 46 ms 2088 KB Output is correct
128 Correct 35 ms 384 KB Output is correct
129 Correct 678 ms 54784 KB Output is correct
130 Correct 713 ms 55424 KB Output is correct
131 Correct 693 ms 56096 KB Output is correct
132 Correct 705 ms 55424 KB Output is correct
133 Correct 705 ms 55424 KB Output is correct
134 Correct 690 ms 56064 KB Output is correct
135 Correct 1 ms 364 KB Output is correct
136 Correct 1 ms 364 KB Output is correct
137 Correct 1 ms 364 KB Output is correct
138 Correct 1 ms 364 KB Output is correct
139 Correct 1 ms 364 KB Output is correct
140 Correct 1 ms 364 KB Output is correct
141 Correct 728 ms 56152 KB Output is correct
142 Correct 697 ms 55680 KB Output is correct
143 Correct 690 ms 56064 KB Output is correct
144 Correct 696 ms 56064 KB Output is correct
145 Correct 692 ms 56084 KB Output is correct
146 Correct 609 ms 54444 KB Output is correct
147 Correct 615 ms 55040 KB Output is correct
148 Correct 607 ms 54528 KB Output is correct
149 Correct 687 ms 55424 KB Output is correct
150 Correct 329 ms 55680 KB Output is correct
151 Correct 322 ms 55680 KB Output is correct
152 Correct 626 ms 55448 KB Output is correct
153 Correct 534 ms 55552 KB Output is correct
154 Correct 455 ms 55456 KB Output is correct
155 Correct 669 ms 55424 KB Output is correct