# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=3e5+5;
long long dp[N],dp1[N],n,m,a[N],b[N],c[N],d[N],ans;
map <long long> tree;
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() {
cin>>m>>n;
for (int i=1; i<=m; i++) {
cin>>a[i]>>b[i]>>c[i]>>d[i];
}
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]); //cout<<dp[5]<<endl;
}
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++) {
// cout<<dp[i]<<" "<<dp1[i]<<" "<<dp1[i]-d[i]<<" "<<d[i]<<" "<<dp[i]+dp1[i]-d[i]<<endl;
ans=min(ans, dp[i]+dp1[i]-d[i]);
}
if (ans==1e17) cout<<-1<<endl;else
cout<<ans<<endl;
}
Compilation message
pinball.cpp:8:15: error: wrong number of template arguments (1, should be at least 2)
8 | map <long long> tree;
| ^
In file included from /usr/include/c++/10/map:61,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
from pinball.cpp:1:
/usr/include/c++/10/bits/stl_map.h:100:11: note: provided for 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
100 | class map
| ^~~
pinball.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
pinball.cpp:12:15: error: invalid types 'int[long long int]' for array subscript
12 | tree[node]=min(tree[node],val);
| ^
pinball.cpp:12:30: error: invalid types 'int[long long int]' for array subscript
12 | tree[node]=min(tree[node],val);
| ^
pinball.cpp:18:10: error: invalid types 'int[long long int]' for array subscript
18 | tree[node]=min(tree[2*node],tree[2*node+1]);
| ^
pinball.cpp:18:25: error: invalid types 'int[long long int]' for array subscript
18 | tree[node]=min(tree[2*node],tree[2*node+1]);
| ^
pinball.cpp:18:38: error: invalid types 'int[long long int]' for array subscript
18 | tree[node]=min(tree[2*node],tree[2*node+1]);
| ^
pinball.cpp: In function 'long long int getans(long long int, long long int, long long int, long long int, long long int)':
pinball.cpp:23:22: error: invalid types 'int[long long int]' for array subscript
23 | return tree[node];
| ^
pinball.cpp: In function 'int main()':
pinball.cpp:34:15: error: invalid types 'int[int]' for array subscript
34 | tree[i]=1e17;
| ^
pinball.cpp:47:15: error: invalid types 'int[int]' for array subscript
47 | tree[i]=1e17;
| ^