#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 1e5 + 2;
int n,m;
struct node {
int l,r;
int64 v;
node* left;
node* right;
node(int _l, int _r, int64 _v): l(_l), r(_r), v(_v) {};
void extend() {
if (left != NULL) return;
int mid = (l + r) / 2;
left = new node(l, mid, 1e15);
right = new node(mid + 1, r, 1e15);
}
int64 query (int il, int ir) {
if (il <= l && r <= ir) return v;
if (l > ir || r < il) return 1e15;
extend();
return min(left->query(il, ir), right->query(il, ir));
}
void update (int x, int64 nval) {
if (l == r && l == x) return void(v = min(v, nval));
if (l > x || r < x) return;
extend();
left->update(x, nval);
right->update(x, nval);
v = min(left->v, right->v);
}
};
int main() {
cin >> n >> m;
node* lf = new node(0, m + 1, 1e15);
node* rt = new node(0, m + 1, 1e15);
int64 rs = 1e15;
lf->update(1, 0);
rt->update(m, 0);
for (int i = 0; i < n; i++){
int64 a,b,c,cost;
cin >> a >> b >> c >> cost;
int64 p1 = lf->query(a,b);
int64 p2 = rt->query(a,b);
rs = min(rs, p1 + p2 + cost);
lf->update(c, p1 + cost);
rt->update(c, p2 + cost);
}
cout << (rs >= 1e15 ? -1: rs);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
944 KB |
Output is correct |
12 |
Correct |
3 ms |
2132 KB |
Output is correct |
13 |
Correct |
3 ms |
2352 KB |
Output is correct |
14 |
Correct |
3 ms |
2516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
944 KB |
Output is correct |
12 |
Correct |
3 ms |
2132 KB |
Output is correct |
13 |
Correct |
3 ms |
2352 KB |
Output is correct |
14 |
Correct |
3 ms |
2516 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
8 ms |
3796 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
11 ms |
8532 KB |
Output is correct |
20 |
Correct |
6 ms |
2644 KB |
Output is correct |
21 |
Correct |
6 ms |
2516 KB |
Output is correct |
22 |
Correct |
11 ms |
8532 KB |
Output is correct |
23 |
Correct |
13 ms |
9812 KB |
Output is correct |
24 |
Correct |
16 ms |
9960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
944 KB |
Output is correct |
12 |
Correct |
3 ms |
2132 KB |
Output is correct |
13 |
Correct |
3 ms |
2352 KB |
Output is correct |
14 |
Correct |
3 ms |
2516 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
8 ms |
3796 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
11 ms |
8532 KB |
Output is correct |
20 |
Correct |
6 ms |
2644 KB |
Output is correct |
21 |
Correct |
6 ms |
2516 KB |
Output is correct |
22 |
Correct |
11 ms |
8532 KB |
Output is correct |
23 |
Correct |
13 ms |
9812 KB |
Output is correct |
24 |
Correct |
16 ms |
9960 KB |
Output is correct |
25 |
Correct |
62 ms |
15028 KB |
Output is correct |
26 |
Correct |
215 ms |
81648 KB |
Output is correct |
27 |
Correct |
544 ms |
138708 KB |
Output is correct |
28 |
Correct |
345 ms |
2940 KB |
Output is correct |
29 |
Correct |
467 ms |
166592 KB |
Output is correct |
30 |
Correct |
577 ms |
29392 KB |
Output is correct |
31 |
Correct |
994 ms |
300996 KB |
Output is correct |
32 |
Correct |
885 ms |
202800 KB |
Output is correct |
33 |
Correct |
147 ms |
70508 KB |
Output is correct |
34 |
Correct |
564 ms |
295420 KB |
Output is correct |
35 |
Runtime error |
742 ms |
524288 KB |
Execution killed with signal 9 |
36 |
Halted |
0 ms |
0 KB |
- |