#include<bits/stdc++.h>
using namespace std;
#define N 100005
int a[N],b[N],c[N],d[N];
long long l,r,ans=1e18;
vector<int> v;
class tree{
public:
vector<long long> t;
tree():t(4*N,1e18){}
void update(int x,int l,int r,int i,long long val){
if(l>c[i]||r<c[i])return ;
if(l==r){
t[x]=min(t[x],val);
return ;
}
int mid=(l+r)/2;
update(x*2,l,mid,i,val);
update(x*2+1,mid+1,r,i,val);
t[x]=min(t[x*2],t[x*2+1]);
}
long long sol(int x,int l,int r,int i){
if(l>b[i]||a[i]>r)return 1e18;
if(a[i]<=l&&r<=b[i])return t[x];
int mid=(l+r)/2;
return min(sol(x*2,l,mid,i),sol(x*2+1,mid+1,r,i));
}
}t1,t2;
int main(){
int n,m,i;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++){
scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
v.push_back(a[i]);
v.push_back(b[i]);
v.push_back(c[i]);
}
v.push_back(-1);
v.push_back(1);
v.push_back(m);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
for(i=1;i<=n;i++){
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
b[i]=lower_bound(v.begin(),v.end(),b[i])-v.begin();
c[i]=lower_bound(v.begin(),v.end(),c[i])-v.begin();
if(a[i]!=1)l=t1.sol(1,1,v.size()-1,i);
else l=0;
if(b[i]!=v.size()-1)r=t2.sol(1,1,v.size()-1,i);
else r=0;
ans=min(ans,l+r+d[i]);
t1.update(1,1,v.size()-1,i,l+d[i]);
t2.update(1,1,v.size()-1,i,r+d[i]);
}
if(ans!=1e18)printf("%lld",ans);
else printf("-1");
return 0;
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | if(b[i]!=v.size()-1)r=t2.sol(1,1,v.size()-1,i);
| ~~~~^~~~~~~~~~~~
pinball.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
pinball.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
4 ms |
6484 KB |
Output is correct |
3 |
Correct |
4 ms |
6484 KB |
Output is correct |
4 |
Correct |
4 ms |
6484 KB |
Output is correct |
5 |
Correct |
3 ms |
6484 KB |
Output is correct |
6 |
Correct |
4 ms |
6484 KB |
Output is correct |
7 |
Correct |
4 ms |
6484 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
4 ms |
6484 KB |
Output is correct |
3 |
Correct |
4 ms |
6484 KB |
Output is correct |
4 |
Correct |
4 ms |
6484 KB |
Output is correct |
5 |
Correct |
3 ms |
6484 KB |
Output is correct |
6 |
Correct |
4 ms |
6484 KB |
Output is correct |
7 |
Correct |
4 ms |
6484 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
4 ms |
6484 KB |
Output is correct |
10 |
Correct |
4 ms |
6484 KB |
Output is correct |
11 |
Correct |
3 ms |
6592 KB |
Output is correct |
12 |
Correct |
4 ms |
6612 KB |
Output is correct |
13 |
Correct |
4 ms |
6592 KB |
Output is correct |
14 |
Correct |
4 ms |
6612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
4 ms |
6484 KB |
Output is correct |
3 |
Correct |
4 ms |
6484 KB |
Output is correct |
4 |
Correct |
4 ms |
6484 KB |
Output is correct |
5 |
Correct |
3 ms |
6484 KB |
Output is correct |
6 |
Correct |
4 ms |
6484 KB |
Output is correct |
7 |
Correct |
4 ms |
6484 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
4 ms |
6484 KB |
Output is correct |
10 |
Correct |
4 ms |
6484 KB |
Output is correct |
11 |
Correct |
3 ms |
6592 KB |
Output is correct |
12 |
Correct |
4 ms |
6612 KB |
Output is correct |
13 |
Correct |
4 ms |
6592 KB |
Output is correct |
14 |
Correct |
4 ms |
6612 KB |
Output is correct |
15 |
Correct |
5 ms |
6592 KB |
Output is correct |
16 |
Correct |
4 ms |
6612 KB |
Output is correct |
17 |
Correct |
5 ms |
6612 KB |
Output is correct |
18 |
Correct |
5 ms |
6552 KB |
Output is correct |
19 |
Correct |
6 ms |
6612 KB |
Output is correct |
20 |
Correct |
5 ms |
6600 KB |
Output is correct |
21 |
Correct |
4 ms |
6612 KB |
Output is correct |
22 |
Correct |
5 ms |
6612 KB |
Output is correct |
23 |
Correct |
4 ms |
6608 KB |
Output is correct |
24 |
Correct |
5 ms |
6612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
4 ms |
6484 KB |
Output is correct |
3 |
Correct |
4 ms |
6484 KB |
Output is correct |
4 |
Correct |
4 ms |
6484 KB |
Output is correct |
5 |
Correct |
3 ms |
6484 KB |
Output is correct |
6 |
Correct |
4 ms |
6484 KB |
Output is correct |
7 |
Correct |
4 ms |
6484 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
4 ms |
6484 KB |
Output is correct |
10 |
Correct |
4 ms |
6484 KB |
Output is correct |
11 |
Correct |
3 ms |
6592 KB |
Output is correct |
12 |
Correct |
4 ms |
6612 KB |
Output is correct |
13 |
Correct |
4 ms |
6592 KB |
Output is correct |
14 |
Correct |
4 ms |
6612 KB |
Output is correct |
15 |
Correct |
5 ms |
6592 KB |
Output is correct |
16 |
Correct |
4 ms |
6612 KB |
Output is correct |
17 |
Correct |
5 ms |
6612 KB |
Output is correct |
18 |
Correct |
5 ms |
6552 KB |
Output is correct |
19 |
Correct |
6 ms |
6612 KB |
Output is correct |
20 |
Correct |
5 ms |
6600 KB |
Output is correct |
21 |
Correct |
4 ms |
6612 KB |
Output is correct |
22 |
Correct |
5 ms |
6612 KB |
Output is correct |
23 |
Correct |
4 ms |
6608 KB |
Output is correct |
24 |
Correct |
5 ms |
6612 KB |
Output is correct |
25 |
Correct |
22 ms |
7276 KB |
Output is correct |
26 |
Correct |
64 ms |
8400 KB |
Output is correct |
27 |
Correct |
182 ms |
11044 KB |
Output is correct |
28 |
Correct |
150 ms |
13612 KB |
Output is correct |
29 |
Correct |
142 ms |
10264 KB |
Output is correct |
30 |
Correct |
230 ms |
13616 KB |
Output is correct |
31 |
Runtime error |
84 ms |
22712 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |