Submission #1008419

# Submission time Handle Problem Language Result Execution time Memory
1008419 2024-06-26T12:11:57 Z iee Treatment Project (JOI20_treatment) C++17
100 / 100
97 ms 19144 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define x first
#define y second
#define bg begin()
#define ed end()
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define R(i,n) for(int i(0);i<(n);++i)
#define L(i,n) for(int i((n)-1);i>=0;--i)
const int iinf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;

//Data
const int N=1e5;
int m,n;
ll f[N];
struct info{
    int t,l,r,c;
    info(){}
    info(int t,int l,int r,int c):
        t(t),l(l),r(r),c(c){}
}a[N];

//Graph
/*
    思考:什么时候 i 后面可以接 j?
        a[i].r-a[j].l>=abs(a[i].t-a[j].t)
    如果 a[j].t<a[i].t,要求就是
        a[i].r-a[i].t>=a[j].l-a[j].t ->up
    如果 a[j].t>a[i].t,要求就是
        a[i].r+a[i].t>=a[j].l+a[j].t ->dn
    
    这题有个关键点:权在点上,所以 dijkstra 可以爽一点
*/
vector<int> adj; // 记得清空
priority_queue<pair<ll,int>> q;

//SegmentTree
struct tree{
    int l,r,mid,ma,mb; tree *ls,*rs;
    tree(int l,int r):l(l),r(r),ma(iinf*2),mb(iinf*2){
        if(r-l==1) return;
        mid=(l+r)>>1,ls=new tree(l,mid),rs=new tree(mid,r);
    }
    void pushup(){
        ma=min(ls->ma,rs->ma);
        mb=min(ls->mb,rs->mb);
    }
    void fix(int i,int a,int b){
        if(r-l==1) return ma=a,mb=b,void();
        i<mid?ls->fix(i,a,b):rs->fix(i,a,b),pushup();
    }
    void adde(int x,int y,int mx,bool t){
        if((t?ma:mb)>mx) return;
        if(r-l==1) return ma=mb=iinf*2,adj.pb(l);
        if(x<mid) ls->adde(x,y,mx,t);
        if(y>mid) rs->adde(x,y,mx,t);
        pushup();
    }
};

//Function

//Main
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>m>>n;
    R(i,n) cin>>a[i].t>>a[i].l>>a[i].r>>a[i].c,--a[i].t,--a[i].l;
    sort(a,a+n,[&](info p,info q){return p.t<q.t;});
    tree *rt=new tree(0,n);
    R(i,n){
        if(a[i].l==0) f[i]=a[i].c,
            q.push(mp(-f[i],i)),rt->fix(i,iinf*2,iinf*2);
        else rt->fix(i,a[i].l-a[i].t,a[i].l+a[i].t),f[i]=linf;
    }
    vector<int> vis(n + 1);
    while(sz(q)){
        int u=q.top().y; q.pop(),adj.clear();
        vis[u] = 1;
        rt->adde(0,u,a[u].r-a[u].t,true);
        rt->adde(u+1,n,a[u].r+a[u].t,false);
        for(int v:adj) assert(!vis[v]), f[v]=f[u]+a[v].c,q.push(mp(-f[v],v));
    }
    ll ns=linf;
    R(i,n)if(a[i].r==m) ns=min(ns,f[i]);
    if(ns==linf) ns=-1;
    cout<<ns<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 75 ms 15696 KB Output is correct
2 Correct 57 ms 15764 KB Output is correct
3 Correct 72 ms 15976 KB Output is correct
4 Correct 66 ms 15308 KB Output is correct
5 Correct 60 ms 17872 KB Output is correct
6 Correct 70 ms 15700 KB Output is correct
7 Correct 75 ms 15440 KB Output is correct
8 Correct 42 ms 15564 KB Output is correct
9 Correct 39 ms 15440 KB Output is correct
10 Correct 50 ms 15440 KB Output is correct
11 Correct 59 ms 17984 KB Output is correct
12 Correct 55 ms 19144 KB Output is correct
13 Correct 69 ms 17628 KB Output is correct
14 Correct 81 ms 17620 KB Output is correct
15 Correct 69 ms 15696 KB Output is correct
16 Correct 72 ms 15700 KB Output is correct
17 Correct 68 ms 14808 KB Output is correct
18 Correct 52 ms 17356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 4 ms 3144 KB Output is correct
21 Correct 5 ms 3164 KB Output is correct
22 Correct 4 ms 3160 KB Output is correct
23 Correct 4 ms 3164 KB Output is correct
24 Correct 3 ms 3256 KB Output is correct
25 Correct 4 ms 3160 KB Output is correct
26 Correct 4 ms 3164 KB Output is correct
27 Correct 4 ms 3176 KB Output is correct
28 Correct 4 ms 3164 KB Output is correct
29 Correct 4 ms 3152 KB Output is correct
30 Correct 3 ms 3164 KB Output is correct
31 Correct 4 ms 3144 KB Output is correct
32 Correct 5 ms 3420 KB Output is correct
33 Correct 3 ms 3396 KB Output is correct
34 Correct 4 ms 3148 KB Output is correct
35 Correct 3 ms 3420 KB Output is correct
36 Correct 4 ms 3688 KB Output is correct
37 Correct 3 ms 3160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 15696 KB Output is correct
2 Correct 57 ms 15764 KB Output is correct
3 Correct 72 ms 15976 KB Output is correct
4 Correct 66 ms 15308 KB Output is correct
5 Correct 60 ms 17872 KB Output is correct
6 Correct 70 ms 15700 KB Output is correct
7 Correct 75 ms 15440 KB Output is correct
8 Correct 42 ms 15564 KB Output is correct
9 Correct 39 ms 15440 KB Output is correct
10 Correct 50 ms 15440 KB Output is correct
11 Correct 59 ms 17984 KB Output is correct
12 Correct 55 ms 19144 KB Output is correct
13 Correct 69 ms 17628 KB Output is correct
14 Correct 81 ms 17620 KB Output is correct
15 Correct 69 ms 15696 KB Output is correct
16 Correct 72 ms 15700 KB Output is correct
17 Correct 68 ms 14808 KB Output is correct
18 Correct 52 ms 17356 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 4 ms 3144 KB Output is correct
39 Correct 5 ms 3164 KB Output is correct
40 Correct 4 ms 3160 KB Output is correct
41 Correct 4 ms 3164 KB Output is correct
42 Correct 3 ms 3256 KB Output is correct
43 Correct 4 ms 3160 KB Output is correct
44 Correct 4 ms 3164 KB Output is correct
45 Correct 4 ms 3176 KB Output is correct
46 Correct 4 ms 3164 KB Output is correct
47 Correct 4 ms 3152 KB Output is correct
48 Correct 3 ms 3164 KB Output is correct
49 Correct 4 ms 3144 KB Output is correct
50 Correct 5 ms 3420 KB Output is correct
51 Correct 3 ms 3396 KB Output is correct
52 Correct 4 ms 3148 KB Output is correct
53 Correct 3 ms 3420 KB Output is correct
54 Correct 4 ms 3688 KB Output is correct
55 Correct 3 ms 3160 KB Output is correct
56 Correct 69 ms 16336 KB Output is correct
57 Correct 64 ms 16080 KB Output is correct
58 Correct 59 ms 14672 KB Output is correct
59 Correct 64 ms 15184 KB Output is correct
60 Correct 68 ms 15956 KB Output is correct
61 Correct 61 ms 14688 KB Output is correct
62 Correct 60 ms 16332 KB Output is correct
63 Correct 65 ms 15696 KB Output is correct
64 Correct 63 ms 15784 KB Output is correct
65 Correct 75 ms 15696 KB Output is correct
66 Correct 77 ms 15952 KB Output is correct
67 Correct 75 ms 16464 KB Output is correct
68 Correct 92 ms 16468 KB Output is correct
69 Correct 83 ms 16344 KB Output is correct
70 Correct 80 ms 16464 KB Output is correct
71 Correct 84 ms 16208 KB Output is correct
72 Correct 76 ms 16452 KB Output is correct
73 Correct 97 ms 16468 KB Output is correct
74 Correct 45 ms 16212 KB Output is correct
75 Correct 46 ms 16356 KB Output is correct
76 Correct 64 ms 18504 KB Output is correct
77 Correct 66 ms 18628 KB Output is correct
78 Correct 74 ms 18124 KB Output is correct
79 Correct 87 ms 16356 KB Output is correct
80 Correct 79 ms 15972 KB Output is correct
81 Correct 48 ms 16260 KB Output is correct
82 Correct 72 ms 15460 KB Output is correct
83 Correct 78 ms 15936 KB Output is correct
84 Correct 84 ms 15528 KB Output is correct
85 Correct 72 ms 16456 KB Output is correct
86 Correct 75 ms 16344 KB Output is correct
87 Correct 72 ms 16468 KB Output is correct
88 Correct 81 ms 16468 KB Output is correct
89 Correct 68 ms 16488 KB Output is correct
90 Correct 65 ms 18888 KB Output is correct
91 Correct 76 ms 17620 KB Output is correct
92 Correct 68 ms 16464 KB Output is correct
93 Correct 90 ms 16488 KB Output is correct
94 Correct 71 ms 16464 KB Output is correct
95 Correct 85 ms 16216 KB Output is correct
96 Correct 67 ms 18628 KB Output is correct
97 Correct 61 ms 18524 KB Output is correct
98 Correct 77 ms 18692 KB Output is correct
99 Correct 64 ms 18680 KB Output is correct
100 Correct 64 ms 18636 KB Output is correct
101 Correct 67 ms 18632 KB Output is correct
102 Correct 64 ms 19000 KB Output is correct
103 Correct 71 ms 16844 KB Output is correct