# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=3e5+5;
int n,m,cnt;
long long dp[N],dp1[N],a[N],b[N],c[N],d[N],ans;
long long tree[4*N];
map <int, int> xx;
vector <long long> v;
void update(long long node, long long le, long long ri ,long long idx, long long val) {
if (le>idx || ri<idx) return;
if (le==ri) {
tree[node]=min(tree[node],val);
return ;
}
int mid=(le+ri)/2;
update(2*node, le ,mid, idx, val);
update(2*node+1, mid+1, ri, idx, val);
tree[node]=min(tree[2*node],tree[2*node+1]);
}
long long getans(long long node, long long le, long long ri ,long long start, long long end) {
if (le>end || ri<start) return 1e17;
if (le>=start && ri<=end) {
return tree[node];
}
int mid=(le+ri)/2;
return min(getans(2*node, le ,mid, start, end),getans(2*node+1, mid+1, ri, start,end));
}
int main() {
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
v.pb(1);
cin>>m>>n;
v.pb(n);
for (int i=1; i<=m; i++) {
cin>>a[i]>>b[i]>>c[i]>>d[i];
v.pb(a[i]);
v.pb(b[i]);
v.pb(c[i]);
}
sort(v.begin(), v.end());
xx[v[0]]=1;
cnt=1;
for (int i=1; i<v.size(); i++) {
if (v[i]!=v[i-1]) {
cnt++;
xx[v[i]]=cnt;
}
}
for (int i=1; i<=m; i++){
a[i]=xx[a[i]];
b[i]=xx[b[i]];
c[i]=xx[c[i]];//cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<endl;
}
n=cnt;
for (int i=1; i<=4*n; i++) {
tree[i]=1e17;
}
for (int i=1; i<=m; i++) {
if (a[i]==1) {
dp[i]=d[i];
update(1,1,n,c[i],dp[i]);
continue;
}
dp[i]=getans(1,1,n,a[i],b[i])+d[i];
update(1,1,n,c[i],dp[i]);
}
for (int i=1; i<=4*n; i++) {
tree[i]=1e17;
}
for (int i=1; i<=m; i++) {
if (b[i]==n) {
dp1[i]=d[i];
update(1,1,n,c[i],dp1[i]);
continue;
}
dp1[i]=getans(1,1,n,a[i],b[i])+d[i];
update(1,1,n,c[i],dp1[i]);
}
ans=1e17;
for (int i=1; i<=m; i++) {
ans=min(ans, dp[i]+dp1[i]-d[i]);
}
if (ans==1e17) cout<<-1;else
cout<<ans;
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i=1; i<v.size(); i++) {
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
3 ms |
588 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
3 ms |
676 KB |
Output is correct |
23 |
Correct |
3 ms |
588 KB |
Output is correct |
24 |
Correct |
3 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
3 ms |
588 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
3 ms |
676 KB |
Output is correct |
23 |
Correct |
3 ms |
588 KB |
Output is correct |
24 |
Correct |
3 ms |
588 KB |
Output is correct |
25 |
Correct |
27 ms |
2352 KB |
Output is correct |
26 |
Correct |
86 ms |
6412 KB |
Output is correct |
27 |
Correct |
251 ms |
13212 KB |
Output is correct |
28 |
Correct |
170 ms |
11268 KB |
Output is correct |
29 |
Correct |
212 ms |
12856 KB |
Output is correct |
30 |
Correct |
252 ms |
12688 KB |
Output is correct |
31 |
Correct |
425 ms |
24364 KB |
Output is correct |
32 |
Correct |
362 ms |
20732 KB |
Output is correct |
33 |
Correct |
55 ms |
6988 KB |
Output is correct |
34 |
Correct |
203 ms |
17464 KB |
Output is correct |
35 |
Correct |
305 ms |
34616 KB |
Output is correct |
36 |
Correct |
539 ms |
34692 KB |
Output is correct |
37 |
Correct |
457 ms |
34676 KB |
Output is correct |
38 |
Correct |
400 ms |
34672 KB |
Output is correct |