This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e5 + 9;
const ll Log2 = 20;
const ll inf = 1e16 + 7;
typedef pair<ll,ll> LL;
struct Seg{
ll L,R,to,val;
};
Seg a[N];
ll m,n,L,R,to,val,st[2][4*N],ans = inf;
void upd(ll cond,ll id,ll l,ll r,ll u,ll val){
if (u < l||r < u) return;
if (l == r){
st[cond][id] = min(st[cond][id],val); return;
}
ll mid = (l + r)/2;
upd(cond,id*2,l,mid,u,val); upd(cond,id*2 + 1,mid + 1,r,u,val);
st[cond][id] = min(st[cond][id*2],st[cond][id*2 + 1]);
}
ll Get(ll cond,ll id,ll l,ll r,ll u,ll v){
if (v < l||r < u) return inf;
if (u <= l&&r <= v) return st[cond][id];
ll mid = (l + r)/2;
return min(Get(cond,id*2,l,mid,u,v),Get(cond,id*2 + 1,mid + 1,r,u,v));
}
/// 0 for L 1 for R
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
for (ll i = 1;i < 4*N;i++) st[0][i] = st[1][i] = inf;
cin>>m>>n;
for (ll i = 1;i <= m;i++){
cin>>L>>R>>to>>val;
ll v1 = Get(0,1,1,n,L,R),v2 = Get(1,1,1,n,L,R);
if (L == 1) v1 = 0;
if (R == n) v2 = 0;
ans = min(ans,v1 + v2 + val);
upd(0,1,1,n,to,v1 + val); upd(1,1,1,n,to,v2 + val);
}
if (ans != inf) cout<<ans;
else cout<<-1;
}
Compilation message (stderr)
pinball.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
pinball.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
pinball.cpp: In function 'int main()':
pinball.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |