Submission #946838

# Submission time Handle Problem Language Result Execution time Memory
946838 2024-03-15T06:22:44 Z vjudge1 Treatment Project (JOI20_treatment) C++17
0 / 100
203 ms 80124 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>*/
template<class S,class T>
bool chmin(S &a,const T &b) {
	return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
	return a<b?(a=b)==b:false;
}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e18;
const ll mod=998244353;
const ll N=4e5+5;
const ld eps=1e-9;
vector<ll> t(N*4,inf);
ll n,m;
ll get(ll l,ll r,ll v=1,ll tl=1,ll tr=n){
    if(tl>r || tr<l) return inf;
    if(l<=tl && tr<=r)return t[v];
    ll tm=(tl+tr)/2;
    return min(get(l,r,v*2,tl,tm),get(l,r,v*2+1,tm+1,tr));
}
void upd(ll pos,ll val,ll v=1,ll tl=1,ll tr=n){
    if(tl>pos || tr<pos) return;
    if(tl==tr){
        chmin(t[v],val);
        return;
    }
    ll tm=(tl+tr)/2;
    upd(pos,val,v*2,tl,tm);
    upd(pos,val,v*2+1,tm+1,tr);
    t[v]=min(t[v*2],t[v*2+1]);
}
void solve(){
    ll i,j;
    cin>>n>>m;
    ll t[m+5],l[m+5],r[m+5],c[m+5];
    set<ll> st;
    for(i=1;i<=m;i++){
        cin>>t[i]>>l[i]>>r[i]>>c[i];
        st.ins(l[i]);
        st.ins(r[i]);
    }
    ll cnt=1;
    map<ll,ll> mp;
    if(*st.begin()>1 || *st.rbegin()<n){
        cout<<-1<<endl;
        return;
    }
    for(auto i : st){
        mp[i]=cnt++;
    }
    pll v;
    for(i=1;i<=m;i++){
        l[i]=mp[l[i]];
        r[i]=mp[r[i]];
        v.pb({r[i],i});
    }
    sort(all(v));
    for(i=0;i<m;i++){
        if(l[v[i].sc]==1){upd(v[i].fr,c[v[i].sc]);continue;}
        upd(v[i].fr,get(l[v[i].sc]-1,v[i].fr)+c[v[i].sc]);
    }
    cout<<get(st.sz,st.sz)<<endl;
}

signed main(){
	start();
    ll t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
/*




*/

Compilation message

treatment.cpp: In function 'void solve()':
treatment.cpp:64:10: warning: unused variable 'j' [-Wunused-variable]
   64 |     ll i,j;
      |          ^
# Verdict Execution time Memory Grader output
1 Runtime error 203 ms 80124 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Runtime error 14 ms 25948 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Runtime error 14 ms 25948 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 203 ms 80124 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -