#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz=2e5;
const ll mnv=1e18;
ll s1[sz*2],s2[sz*2];
int a[sz],b[sz],c[sz],d[sz];
void update(ll *a,int x,ll v)
{
x+=sz;
a[x]=min(a[x],v);
for(;x>1;x>>=1) a[x>>1]=min(a[x],a[x^1]);
}
ll query(ll *a,int s,int e)
{
ll ans=mnv;
for(s+=sz,e+=sz;s<e;s>>=1,e>>=1)
{
if(s&1) ans=min(ans,a[s++]);
if(e&1) ans=min(ans,a[--e]);
}
return ans;
}
int main()
{
int N,M;
scanf("%d %d",&N,&M);
for(int i=0;i<N;i++) scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
vector<int> e;
e.push_back(1),e.push_back(M);
for(int i=0;i<N;i++) e.push_back(a[i]),e.push_back(b[i]),e.push_back(c[i]);
sort(e.begin(),e.end());
vector<int>::iterator it;
it=unique(e.begin(),e.end());
e.resize(distance(e.begin(),it));
for(int i=0;i<N;i++) a[i]=lower_bound(e.begin(),e.end(),a[i])-e.begin(),b[i]=lower_bound(e.begin(),e.end(),b[i])-e.begin(),c[i]=lower_bound(e.begin(),e.end(),c[i])-e.begin();
for(int i=0;i<sz*2;i++) s1[i]=s2[i]=mnv;
ll ans=mnv;
int cnt=e.size();
update(s1,0,0),update(s2,cnt-1,0);
for(int i=0;i<N;i++)
{
ll o1=query(s1,a[i],b[i]+1)+d[i];
update(s1,c[i],o1);
ll o2=query(s2,a[i],b[i]+1)+d[i];
update(s2,c[i],o2);
ans=min(ans,o1+o2-d[i]);
}
return !printf("%lld",ans==mnv ? -1 : ans);
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&N,&M);
~~~~~^~~~~~~~~~~~~~~
pinball.cpp:28:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0;i<N;i++) scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6648 KB |
Output is correct |
2 |
Correct |
7 ms |
6648 KB |
Output is correct |
3 |
Correct |
7 ms |
6700 KB |
Output is correct |
4 |
Correct |
8 ms |
6700 KB |
Output is correct |
5 |
Correct |
6 ms |
6752 KB |
Output is correct |
6 |
Correct |
7 ms |
6752 KB |
Output is correct |
7 |
Correct |
8 ms |
6752 KB |
Output is correct |
8 |
Correct |
7 ms |
6760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6648 KB |
Output is correct |
2 |
Correct |
7 ms |
6648 KB |
Output is correct |
3 |
Correct |
7 ms |
6700 KB |
Output is correct |
4 |
Correct |
8 ms |
6700 KB |
Output is correct |
5 |
Correct |
6 ms |
6752 KB |
Output is correct |
6 |
Correct |
7 ms |
6752 KB |
Output is correct |
7 |
Correct |
8 ms |
6752 KB |
Output is correct |
8 |
Correct |
7 ms |
6760 KB |
Output is correct |
9 |
Correct |
7 ms |
6796 KB |
Output is correct |
10 |
Correct |
8 ms |
6796 KB |
Output is correct |
11 |
Correct |
8 ms |
6816 KB |
Output is correct |
12 |
Correct |
7 ms |
6888 KB |
Output is correct |
13 |
Correct |
7 ms |
7008 KB |
Output is correct |
14 |
Correct |
7 ms |
7008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6648 KB |
Output is correct |
2 |
Correct |
7 ms |
6648 KB |
Output is correct |
3 |
Correct |
7 ms |
6700 KB |
Output is correct |
4 |
Correct |
8 ms |
6700 KB |
Output is correct |
5 |
Correct |
6 ms |
6752 KB |
Output is correct |
6 |
Correct |
7 ms |
6752 KB |
Output is correct |
7 |
Correct |
8 ms |
6752 KB |
Output is correct |
8 |
Correct |
7 ms |
6760 KB |
Output is correct |
9 |
Correct |
7 ms |
6796 KB |
Output is correct |
10 |
Correct |
8 ms |
6796 KB |
Output is correct |
11 |
Correct |
8 ms |
6816 KB |
Output is correct |
12 |
Correct |
7 ms |
6888 KB |
Output is correct |
13 |
Correct |
7 ms |
7008 KB |
Output is correct |
14 |
Correct |
7 ms |
7008 KB |
Output is correct |
15 |
Correct |
6 ms |
7008 KB |
Output is correct |
16 |
Correct |
7 ms |
7008 KB |
Output is correct |
17 |
Correct |
8 ms |
7008 KB |
Output is correct |
18 |
Correct |
7 ms |
7008 KB |
Output is correct |
19 |
Correct |
10 ms |
7008 KB |
Output is correct |
20 |
Correct |
11 ms |
7008 KB |
Output is correct |
21 |
Correct |
8 ms |
7016 KB |
Output is correct |
22 |
Correct |
9 ms |
7016 KB |
Output is correct |
23 |
Correct |
8 ms |
7016 KB |
Output is correct |
24 |
Correct |
8 ms |
7016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6648 KB |
Output is correct |
2 |
Correct |
7 ms |
6648 KB |
Output is correct |
3 |
Correct |
7 ms |
6700 KB |
Output is correct |
4 |
Correct |
8 ms |
6700 KB |
Output is correct |
5 |
Correct |
6 ms |
6752 KB |
Output is correct |
6 |
Correct |
7 ms |
6752 KB |
Output is correct |
7 |
Correct |
8 ms |
6752 KB |
Output is correct |
8 |
Correct |
7 ms |
6760 KB |
Output is correct |
9 |
Correct |
7 ms |
6796 KB |
Output is correct |
10 |
Correct |
8 ms |
6796 KB |
Output is correct |
11 |
Correct |
8 ms |
6816 KB |
Output is correct |
12 |
Correct |
7 ms |
6888 KB |
Output is correct |
13 |
Correct |
7 ms |
7008 KB |
Output is correct |
14 |
Correct |
7 ms |
7008 KB |
Output is correct |
15 |
Correct |
6 ms |
7008 KB |
Output is correct |
16 |
Correct |
7 ms |
7008 KB |
Output is correct |
17 |
Correct |
8 ms |
7008 KB |
Output is correct |
18 |
Correct |
7 ms |
7008 KB |
Output is correct |
19 |
Correct |
10 ms |
7008 KB |
Output is correct |
20 |
Correct |
11 ms |
7008 KB |
Output is correct |
21 |
Correct |
8 ms |
7016 KB |
Output is correct |
22 |
Correct |
9 ms |
7016 KB |
Output is correct |
23 |
Correct |
8 ms |
7016 KB |
Output is correct |
24 |
Correct |
8 ms |
7016 KB |
Output is correct |
25 |
Correct |
21 ms |
7292 KB |
Output is correct |
26 |
Correct |
46 ms |
7668 KB |
Output is correct |
27 |
Correct |
154 ms |
8852 KB |
Output is correct |
28 |
Correct |
151 ms |
9708 KB |
Output is correct |
29 |
Correct |
110 ms |
9708 KB |
Output is correct |
30 |
Correct |
167 ms |
9788 KB |
Output is correct |
31 |
Correct |
204 ms |
9788 KB |
Output is correct |
32 |
Correct |
231 ms |
9788 KB |
Output is correct |
33 |
Correct |
30 ms |
9788 KB |
Output is correct |
34 |
Correct |
120 ms |
9788 KB |
Output is correct |
35 |
Runtime error |
126 ms |
18920 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
36 |
Halted |
0 ms |
0 KB |
- |