# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1020591 |
2024-07-12T07:19:54 Z |
1L1YA |
Pinball (JOI14_pinball) |
C++17 |
|
191 ms |
29124 KB |
//1L1YA
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3,unrool-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define Pb push_back
#define F first
#define S second
#define endl '\n'
#define sep ' '
#define all(x) x.begin(),x.end()
#define al(x,n) x+1,x+n+1
#define SZ(x) ((int)x.size())
#define lc (id<<1)
#define rc (lc|1)
#define mid (l+r>>1)
#define dokme(x) cout << x << endl, exit(0)
#define sik(x) cout << x << endl;continue;
#define FastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll oo=1e16;
const int mod=1e9+7;
const int inf=1e9+111;
const int N=3e5+11;
const int lg=23;
ll n,m,T,a[N],b[N],c[N],d[N],dpl[N],dpr[N],seg[2][N<<2];
vector<int> comp;
void modify(int ind,int pos,ll val,int id=1,int l=0,int r=T){
if(r-l==1){
seg[ind][id]=min(seg[ind][id],val);
return;
}
if(pos<mid) modify(ind,pos,val,lc,l,mid);
else modify(ind,pos,val,rc,mid,r);
seg[ind][id]=min(seg[ind][lc],seg[ind][rc]);
}
ll get(int ind,int ql,int qr,int id=1,int l=0,int r=T){
if(qr<=l || ql>=r) return oo;
if(ql<=l && r<=qr) return seg[ind][id];
return min(get(ind,ql,qr,lc,l,mid),get(ind,ql,qr,rc,mid,r));
}
int main(){
FastIO
cin >> n >> m;
comp.Pb(1);comp.Pb(m+1);
for(int i=1;i<=n;i++){
cin >> a[i] >> b[i] >> c[i] >> d[i];
b[i]++;
comp.Pb(a[i]);
comp.Pb(b[i]);
comp.Pb(c[i]);
}
sort(all(comp));
comp.resize(unique(all(comp))-comp.begin());
for(int i=1;i<=n;i++){
a[i]=lower_bound(all(comp),a[i])-comp.begin();
b[i]=lower_bound(all(comp),b[i])-comp.begin();
c[i]=lower_bound(all(comp),c[i])-comp.begin();
}
T=SZ(comp);
fill(seg[0],seg[0]+(T<<2),oo);
fill(seg[1],seg[1]+(T<<2),oo);
ll ans=oo;
for(int i=1;i<=n;i++){
dpl[i]=dpr[i]=oo;
if(!a[i]) dpl[i]=d[i];
if(b[i]==T-1) dpr[i]=d[i];
dpl[i]=min(dpl[i],get(0,a[i],b[i])+d[i]);
dpr[i]=min(dpr[i],get(1,a[i],b[i])+d[i]);
ans=min(ans,dpl[i]+dpr[i]-d[i]);
modify(0,c[i],dpl[i]);
modify(1,c[i],dpr[i]);
}
cout << (ans==oo?-1:ans) << endl;
return 0;
}
Compilation message
pinball.cpp: In function 'void modify(int, int, ll, int, int, int)':
pinball.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
pinball.cpp:45:9: note: in expansion of macro 'mid'
45 | if(pos<mid) modify(ind,pos,val,lc,l,mid);
| ^~~
pinball.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
pinball.cpp:45:38: note: in expansion of macro 'mid'
45 | if(pos<mid) modify(ind,pos,val,lc,l,mid);
| ^~~
pinball.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
pinball.cpp:46:29: note: in expansion of macro 'mid'
46 | else modify(ind,pos,val,rc,mid,r);
| ^~~
pinball.cpp: In function 'll get(int, int, int, int, int, int)':
pinball.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
pinball.cpp:53:32: note: in expansion of macro 'mid'
53 | return min(get(ind,ql,qr,lc,l,mid),get(ind,ql,qr,rc,mid,r));
| ^~~
pinball.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
pinball.cpp:53:54: note: in expansion of macro 'mid'
53 | return min(get(ind,ql,qr,lc,l,mid),get(ind,ql,qr,rc,mid,r));
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
744 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
744 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
13 ms |
2140 KB |
Output is correct |
26 |
Correct |
37 ms |
5844 KB |
Output is correct |
27 |
Correct |
110 ms |
11720 KB |
Output is correct |
28 |
Correct |
96 ms |
10436 KB |
Output is correct |
29 |
Correct |
90 ms |
9932 KB |
Output is correct |
30 |
Correct |
124 ms |
10980 KB |
Output is correct |
31 |
Correct |
167 ms |
18164 KB |
Output is correct |
32 |
Correct |
160 ms |
15640 KB |
Output is correct |
33 |
Correct |
24 ms |
6112 KB |
Output is correct |
34 |
Correct |
87 ms |
14796 KB |
Output is correct |
35 |
Correct |
127 ms |
29124 KB |
Output is correct |
36 |
Correct |
191 ms |
29124 KB |
Output is correct |
37 |
Correct |
186 ms |
29124 KB |
Output is correct |
38 |
Correct |
171 ms |
29124 KB |
Output is correct |