Submission #156481

#TimeUsernameProblemLanguageResultExecution timeMemory
156481nvmdavaPinball (JOI14_pinball)C++17
0 / 100
2 ms504 KiB
#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;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...