Submission #546350

# Submission time Handle Problem Language Result Execution time Memory
546350 2022-04-07T10:50:12 Z krit3379 Pinball (JOI14_pinball) C++17
0 / 100
5 ms 6588 KB
#include<bits/stdc++.h>
using namespace std;
#define N 100005

int a[N],b[N],c[N],d[N];
long long l,r,ans=1e18;
vector<int> v;

class tree{
public:
    vector<long long> t;
    tree():t(4*N,1e18){}
    void update(int x,int l,int r,int i,long long val){
        if(l>c[i]||r<c[i])return ;
        if(l==r){
            t[x]=min(t[x],val);
            return ;
        }
        int mid=(l+r)/2;
        update(x*2,l,mid,i,val);
        update(x*2+1,mid+1,r,i,val);
        t[x]=min(t[x*2],t[x*2+1]);
    }
    long long sol(int x,int l,int r,int i){
        if(l>b[i]||a[i]>r)return 1e18;
        if(a[i]<=l&&r<=b[i])return t[x];
        int mid=(l+r)/2;
        return min(sol(x*2,l,mid,i),sol(x*2+1,mid+1,r,i));
    }
}t1,t2;

int main(){
    int n,m,i;
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
        v.push_back(a[i]);
        v.push_back(b[i]);
        v.push_back(c[i]);
    }
    v.push_back(-1);
    v.push_back(n);
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());
    for(i=1;i<=n;i++){
        a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
        b[i]=lower_bound(v.begin(),v.end(),b[i])-v.begin();
        c[i]=lower_bound(v.begin(),v.end(),c[i])-v.begin();
        if(a[i]!=1)l=t1.sol(1,1,v.size()-1,i);
        else l=0;
        if(b[i]!=v.size()-1)r=t2.sol(1,1,v.size()-1,i);
        else r=0;
        ans=min(ans,l+r+d[i]);
        t1.update(1,1,v.size()-1,i,l+d[i]);
        t2.update(1,1,v.size()-1,i,r+d[i]);
    }
    if(ans!=1e18)printf("%lld",ans);
    else printf("-1");
    return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         if(b[i]!=v.size()-1)r=t2.sol(1,1,v.size()-1,i);
      |            ~~~~^~~~~~~~~~~~
pinball.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
pinball.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6588 KB Output is correct
5 Correct 5 ms 6484 KB Output is correct
6 Correct 3 ms 6520 KB Output is correct
7 Incorrect 4 ms 6484 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6588 KB Output is correct
5 Correct 5 ms 6484 KB Output is correct
6 Correct 3 ms 6520 KB Output is correct
7 Incorrect 4 ms 6484 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6588 KB Output is correct
5 Correct 5 ms 6484 KB Output is correct
6 Correct 3 ms 6520 KB Output is correct
7 Incorrect 4 ms 6484 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6588 KB Output is correct
5 Correct 5 ms 6484 KB Output is correct
6 Correct 3 ms 6520 KB Output is correct
7 Incorrect 4 ms 6484 KB Output isn't correct
8 Halted 0 ms 0 KB -