Submission #492553

# Submission time Handle Problem Language Result Execution time Memory
492553 2021-12-07T22:17:24 Z Urvuk3 Pinball (JOI14_pinball) C++17
0 / 100
205 ms 524292 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
const ll MAXN=1e6+5,MAXA=5e6+5,INF=1e9,LINF=1e18;
#define fi first
#define se second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mid (l+r)/2
#define sz(a) int((a).size())
#define all(a) a.begin(),a.end()
#define mod 1000000007LL
#define pb push_back
#define endl "\n"
#define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush;
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
#define PRINTvec(x) { cerr<<#x<<"-"; for(int i=0;i<sz(x);i++) cerr<<x[i]<<" "; cerr<<endl; }

ll n,m,k,q,x,y,z,res=LINF,l,r;
string s,t;
ifstream input;
ofstream output;

#ifdef ONLINE_JUDGE
    #define input cin
    #define output cout
#endif

vector<ll> segL(4*MAXN,LINF),segR(4*MAXN,LINF);
vector<ll> dpL(MAXN),dpR(MAXN);

void updatesegL(int node,int l,int r,int idx,ll val){
    if(l==r){
        segL[node]=min(segL[node],val);
        return;
    }
    if(idx<=mid) updatesegL(2*node,l,mid,idx,val);
    else updatesegL(2*node+1,mid+1,r,idx,val);
    segL[node]=min(segL[2*node],segL[2*node+1]);
}

ll querysegL(int node,int l,int r,int L,int R){
    if(L<=l && r<=R){
        return segL[node];
    }
    ll ret=LINF;
    if(L<=mid) ret=min(ret,querysegL(2*node,l,mid,L,R));
    if(R>mid) ret=min(ret,querysegL(2*node+1,mid+1,r,L,R));
    return ret;
}

void updatesegR(int node,int l,int r,int idx,ll val){
    if(l==r){
        segR[node]=min(segR[node],val);
        return;
    }
    if(idx<=mid) updatesegR(2*node,l,mid,idx,val);
    else updatesegR(2*node+1,mid+1,r,idx,val);
    segR[node]=min(segR[2*node],segR[2*node+1]);
}

ll querysegR(int node,int l,int r,int L,int R){
    if(L<=l && r<=R){
        return segR[node];
    }
    ll ret=LINF;
    if(L<=mid) ret=min(ret,querysegR(2*node,l,mid,L,R));
    if(R>mid) ret=min(ret,querysegR(2*node+1,mid+1,r,L,R));
    return ret;
}

struct dev{
    int a,b,c,d;
    void input(){
        cin>>a>>b>>c>>d;
    }
    void output(){
        cout<<"a="<<a<<" b="<<b<<" c="<<c<<" d="<<d<<endl;
    }
};

vector<dev> a;

void solve(){
    cin>>n>>m;
    a.resize(n+1);
    for(int i=1;i<=n;i++) a[i].input();
    for(int i=1;i<=n;i++){
        if(a[i].a==1) dpL[i]=a[i].d;
        else dpL[i]=querysegL(1,1,n,a[i].a,a[i].b)+a[i].d;
        if(a[i].b==m) dpR[i]=a[i].d;
        else dpR[i]=querysegR(1,1,n,a[i].a,a[i].b)+a[i].d;
        updatesegL(1,1,n,a[i].c,dpL[i]); updatesegR(1,1,n,a[i].c,dpR[i]);
    }
    /*
    for(int i=1;i<=n;i++){
        ///cout<<"dpL["<<i<<"]="<<dpL[i]<<endl;
        ///cout<<"dpR["<<i<<"]="<<dpR[i]<<endl;
        if(dpL[i]>=LINF || dpR[i]>=LINF) continue;
        res=min(res,dpL[i]+dpR[i]-a[i].d);
    }
    cout<<(res!=LINF ? res : -1)<<endl;
    */
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        input.open("D:\\UROS\\Programiranje\\input.in",ios::in);
	output.open("D:\\UROS\\Programiranje\\output.out",ios::out|ios::trunc);
    #endif
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 205 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 205 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 205 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 205 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -