#include<stdio.h>
#include<algorithm>
using namespace std;
struct xy {long long a, b, c, d;}a[121212];
long long ALL[414141], an = 0;
long long F(long long x) { return (lower_bound(ALL, ALL + an, x) - ALL); }
long long tree[2][1212121], tn;
long long min(long long a, long long b) { if (a < b)return a; return b; }
void insert_g(long long tp, long long w, long long g) { for (long long i = tn + w; i > 0; i /= 2)tree[tp][i] = min(tree[tp][i], g); }
long long search_g(long long tp, long long ss, long long ee) {
long long s = ss + tn, e = ee + tn;
long long res = 1e18;
while (s <= e) {
if (s % 2 == 1)res = min(res, tree[tp][s++]);
if (e % 2 == 0)res = min(res, tree[tp][e--]);
s /= 2; e /= 2;
}
return res;
}
int main() {
long long n, m; scanf("%lld%lld", &m, &n);
long long i, j;
for (i = 0; i < m; i++) {
scanf("%lld%lld%lld%lld", &a[i].a, &a[i].b, &a[i].c, &a[i].d);
ALL[an++] = a[i].a; ALL[an++] = a[i].b; ALL[an++] = a[i].c;
}
ALL[an++] = 1; ALL[an++] = n;
sort(ALL, ALL + an);
an = unique(ALL, ALL + an) - ALL;
for (tn = 1; tn < an; tn *= 2);
for (i = 0; i < m; i++) a[i] = { F(a[i].a), F(a[i].b), F(a[i].c), a[i].d };
for (i = 0; i < tn * 2; i++)tree[0][i] = tree[1][i] = 1e18;
long long ans = 1e18;
for (i = 0; i < m; i++) {
long long l = (a[i].a == 0 ? 0 : search_g(0, a[i].a, a[i].b))+a[i].d;
long long r = (a[i].b == an-1 ? 0 : search_g(1, a[i].a, a[i].b))+a[i].d;
ans = min(ans, l + r - a[i].d);
insert_g(0, a[i].c, l);
insert_g(1, a[i].c, r);
}
if (ans > 1e17)printf("-1");
else printf("%lld", ans);
return 0;
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:22:15: warning: unused variable 'j' [-Wunused-variable]
long long i, j;
^
pinball.cpp:21:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
long long n, m; scanf("%lld%lld", &m, &n);
~~~~~^~~~~~~~~~~~~~~~~~~~
pinball.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld%lld", &a[i].a, &a[i].b, &a[i].c, &a[i].d);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
472 KB |
Output is correct |
9 |
Correct |
3 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
3 ms |
696 KB |
Output is correct |
12 |
Correct |
2 ms |
696 KB |
Output is correct |
13 |
Correct |
2 ms |
696 KB |
Output is correct |
14 |
Correct |
2 ms |
696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
472 KB |
Output is correct |
9 |
Correct |
3 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
3 ms |
696 KB |
Output is correct |
12 |
Correct |
2 ms |
696 KB |
Output is correct |
13 |
Correct |
2 ms |
696 KB |
Output is correct |
14 |
Correct |
2 ms |
696 KB |
Output is correct |
15 |
Correct |
3 ms |
696 KB |
Output is correct |
16 |
Correct |
4 ms |
696 KB |
Output is correct |
17 |
Correct |
4 ms |
696 KB |
Output is correct |
18 |
Correct |
3 ms |
696 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
4 ms |
760 KB |
Output is correct |
21 |
Correct |
3 ms |
760 KB |
Output is correct |
22 |
Correct |
4 ms |
760 KB |
Output is correct |
23 |
Correct |
3 ms |
760 KB |
Output is correct |
24 |
Correct |
4 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
472 KB |
Output is correct |
9 |
Correct |
3 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
3 ms |
696 KB |
Output is correct |
12 |
Correct |
2 ms |
696 KB |
Output is correct |
13 |
Correct |
2 ms |
696 KB |
Output is correct |
14 |
Correct |
2 ms |
696 KB |
Output is correct |
15 |
Correct |
3 ms |
696 KB |
Output is correct |
16 |
Correct |
4 ms |
696 KB |
Output is correct |
17 |
Correct |
4 ms |
696 KB |
Output is correct |
18 |
Correct |
3 ms |
696 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
4 ms |
760 KB |
Output is correct |
21 |
Correct |
3 ms |
760 KB |
Output is correct |
22 |
Correct |
4 ms |
760 KB |
Output is correct |
23 |
Correct |
3 ms |
760 KB |
Output is correct |
24 |
Correct |
4 ms |
760 KB |
Output is correct |
25 |
Correct |
22 ms |
2168 KB |
Output is correct |
26 |
Correct |
44 ms |
4116 KB |
Output is correct |
27 |
Correct |
127 ms |
8572 KB |
Output is correct |
28 |
Correct |
129 ms |
8572 KB |
Output is correct |
29 |
Correct |
98 ms |
8572 KB |
Output is correct |
30 |
Correct |
156 ms |
8572 KB |
Output is correct |
31 |
Correct |
204 ms |
14204 KB |
Output is correct |
32 |
Correct |
198 ms |
14204 KB |
Output is correct |
33 |
Correct |
25 ms |
14204 KB |
Output is correct |
34 |
Correct |
96 ms |
14204 KB |
Output is correct |
35 |
Correct |
175 ms |
22564 KB |
Output is correct |
36 |
Correct |
267 ms |
22564 KB |
Output is correct |
37 |
Correct |
212 ms |
22564 KB |
Output is correct |
38 |
Correct |
213 ms |
22564 KB |
Output is correct |