Submission #261258

# Submission time Handle Problem Language Result Execution time Memory
261258 2020-08-11T15:34:43 Z Berted Fuel Station (NOI20_fuelstation) C++14
100 / 100
2035 ms 45512 KB
#include <iostream>
#include <algorithm>
#include <map>
#define ll long long
#define pii pair<int, int>
#define ppi pair<pii, int>
#define fst first
#define snd second

using namespace std;

const int SZ = (1 << 20) + 69;

int n, d; 
ll coord[300069] = {}, seg[SZ] = {}, lz[SZ], rs = 1e18;
map<int, int> mp;
ppi dt[300069] = {};

void bld(int idx, int L, int R)
{
	if (L < R)
	{
		bld(2 * idx, L, (L + R) / 2);
		bld(2 * idx + 1, (L + R) / 2 + 1, R);
		seg[idx] = max(seg[2 * idx], seg[2 * idx + 1]);
	}
	else {seg[idx] = coord[L];}
}

void prop(int idx, int L, int R)
{
	if (lz[idx])
	{
		seg[idx] += lz[idx];
		if (L < R)
		{
			lz[2 * idx] += lz[idx];
			lz[2 * idx + 1] += lz[idx];
		}
		lz[idx] = 0;
	}
}

void upd(int idx, int L, int R, int x, int v)
{
	prop(idx, L, R);
	if (x <= R) 
	{
		if (x <= L) {lz[idx] += v; prop(idx, L, R);}
		else
		{
			int M = (L + R) / 2;
			upd(2 * idx, L, M, x, v);
			upd(2 * idx + 1, M + 1, R, x, v);
			seg[idx] = max(seg[2 * idx], seg[2 * idx + 1]);
		}
	}
}

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> d;
	rs = d;
	for (int i = 0; i < n; i++)
	{
		int x, a, b; cin >> x >> a >> b;
		mp[x] = 1;
		dt[i] = {{b, x}, a};
	}
	mp[d] = 1;
	int it = 0;
	for (auto &x : mp)
	{
		coord[it] = x.fst;
		x.snd = it++;
	}
	bld(1, 0, it - 1);
	//cout << seg[1] << "\n";
	for (int i = 0; i < n; i++)
	{
		upd(1, 0, it - 1, mp[dt[i].fst.snd] + 1, -dt[i].snd);
	}
	sort(dt, dt + n);
	//cout << seg[1] << "\n";
	for (int i = 0; i < n; i++)
	{
		if (seg[1] <= dt[i].fst.fst) {rs = min(rs, seg[1]);}
		upd(1, 0, it - 1, mp[dt[i].fst.snd] + 1, dt[i].snd);
	}
	cout << rs << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 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 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 454 ms 13480 KB Output is correct
2 Correct 450 ms 13688 KB Output is correct
3 Correct 449 ms 13432 KB Output is correct
4 Correct 320 ms 12408 KB Output is correct
5 Correct 319 ms 12920 KB Output is correct
6 Correct 442 ms 13048 KB Output is correct
7 Correct 430 ms 12920 KB Output is correct
8 Correct 311 ms 12408 KB Output is correct
9 Correct 451 ms 14072 KB Output is correct
10 Correct 333 ms 11768 KB Output is correct
11 Correct 428 ms 12980 KB Output is correct
12 Correct 334 ms 12408 KB Output is correct
13 Correct 429 ms 12920 KB Output is correct
14 Correct 433 ms 13592 KB Output is correct
15 Correct 314 ms 12408 KB Output is correct
16 Correct 448 ms 14076 KB Output is correct
17 Correct 312 ms 13048 KB Output is correct
18 Correct 442 ms 13564 KB Output is correct
19 Correct 324 ms 12408 KB Output is correct
20 Correct 464 ms 13560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 9 ms 640 KB Output is correct
3 Correct 22 ms 1664 KB Output is correct
4 Correct 21 ms 1664 KB Output is correct
5 Correct 24 ms 1664 KB Output is correct
6 Correct 17 ms 1664 KB Output is correct
7 Correct 25 ms 1664 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 1 ms 384 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 11 ms 768 KB Output is correct
16 Correct 13 ms 896 KB Output is correct
17 Correct 14 ms 1056 KB Output is correct
18 Correct 14 ms 1152 KB Output is correct
19 Correct 10 ms 640 KB Output is correct
20 Correct 11 ms 768 KB Output is correct
21 Correct 11 ms 768 KB Output is correct
22 Correct 8 ms 640 KB Output is correct
23 Correct 8 ms 640 KB Output is correct
24 Correct 9 ms 640 KB Output is correct
25 Correct 10 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 9 ms 640 KB Output is correct
3 Correct 22 ms 1664 KB Output is correct
4 Correct 21 ms 1664 KB Output is correct
5 Correct 24 ms 1664 KB Output is correct
6 Correct 17 ms 1664 KB Output is correct
7 Correct 25 ms 1664 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 1 ms 384 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 11 ms 768 KB Output is correct
16 Correct 13 ms 896 KB Output is correct
17 Correct 14 ms 1056 KB Output is correct
18 Correct 14 ms 1152 KB Output is correct
19 Correct 10 ms 640 KB Output is correct
20 Correct 11 ms 768 KB Output is correct
21 Correct 11 ms 768 KB Output is correct
22 Correct 8 ms 640 KB Output is correct
23 Correct 8 ms 640 KB Output is correct
24 Correct 9 ms 640 KB Output is correct
25 Correct 10 ms 640 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 271 ms 8184 KB Output is correct
28 Correct 421 ms 9088 KB Output is correct
29 Correct 420 ms 8688 KB Output is correct
30 Correct 412 ms 8760 KB Output is correct
31 Correct 429 ms 9364 KB Output is correct
32 Correct 463 ms 9072 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 404 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 296 ms 8440 KB Output is correct
40 Correct 309 ms 8312 KB Output is correct
41 Correct 332 ms 8312 KB Output is correct
42 Correct 304 ms 8316 KB Output is correct
43 Correct 378 ms 8824 KB Output is correct
44 Correct 380 ms 8312 KB Output is correct
45 Correct 365 ms 8312 KB Output is correct
46 Correct 283 ms 8312 KB Output is correct
47 Correct 295 ms 9720 KB Output is correct
48 Correct 290 ms 9848 KB Output is correct
49 Correct 305 ms 7800 KB Output is correct
50 Correct 272 ms 7928 KB Output is correct
51 Correct 299 ms 8056 KB Output is correct
52 Correct 288 ms 7656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 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 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 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 1 ms 384 KB Output is correct
22 Correct 1 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 1 ms 384 KB Output is correct
27 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 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 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 9 ms 640 KB Output is correct
18 Correct 22 ms 1664 KB Output is correct
19 Correct 21 ms 1664 KB Output is correct
20 Correct 24 ms 1664 KB Output is correct
21 Correct 17 ms 1664 KB Output is correct
22 Correct 25 ms 1664 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 1 ms 384 KB Output is correct
29 Correct 11 ms 768 KB Output is correct
30 Correct 11 ms 768 KB Output is correct
31 Correct 13 ms 896 KB Output is correct
32 Correct 14 ms 1056 KB Output is correct
33 Correct 14 ms 1152 KB Output is correct
34 Correct 10 ms 640 KB Output is correct
35 Correct 11 ms 768 KB Output is correct
36 Correct 11 ms 768 KB Output is correct
37 Correct 8 ms 640 KB Output is correct
38 Correct 8 ms 640 KB Output is correct
39 Correct 9 ms 640 KB Output is correct
40 Correct 10 ms 640 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 9 ms 768 KB Output is correct
43 Correct 18 ms 1792 KB Output is correct
44 Correct 21 ms 1792 KB Output is correct
45 Correct 18 ms 1824 KB Output is correct
46 Correct 20 ms 1792 KB Output is correct
47 Correct 22 ms 1896 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 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 19 ms 1792 KB Output is correct
55 Correct 18 ms 1900 KB Output is correct
56 Correct 29 ms 1792 KB Output is correct
57 Correct 20 ms 1792 KB Output is correct
58 Correct 19 ms 1792 KB Output is correct
59 Correct 10 ms 768 KB Output is correct
60 Correct 12 ms 896 KB Output is correct
61 Correct 17 ms 1024 KB Output is correct
62 Correct 11 ms 768 KB Output is correct
63 Correct 12 ms 768 KB Output is correct
64 Correct 15 ms 896 KB Output is correct
65 Correct 16 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 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 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 454 ms 13480 KB Output is correct
17 Correct 450 ms 13688 KB Output is correct
18 Correct 449 ms 13432 KB Output is correct
19 Correct 320 ms 12408 KB Output is correct
20 Correct 319 ms 12920 KB Output is correct
21 Correct 442 ms 13048 KB Output is correct
22 Correct 430 ms 12920 KB Output is correct
23 Correct 311 ms 12408 KB Output is correct
24 Correct 451 ms 14072 KB Output is correct
25 Correct 333 ms 11768 KB Output is correct
26 Correct 428 ms 12980 KB Output is correct
27 Correct 334 ms 12408 KB Output is correct
28 Correct 429 ms 12920 KB Output is correct
29 Correct 433 ms 13592 KB Output is correct
30 Correct 314 ms 12408 KB Output is correct
31 Correct 448 ms 14076 KB Output is correct
32 Correct 312 ms 13048 KB Output is correct
33 Correct 442 ms 13564 KB Output is correct
34 Correct 324 ms 12408 KB Output is correct
35 Correct 464 ms 13560 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 9 ms 640 KB Output is correct
38 Correct 22 ms 1664 KB Output is correct
39 Correct 21 ms 1664 KB Output is correct
40 Correct 24 ms 1664 KB Output is correct
41 Correct 17 ms 1664 KB Output is correct
42 Correct 25 ms 1664 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 1 ms 384 KB Output is correct
49 Correct 11 ms 768 KB Output is correct
50 Correct 11 ms 768 KB Output is correct
51 Correct 13 ms 896 KB Output is correct
52 Correct 14 ms 1056 KB Output is correct
53 Correct 14 ms 1152 KB Output is correct
54 Correct 10 ms 640 KB Output is correct
55 Correct 11 ms 768 KB Output is correct
56 Correct 11 ms 768 KB Output is correct
57 Correct 8 ms 640 KB Output is correct
58 Correct 8 ms 640 KB Output is correct
59 Correct 9 ms 640 KB Output is correct
60 Correct 10 ms 640 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 271 ms 8184 KB Output is correct
63 Correct 421 ms 9088 KB Output is correct
64 Correct 420 ms 8688 KB Output is correct
65 Correct 412 ms 8760 KB Output is correct
66 Correct 429 ms 9364 KB Output is correct
67 Correct 463 ms 9072 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 404 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 296 ms 8440 KB Output is correct
75 Correct 309 ms 8312 KB Output is correct
76 Correct 332 ms 8312 KB Output is correct
77 Correct 304 ms 8316 KB Output is correct
78 Correct 378 ms 8824 KB Output is correct
79 Correct 380 ms 8312 KB Output is correct
80 Correct 365 ms 8312 KB Output is correct
81 Correct 283 ms 8312 KB Output is correct
82 Correct 295 ms 9720 KB Output is correct
83 Correct 290 ms 9848 KB Output is correct
84 Correct 305 ms 7800 KB Output is correct
85 Correct 272 ms 7928 KB Output is correct
86 Correct 299 ms 8056 KB Output is correct
87 Correct 288 ms 7656 KB Output is correct
88 Correct 1 ms 384 KB Output is correct
89 Correct 1 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 1 ms 384 KB Output is correct
94 Correct 1 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 1 ms 384 KB Output is correct
99 Correct 1 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 9 ms 768 KB Output is correct
105 Correct 18 ms 1792 KB Output is correct
106 Correct 21 ms 1792 KB Output is correct
107 Correct 18 ms 1824 KB Output is correct
108 Correct 20 ms 1792 KB Output is correct
109 Correct 22 ms 1896 KB Output is correct
110 Correct 1 ms 384 KB Output is correct
111 Correct 1 ms 384 KB Output is correct
112 Correct 1 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 19 ms 1792 KB Output is correct
117 Correct 18 ms 1900 KB Output is correct
118 Correct 29 ms 1792 KB Output is correct
119 Correct 20 ms 1792 KB Output is correct
120 Correct 19 ms 1792 KB Output is correct
121 Correct 10 ms 768 KB Output is correct
122 Correct 12 ms 896 KB Output is correct
123 Correct 17 ms 1024 KB Output is correct
124 Correct 11 ms 768 KB Output is correct
125 Correct 12 ms 768 KB Output is correct
126 Correct 15 ms 896 KB Output is correct
127 Correct 16 ms 768 KB Output is correct
128 Correct 1 ms 384 KB Output is correct
129 Correct 535 ms 12556 KB Output is correct
130 Correct 2035 ms 44884 KB Output is correct
131 Correct 1407 ms 45376 KB Output is correct
132 Correct 1865 ms 44892 KB Output is correct
133 Correct 1858 ms 44780 KB Output is correct
134 Correct 1513 ms 45492 KB Output is correct
135 Correct 1 ms 384 KB Output is correct
136 Correct 1 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 1366 ms 45504 KB Output is correct
142 Correct 1501 ms 45304 KB Output is correct
143 Correct 1845 ms 45512 KB Output is correct
144 Correct 2019 ms 45464 KB Output is correct
145 Correct 1961 ms 45492 KB Output is correct
146 Correct 1265 ms 43152 KB Output is correct
147 Correct 1348 ms 44000 KB Output is correct
148 Correct 1427 ms 43444 KB Output is correct
149 Correct 535 ms 13268 KB Output is correct
150 Correct 362 ms 12344 KB Output is correct
151 Correct 399 ms 12408 KB Output is correct
152 Correct 587 ms 13304 KB Output is correct
153 Correct 350 ms 12024 KB Output is correct
154 Correct 327 ms 12024 KB Output is correct
155 Correct 540 ms 13176 KB Output is correct