#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define N 100005
#define MOD 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
struct Node{
Node *l = NULL, *r = NULL;
ll val = INF;
int L, R;
Node(int lll, int rrr){
L = lll;
R = rrr;
}
ll update(int x, ll t){
if(t > INF) return INF;
if(L == R){
val = min(val, t);
return val;
}
ll ret;
int M = (L + R) >> 1;
if(M >= x){
if(l == NULL)
l = new Node(L, M);
ret = l -> update(x, t);
} else {
if(r == NULL)
r = new Node(M + 1, R);
ret = r -> update(x, t);
}
ll v1, v2;
if(l == NULL)
v1 = INF;
else
v1 = l -> val;
if(r == NULL)
v2 = INF;
else
v2 = r -> val;
val = min(v1, v2);
return ret;
}
ll query(int LL, int RR){
if(LL <= L && R <= RR)
return val;
if(LL > R || L > RR)
return INF;
ll v1, v2;
if(l == NULL)
v1 = INF;
else
v1 = l -> query(LL, RR);
if(r == NULL)
v2 = INF;
else
v2 = r -> query(LL, RR);
return min(v1, v2);
}
} *a = NULL, *b = NULL;
ll ans = INF;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int m, n;
cin>>m>>n;
a = new Node(1, n);
b = new Node(1, n);
a -> update(1, 0);
b -> update(n, 0);
for(int i = 1; i <= m; i++){
int A, B, C, D;
cin>>A>>B>>C>>D;
ans = min(ans, a -> update(C, a -> query(A, B) + D) + b -> update(C, b -> query(A, B) + D) - D);
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |