#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
const int N=1e6+99,Max=4e5,inf=1e15;
int m,n,ans=inf,L[N],R[N],seg[2][N];
vector<int> Q[N];
void upd(int x,int val,int s){
x+=Max;
while(x) minm(seg[s][x],val),x/=2;
}
int get(int l,int r,int s){
int res=inf;
for(l+=Max,r+=Max;l<r;l>>=1,r>>=1){
if(l&1) minm(res,seg[s][l++]);
if(r&1) minm(res,seg[s][--r]);
}
return res;
}
main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
f(s,0,2) f(i,0,N) seg[s][i]=inf;
vector<int> vec;
cin>>m>>n;
f(i,1,m+1){
int x;
f(j,0,3){ cin>>x; Q[i].pb(x); vec.pb(x); }
cin>>x;
Q[i].pb(x);
}
vec.pb(1);
vec.pb(n);
sort(all(vec));
vec.resize(unique(vec.begin(),vec.end())-vec.begin());
f(i,1,m+1){
int l,r,p,cost;
cost=Q[i][3];
l=lower_bound(all(vec),Q[i][0])-vec.begin();
r=lower_bound(all(vec),Q[i][1])-vec.begin();
p=lower_bound(all(vec),Q[i][2])-vec.begin();
//cout<<l<<" "<<r<<" "<<p<<endl;
if(l==0){
L[i]=0;
}
else{
L[i]=get(l,r+1,0);
}
if(r==n-1){
R[i]=0;
}
else{
R[i]=get(l,r+1,1);
}
L[i]+=cost;
R[i]+=cost;
upd(p,L[i],0);
upd(p,R[i],1);
minm(ans,L[i]+R[i]-cost);
}
cout<<(ans==inf ? -1 : ans);
}
Compilation message
pinball.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
41 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
39372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
39372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
39372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
39372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |