#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = (int)5e5 + 7;
const ll inf = (ll)1e18 + 7;
int n, m;
int a[maxn], b[maxn], c[maxn], d[maxn];
int used[maxn];
ll ans;
vector <int> vec;
struct T {
ll tree[maxn * 4];
T() {
for (int i = 0; i < maxn * 4; i++) {
tree[i] = inf;
}
}
void upd(int pos, ll val, int v = 1, int tl = 0, int tr = maxn - 1) {
tree[v] = min(tree[v], val);
if (tl == tr) {
return ;
}
int mid = (tl + tr) >> 1;
if (pos <= mid) {
upd(pos, val, v + v, tl, mid);
} else {
upd(pos, val, v + v + 1, mid + 1, tr);
}
}
ll get(int l, int r, int v = 1, int tl = 0, int tr = maxn - 1) {
if (tl > r || tr < l) return inf;
if (l <= tl && tr <= r) return tree[v];
int mid = (tl + tr) >> 1;
return min(get(l, r, v + v, tl, mid), get(l, r, v + v + 1, mid + 1, tr));
}
};
T l, r;
int getx(int x) {
return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}
main() {
scanf("%d %d", &m, &n);
for (int i = 0; i < m; i++) {
scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
vec.push_back(a[i]);
vec.push_back(b[i]);
vec.push_back(c[i]);
}
ans = 1e18;
vec.push_back(1);
vec.push_back(n);
sort(vec.begin(), vec.end());
vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
l.upd(0, 0);
r.upd(vec.size() - 1, 0);
for (int i = 0; i < m; i++) {
a[i] = getx(a[i]);
b[i] = getx(b[i]);
c[i] = getx(c[i]);
ll left, right;
tie(left, right) = make_tuple(l.get(a[i], b[i]), r.get(a[i], b[i]));
ans = min(ans, left + right + d[i]);
l.upd(c[i], left + d[i]);
r.upd(c[i], right + d[i]);
}
if (ans == (ll)1e18) ans = -1;
printf("%lld\n", ans);
}
Compilation message
pinball.cpp:48:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
pinball.cpp: In function 'int main()':
pinball.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &m, &n);
~~~~~^~~~~~~~~~~~~~~~~
pinball.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
31736 KB |
Output is correct |
2 |
Correct |
26 ms |
31608 KB |
Output is correct |
3 |
Correct |
25 ms |
31608 KB |
Output is correct |
4 |
Correct |
26 ms |
31608 KB |
Output is correct |
5 |
Correct |
26 ms |
31708 KB |
Output is correct |
6 |
Correct |
26 ms |
31736 KB |
Output is correct |
7 |
Correct |
26 ms |
31736 KB |
Output is correct |
8 |
Correct |
26 ms |
31736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
31736 KB |
Output is correct |
2 |
Correct |
26 ms |
31608 KB |
Output is correct |
3 |
Correct |
25 ms |
31608 KB |
Output is correct |
4 |
Correct |
26 ms |
31608 KB |
Output is correct |
5 |
Correct |
26 ms |
31708 KB |
Output is correct |
6 |
Correct |
26 ms |
31736 KB |
Output is correct |
7 |
Correct |
26 ms |
31736 KB |
Output is correct |
8 |
Correct |
26 ms |
31736 KB |
Output is correct |
9 |
Correct |
31 ms |
31608 KB |
Output is correct |
10 |
Correct |
26 ms |
31736 KB |
Output is correct |
11 |
Correct |
27 ms |
31736 KB |
Output is correct |
12 |
Correct |
27 ms |
31736 KB |
Output is correct |
13 |
Correct |
27 ms |
31736 KB |
Output is correct |
14 |
Correct |
27 ms |
31736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
31736 KB |
Output is correct |
2 |
Correct |
26 ms |
31608 KB |
Output is correct |
3 |
Correct |
25 ms |
31608 KB |
Output is correct |
4 |
Correct |
26 ms |
31608 KB |
Output is correct |
5 |
Correct |
26 ms |
31708 KB |
Output is correct |
6 |
Correct |
26 ms |
31736 KB |
Output is correct |
7 |
Correct |
26 ms |
31736 KB |
Output is correct |
8 |
Correct |
26 ms |
31736 KB |
Output is correct |
9 |
Correct |
31 ms |
31608 KB |
Output is correct |
10 |
Correct |
26 ms |
31736 KB |
Output is correct |
11 |
Correct |
27 ms |
31736 KB |
Output is correct |
12 |
Correct |
27 ms |
31736 KB |
Output is correct |
13 |
Correct |
27 ms |
31736 KB |
Output is correct |
14 |
Correct |
27 ms |
31736 KB |
Output is correct |
15 |
Correct |
26 ms |
31740 KB |
Output is correct |
16 |
Correct |
27 ms |
31608 KB |
Output is correct |
17 |
Correct |
28 ms |
31736 KB |
Output is correct |
18 |
Correct |
28 ms |
31736 KB |
Output is correct |
19 |
Correct |
28 ms |
31736 KB |
Output is correct |
20 |
Correct |
28 ms |
31736 KB |
Output is correct |
21 |
Correct |
27 ms |
31736 KB |
Output is correct |
22 |
Correct |
28 ms |
31736 KB |
Output is correct |
23 |
Correct |
27 ms |
31736 KB |
Output is correct |
24 |
Correct |
28 ms |
31736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
31736 KB |
Output is correct |
2 |
Correct |
26 ms |
31608 KB |
Output is correct |
3 |
Correct |
25 ms |
31608 KB |
Output is correct |
4 |
Correct |
26 ms |
31608 KB |
Output is correct |
5 |
Correct |
26 ms |
31708 KB |
Output is correct |
6 |
Correct |
26 ms |
31736 KB |
Output is correct |
7 |
Correct |
26 ms |
31736 KB |
Output is correct |
8 |
Correct |
26 ms |
31736 KB |
Output is correct |
9 |
Correct |
31 ms |
31608 KB |
Output is correct |
10 |
Correct |
26 ms |
31736 KB |
Output is correct |
11 |
Correct |
27 ms |
31736 KB |
Output is correct |
12 |
Correct |
27 ms |
31736 KB |
Output is correct |
13 |
Correct |
27 ms |
31736 KB |
Output is correct |
14 |
Correct |
27 ms |
31736 KB |
Output is correct |
15 |
Correct |
26 ms |
31740 KB |
Output is correct |
16 |
Correct |
27 ms |
31608 KB |
Output is correct |
17 |
Correct |
28 ms |
31736 KB |
Output is correct |
18 |
Correct |
28 ms |
31736 KB |
Output is correct |
19 |
Correct |
28 ms |
31736 KB |
Output is correct |
20 |
Correct |
28 ms |
31736 KB |
Output is correct |
21 |
Correct |
27 ms |
31736 KB |
Output is correct |
22 |
Correct |
28 ms |
31736 KB |
Output is correct |
23 |
Correct |
27 ms |
31736 KB |
Output is correct |
24 |
Correct |
28 ms |
31736 KB |
Output is correct |
25 |
Correct |
46 ms |
32376 KB |
Output is correct |
26 |
Correct |
82 ms |
33496 KB |
Output is correct |
27 |
Correct |
203 ms |
36276 KB |
Output is correct |
28 |
Correct |
197 ms |
38712 KB |
Output is correct |
29 |
Correct |
151 ms |
35572 KB |
Output is correct |
30 |
Correct |
229 ms |
38760 KB |
Output is correct |
31 |
Correct |
300 ms |
38764 KB |
Output is correct |
32 |
Correct |
287 ms |
38764 KB |
Output is correct |
33 |
Correct |
60 ms |
33012 KB |
Output is correct |
34 |
Correct |
153 ms |
35392 KB |
Output is correct |
35 |
Correct |
220 ms |
38892 KB |
Output is correct |
36 |
Correct |
357 ms |
38888 KB |
Output is correct |
37 |
Correct |
319 ms |
38760 KB |
Output is correct |
38 |
Correct |
354 ms |
38764 KB |
Output is correct |