This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define f first
#define sc second
#define pb push_back
using namespace std;
ll a,b,c,d,i,e,f,g,n,m,k,l,tree[3000006][4],minn,dp1[100005],dp2[100005];
pair < pair <ll,ll> , pair < ll , ll > > A[100005];
vector <ll> v;
map <ll,ll> mp;
void update(ll node,ll le,ll ri,ll idx,ll val,ll type) {
if(ri<idx || le>idx) return;
if(le==ri) { tree[node][type]=min(tree[node][type],val); return; }
update(2*node,le,(le+ri)/2,idx,val,type);
update(2*node+1,(le+ri)/2+1,ri,idx,val,type);
tree[node][type]=min(tree[2*node][type],tree[2*node+1][type]);
}
ll getmin(ll node,ll le,ll ri,ll start,ll end,ll type) {
if(ri<start || le>end) return 1e17;
if(start<=le && ri<=end) { return tree[node][type]; }
a=min(getmin(2*node,le,(le+ri)/2,start,end,type),getmin(2*node+1,(le+ri)/2+1,ri,start,end,type));
return a;
}
int main() {
cin>>n>>m;
for(ll i=1;i<=n;i++) {
cin>>A[i].f.f>>A[i].f.sc>>A[i].sc.f>>A[i].sc.sc;
v.pb(A[i].f.f);
v.pb(A[i].f.sc);
v.pb(A[i].sc.f);
dp1[i]=1e17; dp2[i]=1e17;
}
v.pb(1); v.pb(m);
sort(v.begin(),v.end());
k=1; mp[v[0]]=k;
for(ll i=1;i<v.size();i++) {
if(v[i]>v[i-1]) k++;
mp[v[i]]=k;
}
for(ll i=1;i<=n;i++) {
A[i].f.f=mp[A[i].f.f];
A[i].f.sc=mp[A[i].f.sc];
A[i].sc.f=mp[A[i].sc.f];
//cout<<A[i].f.f<<" "<<A[i].f.sc<<" "<<A[i].sc.f<<endl;
}
m=mp[m];
for(ll i=0;i<=4*m;i++) {
tree[i][1]=1e17;
tree[i][2]=1e17;
}
minn=1e17;
for(ll i=1;i<=n;i++) {
if(A[i].f.f==1) dp1[i]=A[i].sc.sc;
if(A[i].f.sc==m) dp2[i]=A[i].sc.sc;
if(dp1[i]==1e17) {
//cout<<"* "<<getmin(1,1,m,A[i].f.f,A[i].f.sc,1)<<" ";
dp1[i]=getmin(1,1,m,A[i].f.f,A[i].f.sc,1)+A[i].sc.sc;
}
if(dp2[i]==1e17) {
// cout<<"^";
dp2[i]=getmin(1,1,m,A[i].f.f,A[i].f.sc,2)+A[i].sc.sc;
}
//cout<<dp1[i]<<" "<<dp2[i]<<endl;
update(1,1,m,A[i].sc.f,dp1[i],1);
update(1,1,m,A[i].sc.f,dp2[i],2);
minn=min(minn,dp1[i]+dp2[i]-A[i].sc.sc);
}
if(minn==1e17) cout<<-1;
else cout<<minn;
}
Compilation message (stderr)
pinball.cpp: In function 'int main()':
pinball.cpp:36:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(ll i=1;i<v.size();i++) {
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |