Submission #442071

# Submission time Handle Problem Language Result Execution time Memory
442071 2021-07-07T03:50:21 Z zaneyu Pinball (JOI14_pinball) C++14
51 / 100
444 ms 28916 KB
/*input
3 5
2 4 3 10
1 3 1 20
2 5 4 30
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=1e18+1;
const int INF=0x3f3f3f3f;
int MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-3;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
inline ll mult(ll a,ll b){
    if(a>=MOD) a%=MOD;
    if(b>=MOD) b%=MOD;
    return (a*b)%MOD;
}
inline ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const int maxn=3e5+5;
const int maxlg=__lg(maxn)+2;
struct seg{
    ll seg[4*maxn];
    void upd(int idx,int l,int r,int p,ll x){
        if(r<p or l>p) return;
        if(l==r){
            seg[idx]=x;
            return;
        }
        int mid=(l+r)/2;
        upd(idx*2,l,mid,p,x);
        upd(idx*2+1,mid+1,r,p,x);
        seg[idx]=min(seg[idx*2],seg[idx*2+1]);
    }
    ll query(int idx,int l,int r,int ql,int qr){
        if(r<ql or l>qr) return INF64;
        if(ql<=l and r<=qr) return seg[idx];
        int mid=(l+r)/2;
        return min(query(idx*2,l,mid,ql,qr),query(idx*2+1,mid+1,r,ql,qr));
    }
}dp1,dp2;
ll vdp1[maxn],vdp2[maxn];
int l[maxn],r[maxn],a[maxn],c[maxn];
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> v;
    REP(i,n){
        cin>>l[i]>>r[i]>>a[i]>>c[i];
        v.pb(a[i]),v.pb(l[i]),v.pb(r[i]);
        if(l[i]>1) v.pb(l[i]-1);
        if(r[i]<m) v.pb(r[i]+1);
    }
    SORT_UNIQUE(v);
    m=sz(v);
    REP(i,n){
        l[i]=lower_bound(ALL(v),l[i])-v.begin();
        r[i]=lower_bound(ALL(v),r[i])-v.begin();
        a[i]=lower_bound(ALL(v),a[i])-v.begin();
    }
    REP1(i,m-1) dp1.upd(1,0,m-1,i,INF64),vdp1[i]=INF64;
    REP(i,m-1) dp2.upd(1,0,m-1,i,INF64),vdp2[i]=INF64;
    ll ans=INF64;
    REP(i,n){
        ll c1=dp1.query(1,0,m-1,l[i],r[i]),c2=dp2.query(1,0,m-1,l[i],r[i]);
        //cout<<c1<<' '<<c2<<'\n';
        MNTO(vdp1[a[i]],c1+c[i]);
        MNTO(vdp2[a[i]],c2+c[i]);
        MNTO(ans,c1+c2+c[i]);
        dp1.upd(1,0,m-1,a[i],vdp1[a[i]]);
        dp2.upd(1,0,m-1,a[i],vdp2[a[i]]);
    }
    if(ans==INF64) ans=-1;
    cout<<ans<<'\n';
}  
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 3 ms 716 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 3 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 3 ms 716 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 3 ms 716 KB Output is correct
25 Correct 33 ms 2172 KB Output is correct
26 Correct 88 ms 6796 KB Output is correct
27 Correct 220 ms 13260 KB Output is correct
28 Correct 162 ms 7880 KB Output is correct
29 Correct 175 ms 10324 KB Output is correct
30 Correct 223 ms 9188 KB Output is correct
31 Correct 444 ms 19640 KB Output is correct
32 Correct 329 ms 18484 KB Output is correct
33 Correct 64 ms 7424 KB Output is correct
34 Correct 209 ms 16180 KB Output is correct
35 Incorrect 336 ms 28916 KB Output isn't correct
36 Halted 0 ms 0 KB -