#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
//using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
*/
#define maxn 100005
#define maxx 400025
ll n,m;
struct tupl{
ll t,l,r,c;
} a[maxn];
ll tsz = 1,tsz2 = 1;
set<pair<int,int> > t[4*maxn];
set<pair<int,int> > t[4*maxn];
void upd(ll v,ll tl,ll tr,ll i,pll p,bool f){
if(f) t[v].insert(p);
else t[v].erase(p);
if(tl==tr) return;
ll mid = (tl+tr)/2;
if(i<=mid) upd(2*v,tl,mid,i,p,f);
else upd(2*v+1,mid+1,tr,i,p,f);
}
void upd2(ll v,ll tl,ll tr,ll i,pll p,bool f){
if(f) t2[v].insert(p);
else t2[v].erase(p);
if(tl==tr) return;
ll mid = (tl+tr)/2;
if(i<=mid) upd2(2*v,tl,mid,i,p,f);
else upd2(2*v+1,mid+1,tr,i,p,f);
}
set<ll> s;
void get(ll v,ll tl,ll tr,ll l,ll r,ll x){
if(l>r) return;
if(tl==l&&tr==r){
auto it = t[v].begin();
while(it!=t[v].end()&&(*it).fi<=x){
s.insert((*it).sc);
it++;
}
return;
}
ll mid = (tl+tr)/2;
get(2*v,tl,mid,l,min(mid,r),x);
get(2*v+1,mid+1,tr,max(mid+1,l),r,x);
}
void get2(ll v,ll tl,ll tr,ll l,ll r,ll x){
if(l>r) return;
if(tl==l&&tr==r){
auto it = t2[v].begin();
while(it!=t2[v].end()&&(*it).fi<=x){
s.insert((*it).sc);
it++;
}
return;
}
ll mid = (tl+tr)/2;
get2(2*v,tl,mid,l,min(mid,r),x);
get2(2*v+1,mid+1,tr,max(mid+1,l),r,x);
}
ll d[maxn];
set<ll> st;
map<ll,ll> mp;
ll it = 0;
void tc(){
cin >> m >> n;
for(ll i = 1;i<=n;i++) cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
for(ll i = 1;i<=n;i++) a[i].l--;
for(ll i = 1;i<=n;i++) st.insert(a[i].t);
for(ll x : st) mp[x] = ++it;
ll mxt = it;
for(ll i = 1;i<=n;i++) mxt = max(mxt,a[i].t);
for(ll i = 1;i<=n;i++){
if(a[i].l==0) continue;
upd(1,1,mxt,mp[a[i].t],{a[i].l+a[i].t,i},1);
upd2(1,1,mxt,mp[a[i].t],{a[i].l-a[i].t,i},1);
}
for(ll i = 1;i<=n;i++) d[i] = llinf;
priority_queue<pll> pq;
for(ll i = 1;i<=n;i++){
if(a[i].l==0){
d[i] = a[i].c;
pq.push({-d[i],i});
}
}
while(sz(pq)){
pll p = pq.top();
ll i = p.sc;
pq.pop();
if(-p.fi!=d[i]) continue;
s.clear();
get(1,1,mxt,mp[a[i].t],mxt,a[i].r+a[i].t);
get2(1,1,mxt,1,mp[a[i].t],a[i].r-a[i].t);
for(ll j : s){
if(j==i) continue;
d[j] = d[i] + a[j].c;
upd(1,1,mxt,mp[a[j].t],{a[j].l+a[j].t,j},0);
upd2(1,1,mxt,mp[a[j].t],{a[j].l-a[j].t,j},0);
pq.push({-d[j],j});
}
}
ll ans = llinf;
for(ll i = 1;i<=n;i++) if(a[i].r==m) ans = min(ans,d[i]);
if(ans==llinf) ans = -1;
cout<<ans<<endl;
}
int main(){
daj_mi_malo_vremena
int t; t = 1;
while(t--){
tc();
}
return 0;
}
Compilation message
treatment.cpp:56:21: error: redefinition of 'std::set<std::pair<int, int> > t [400020]'
56 | set<pair<int,int> > t[4*maxn];
| ^
treatment.cpp:55:21: note: 'std::set<std::pair<int, int> > t [400020]' previously declared here
55 | set<pair<int,int> > t[4*maxn];
| ^
treatment.cpp: In function 'void upd2(long long int, long long int, long long int, long long int, std::pair<long long int, long long int>, bool)':
treatment.cpp:66:11: error: 't2' was not declared in this scope; did you mean 'tl'?
66 | if(f) t2[v].insert(p);
| ^~
| tl
treatment.cpp:67:10: error: 't2' was not declared in this scope; did you mean 'tl'?
67 | else t2[v].erase(p);
| ^~
| tl
treatment.cpp: In function 'void get2(long long int, long long int, long long int, long long int, long long int, long long int)':
treatment.cpp:91:19: error: 't2' was not declared in this scope; did you mean 'tl'?
91 | auto it = t2[v].begin();
| ^~
| tl