Submission #1047050

# Submission time Handle Problem Language Result Execution time Memory
1047050 2024-08-07T08:09:19 Z 변재우(#11026) Treatment Project (JOI20_treatment) C++17
35 / 100
1902 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

const int Nmax=100010, S=(1<<17);
const ll INF=1e18;
int N, M;
ll ans=INF, D[Nmax];
struct Data {
    int t, l, r, c;
}A[Nmax];
vector<int> T, X1, X2;
priority_queue<pair<ll, int>> PQ;

struct Seg2D {
    struct Seg1D {
        struct Node {
            set<int> v; Node *l, *r;
        };
        Node *root;
        Seg1D() {root=new Node();}
        void Update(int k, int v) {Update(root, 1, S, k, v);}
        int Query(int l, int r) {return Query(root, 1, S, l, r);}
        void Delete(int k, int v) {Delete(root, 1, S, k, v);}
        void Update(Node *curr, int s, int e, int k, int v) {
            curr->v.insert(v);
            if(s==e) return;
            int m=(s+e)/2;
            if(k<=m) {
                if(!(curr->l)) curr->l=new Node();
                Update(curr->l, s, m, k, v);
            }
            else {
                if(!(curr->r)) curr->r=new Node();
                Update(curr->r, m+1, e, k, v);
            }
        }
        int Query(Node *curr, int s, int e, int l, int r) {
            if(!curr || s>r || l>e) return -1;
            if(l<=s && e<=r) {
                if(curr->v.empty()) return -1;
                return *(curr->v.begin());
            }
            int m=(s+e)/2;
            int tmp=Query(curr->l, s, m, l, r);
            if(tmp>0) return tmp;
            return Query(curr->r, m+1, e, l, r);
        }
        void Delete(Node *curr, int s, int e, int k, int v) {
            curr->v.erase(v);
            if(s==e) return;
            int m=(s+e)/2;
            if(k<=m) Delete(curr->l, s, m, k, v);
            else Delete(curr->r, m+1, e, k, v);
        }
    }Tree[2*S];
    void Update(int k, int x, int v) {Update(1, 1, S, k, x, v);}
    void Update(int node, int s, int e, int k, int x, int v) {
        Tree[node].Update(x, v);
        if(s==e) return;
        int lch=2*node, rch=lch+1, m=(s+e)/2;
        if(k<=m) Update(lch, s, m, k, x, v);
        else Update(rch, m+1, e, k, x, v);
    }
    int Query(int l, int r, int lo, int hi) {return Query(1, 1, S, l, r, lo, hi);}
    int Query(int node, int s, int e, int l, int r, int lo, int hi) {
        if(s>r || l>e) return -1;
        if(l<=s && e<=r) return Tree[node].Query(lo, hi);
        int lch=2*node, rch=lch+1, m=(s+e)/2;
        int tmp=Query(lch, s, m, l, r, lo, hi);
        if(tmp>0) return tmp;
        return Query(rch, m+1, e, l, r, lo, hi);
    }
    void Delete(int k, int x, int v) {Delete(1, 1, S, k, x, v);}
    void Delete(int node, int s, int e, int k, int x, int v) {
        Tree[node].Delete(x, v);
        if(s==e) return;
        int lch=2*node, rch=lch+1, m=(s+e)/2;
        if(k<=m) Delete(lch, s, m, k, x, v);
        else Delete(rch, m+1, e, k, x, v);
    }
}P, P2;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>M;
    for(int i=1; i<=M; i++) {
        cin>>A[i].t>>A[i].l>>A[i].r>>A[i].c;
        A[i].r++;
        T.push_back(A[i].t);
        X1.push_back(A[i].l-A[i].t), X2.push_back(A[i].l+A[i].t);
    }
    sort(T.begin(), T.end()), T.erase(unique(T.begin(), T.end()), T.end());
    sort(X1.begin(), X1.end()), X1.erase(unique(X1.begin(), X1.end()), X1.end());
    sort(X2.begin(), X2.end()), X2.erase(unique(X2.begin(), X2.end()), X2.end());
    fill(D+1, D+M+1, INF);
    for(int i=1; i<=M; i++) {
        if(A[i].l==1) {
            D[i]=A[i].c, PQ.push({-D[i], i});
            continue;
        }
        P.Update(lower_bound(T.begin(), T.end(), A[i].t)-T.begin()+1, lower_bound(X1.begin(), X1.end(), A[i].l-A[i].t)-X1.begin()+1, i);
        P2.Update(lower_bound(T.begin(), T.end(), A[i].t)-T.begin()+1, lower_bound(X2.begin(), X2.end(), A[i].l+A[i].t)-X2.begin()+1, i);
    }
    while(!PQ.empty()) {
        int i=PQ.top().second; ll d=-PQ.top().first; PQ.pop();
        if(d!=D[i]) continue;
        while(true) {
            int t=P.Query(1, lower_bound(T.begin(), T.end(), A[i].t)-T.begin()+1, 1, upper_bound(X1.begin(), X1.end(), A[i].r-A[i].t)-X1.begin());
            if(t<0) break;
            if(D[t]>D[i]+A[t].c) D[t]=D[i]+A[t].c, PQ.push({-D[t], t});
            P.Delete(lower_bound(T.begin(), T.end(), A[t].t)-T.begin()+1, lower_bound(X1.begin(), X1.end(), A[t].l-A[t].t)-X1.begin()+1, t);
            P2.Delete(lower_bound(T.begin(), T.end(), A[t].t)-T.begin()+1, lower_bound(X2.begin(), X2.end(), A[t].l+A[t].t)-X2.begin()+1, t);
        }
        while(true) {
            int t=P2.Query(lower_bound(T.begin(), T.end(), A[i].t)-T.begin()+1, T.size(), 1, upper_bound(X2.begin(), X2.end(), A[i].r+A[i].t)-X2.begin());
            if(t<0) break;
            if(D[t]>D[i]+A[t].c) D[t]=D[i]+A[t].c, PQ.push({-D[t], t});
            P.Delete(lower_bound(T.begin(), T.end(), A[t].t)-T.begin()+1, lower_bound(X1.begin(), X1.end(), A[t].l-A[t].t)-X1.begin()+1, t);
            P2.Delete(lower_bound(T.begin(), T.end(), A[t].t)-T.begin()+1, lower_bound(X2.begin(), X2.end(), A[t].l+A[t].t)-X2.begin()+1, t);
        }
        if(A[i].r==N+1) ans=min(ans, D[i]);
    }
    if(ans==INF) cout<<-1;
    else cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1902 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47536 KB Output is correct
2 Correct 18 ms 48224 KB Output is correct
3 Correct 18 ms 48072 KB Output is correct
4 Correct 19 ms 48216 KB Output is correct
5 Correct 19 ms 48240 KB Output is correct
6 Correct 23 ms 48176 KB Output is correct
7 Correct 25 ms 48312 KB Output is correct
8 Correct 31 ms 48208 KB Output is correct
9 Correct 19 ms 48472 KB Output is correct
10 Correct 29 ms 48220 KB Output is correct
11 Correct 25 ms 48220 KB Output is correct
12 Correct 20 ms 48216 KB Output is correct
13 Correct 22 ms 48216 KB Output is correct
14 Correct 19 ms 48376 KB Output is correct
15 Correct 19 ms 48172 KB Output is correct
16 Correct 19 ms 48220 KB Output is correct
17 Correct 24 ms 48364 KB Output is correct
18 Correct 21 ms 48128 KB Output is correct
19 Correct 21 ms 48212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47536 KB Output is correct
2 Correct 18 ms 48224 KB Output is correct
3 Correct 18 ms 48072 KB Output is correct
4 Correct 19 ms 48216 KB Output is correct
5 Correct 19 ms 48240 KB Output is correct
6 Correct 23 ms 48176 KB Output is correct
7 Correct 25 ms 48312 KB Output is correct
8 Correct 31 ms 48208 KB Output is correct
9 Correct 19 ms 48472 KB Output is correct
10 Correct 29 ms 48220 KB Output is correct
11 Correct 25 ms 48220 KB Output is correct
12 Correct 20 ms 48216 KB Output is correct
13 Correct 22 ms 48216 KB Output is correct
14 Correct 19 ms 48376 KB Output is correct
15 Correct 19 ms 48172 KB Output is correct
16 Correct 19 ms 48220 KB Output is correct
17 Correct 24 ms 48364 KB Output is correct
18 Correct 21 ms 48128 KB Output is correct
19 Correct 21 ms 48212 KB Output is correct
20 Correct 572 ms 195384 KB Output is correct
21 Correct 518 ms 195396 KB Output is correct
22 Correct 1105 ms 235256 KB Output is correct
23 Correct 934 ms 235464 KB Output is correct
24 Correct 725 ms 238988 KB Output is correct
25 Correct 896 ms 281664 KB Output is correct
26 Correct 652 ms 279412 KB Output is correct
27 Correct 470 ms 269388 KB Output is correct
28 Correct 665 ms 238672 KB Output is correct
29 Correct 760 ms 281392 KB Output is correct
30 Correct 344 ms 280176 KB Output is correct
31 Correct 279 ms 271656 KB Output is correct
32 Correct 885 ms 286548 KB Output is correct
33 Correct 888 ms 291156 KB Output is correct
34 Correct 906 ms 282436 KB Output is correct
35 Correct 928 ms 286752 KB Output is correct
36 Correct 888 ms 291156 KB Output is correct
37 Correct 878 ms 282704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1902 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -