Submission #259960

# Submission time Handle Problem Language Result Execution time Memory
259960 2020-08-08T21:03:29 Z thebes Treatment Project (JOI20_treatment) C++14
5 / 100
3000 ms 472164 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define F first
#define S second

const int MN = 1e5+5;
const ll inf = 1e12;
ll N, M, i, j, x, y, c, t, dis[MN], vs[MN], ans=1LL<<60;
struct idk{ll a,b,c,d;}arr[MN],go[MN];
map<ll,ll> mpx, mpy; vector<ll> ed;
struct pq{bool operator()(const pll&i,const pll&j){return i.S>j.S;}};
priority_queue<pll,vector<pll>,pq> q;

struct segtree{
    set<pii> st[6*MN], st2[6*MN]; ll n, c;
    void init(ll N){n=N;}
    void upd(ll i,ll s,ll e,ll ss,ll se,ll val,ll id){
        if(s>=ss&&e<=se) st2[i].insert({val,id});
        else st[i].insert({val,id});
        if(s>=ss&&e<=se) return;
        else if((s+e)/2<ss) upd(2*i+1,(s+e)/2+1,e,ss,se,val,id);
        else if((s+e)/2>=se) upd(2*i,s,(s+e)/2,ss,se,val,id);
        else upd(2*i,s,(s+e)/2,ss,se,val,id), upd(2*i+1,(s+e)/2+1,e,ss,se,val,id);
    }
    inline void update(ll s,ll e,ll c,ll id){
        upd(1,1,n,s,e,c,id);
    }
    void qu(ll i,ll s,ll e,ll ss,ll se,ll a,ll b){
        auto it=st2[i].lower_bound({a,0});
        while(it!=st2[i].end()&&it->first<=b){
            if(!vs[it->second]){
                vs[it->second]=1;
                q.push({it->second,c+arr[it->second].c});
            }
            auto it2=it; it++;
            st2[i].erase(it2);
        }
        if(s>=ss&&e<=se){
            auto it=st[i].lower_bound({a,0});
            while(it!=st[i].end()&&it->first<=b){
                if(!vs[it->second]){
                    vs[it->second]=1;
                    q.push({it->second,c+arr[it->second].c});
                }
                auto it2=it; it++;
                st[i].erase(it2);
            }
        }
        else{
            if((s+e)/2<ss) qu(2*i+1,(s+e)/2+1,e,ss,se,a,b);
            else if((s+e)/2>=se) qu(2*i,s,(s+e)/2,ss,se,a,b);
            else qu(2*i,s,(s+e)/2,ss,se,a,b),qu(2*i+1,(s+e)/2+1,e,ss,se,a,b);
        }
    }
    inline void query(ll s,ll e,ll x,ll y,ll cur){
        c = cur;
        qu(1,1,n,s,e,x,y);
    }
}stx, sty;

int main(){
    scanf("%lld%lld",&N,&M);
    for(i=1;i<=M;i++){
        scanf("%lld%lld%lld%lld",&t,&x,&y,&c);
        arr[i]={x,y,c,t};
        if(x==1) q.push({i,c}), x=-inf, vs[i]=1;
        if(y==N) ed.push_back(i), y=inf;
        y++;
        ll sx = t-y, ex = t-x;
        ll sy = t+x, ey = t+y;
        go[i]={sx,ex,sy,ey};
        mpx[sx]=mpx[ex]=mpy[sy]=mpy[ey]=0;
    }
    i=0; stx.init(mpx.size());
    for(auto it=mpx.begin();it!=mpx.end();it++)
        it->second = ++i;
    i=0; sty.init(mpy.size());
    for(auto it=mpy.begin();it!=mpy.end();it++)
        it->second = ++i;
    for(i=1;i<=M;i++){
        go[i].a=mpx[go[i].a]; go[i].b=mpx[go[i].b];
        go[i].c=mpy[go[i].c]; go[i].d=mpy[go[i].d];
        stx.update(go[i].a,go[i].b,go[i].c,i);
        stx.update(go[i].a,go[i].b,go[i].d,i);
        sty.update(go[i].c,go[i].d,go[i].a,i);
        sty.update(go[i].c,go[i].d,go[i].b,i);
    }
    memset(dis,-1,sizeof(dis));
    while(q.size()){
        pll x=q.top(); q.pop();
        dis[x.F]=x.S;
        int id = x.F;
        stx.query(go[id].a,go[id].b,go[id].c,go[id].d,x.S);
        sty.query(go[id].c,go[id].d,go[id].a,go[id].b,x.S);
    }
    for(auto v : ed){
        if(dis[v]!=-1) ans=min(ans,dis[v]);
    }
    printf("%lld\n",ans==1LL<<60?-1:ans);
    return 0;
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&N,&M);
     ~~~~~^~~~~~~~~~~~~~~~~~
treatment.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld%lld",&t,&x,&y,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 3107 ms 472164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 113784 KB Output is correct
2 Correct 90 ms 113912 KB Output is correct
3 Correct 78 ms 113912 KB Output is correct
4 Correct 78 ms 113912 KB Output is correct
5 Correct 79 ms 113912 KB Output is correct
6 Correct 75 ms 113912 KB Output is correct
7 Correct 75 ms 113912 KB Output is correct
8 Correct 74 ms 113912 KB Output is correct
9 Correct 74 ms 113912 KB Output is correct
10 Correct 75 ms 113912 KB Output is correct
11 Correct 74 ms 113912 KB Output is correct
12 Correct 74 ms 113912 KB Output is correct
13 Correct 77 ms 113912 KB Output is correct
14 Correct 77 ms 113912 KB Output is correct
15 Correct 85 ms 113928 KB Output is correct
16 Correct 84 ms 113880 KB Output is correct
17 Correct 93 ms 113912 KB Output is correct
18 Correct 91 ms 113912 KB Output is correct
19 Correct 92 ms 113912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 113784 KB Output is correct
2 Correct 90 ms 113912 KB Output is correct
3 Correct 78 ms 113912 KB Output is correct
4 Correct 78 ms 113912 KB Output is correct
5 Correct 79 ms 113912 KB Output is correct
6 Correct 75 ms 113912 KB Output is correct
7 Correct 75 ms 113912 KB Output is correct
8 Correct 74 ms 113912 KB Output is correct
9 Correct 74 ms 113912 KB Output is correct
10 Correct 75 ms 113912 KB Output is correct
11 Correct 74 ms 113912 KB Output is correct
12 Correct 74 ms 113912 KB Output is correct
13 Correct 77 ms 113912 KB Output is correct
14 Correct 77 ms 113912 KB Output is correct
15 Correct 85 ms 113928 KB Output is correct
16 Correct 84 ms 113880 KB Output is correct
17 Correct 93 ms 113912 KB Output is correct
18 Correct 91 ms 113912 KB Output is correct
19 Correct 92 ms 113912 KB Output is correct
20 Correct 363 ms 144316 KB Output is correct
21 Correct 376 ms 144248 KB Output is correct
22 Correct 259 ms 134136 KB Output is correct
23 Correct 245 ms 134136 KB Output is correct
24 Correct 449 ms 145144 KB Output is correct
25 Incorrect 314 ms 138872 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3107 ms 472164 KB Time limit exceeded
2 Halted 0 ms 0 KB -