답안 #1047040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047040 2024-08-07T08:01:14 Z 변재우(#11026) 치료 계획 (JOI20_treatment) C++17
35 / 100
1437 ms 524288 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int Nmax=100010, INF=1e18, S=(1<<18);
int N, M, ans=INF, D[Nmax];
struct Data {
    int t, l, r, c;
}A[Nmax];
vector<int> T, X;
priority_queue<pair<int, 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);
        X.push_back(A[i].l-A[i].t), X.push_back(A[i].l+A[i].t);
    }
    sort(T.begin(), T.end()), T.erase(unique(T.begin(), T.end()), T.end());
    sort(X.begin(), X.end()), X.erase(unique(X.begin(), X.end()), X.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(X.begin(), X.end(), A[i].l-A[i].t)-X.begin()+1, i);
        P2.Update(lower_bound(T.begin(), T.end(), A[i].t)-T.begin()+1, lower_bound(X.begin(), X.end(), A[i].l+A[i].t)-X.begin()+1, i);
    }
    while(!PQ.empty()) {
        int i=PQ.top().second, 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(X.begin(), X.end(), A[i].r-A[i].t)-X.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(X.begin(), X.end(), A[t].l-A[t].t)-X.begin()+1, t);
            P2.Delete(lower_bound(T.begin(), T.end(), A[t].t)-T.begin()+1, lower_bound(X.begin(), X.end(), A[t].l+A[t].t)-X.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(X.begin(), X.end(), A[i].r+A[i].t)-X.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(X.begin(), X.end(), A[t].l-A[t].t)-X.begin()+1, t);
            P2.Delete(lower_bound(T.begin(), T.end(), A[t].t)-T.begin()+1, lower_bound(X.begin(), X.end(), A[t].l+A[t].t)-X.begin()+1, t);
        }
        if(A[i].r==N+1) ans=min(ans, D[i]);
    }
    if(ans==INF) cout<<-1;
    else cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1437 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 90712 KB Output is correct
2 Correct 45 ms 91328 KB Output is correct
3 Correct 37 ms 91220 KB Output is correct
4 Correct 39 ms 91476 KB Output is correct
5 Correct 37 ms 91472 KB Output is correct
6 Correct 43 ms 91216 KB Output is correct
7 Correct 37 ms 91484 KB Output is correct
8 Correct 46 ms 91552 KB Output is correct
9 Correct 42 ms 91472 KB Output is correct
10 Correct 37 ms 91412 KB Output is correct
11 Correct 36 ms 91476 KB Output is correct
12 Correct 40 ms 91436 KB Output is correct
13 Correct 36 ms 91368 KB Output is correct
14 Correct 36 ms 91484 KB Output is correct
15 Correct 36 ms 91288 KB Output is correct
16 Correct 42 ms 91380 KB Output is correct
17 Correct 35 ms 91484 KB Output is correct
18 Correct 35 ms 91352 KB Output is correct
19 Correct 35 ms 91416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 90712 KB Output is correct
2 Correct 45 ms 91328 KB Output is correct
3 Correct 37 ms 91220 KB Output is correct
4 Correct 39 ms 91476 KB Output is correct
5 Correct 37 ms 91472 KB Output is correct
6 Correct 43 ms 91216 KB Output is correct
7 Correct 37 ms 91484 KB Output is correct
8 Correct 46 ms 91552 KB Output is correct
9 Correct 42 ms 91472 KB Output is correct
10 Correct 37 ms 91412 KB Output is correct
11 Correct 36 ms 91476 KB Output is correct
12 Correct 40 ms 91436 KB Output is correct
13 Correct 36 ms 91368 KB Output is correct
14 Correct 36 ms 91484 KB Output is correct
15 Correct 36 ms 91288 KB Output is correct
16 Correct 42 ms 91380 KB Output is correct
17 Correct 35 ms 91484 KB Output is correct
18 Correct 35 ms 91352 KB Output is correct
19 Correct 35 ms 91416 KB Output is correct
20 Correct 611 ms 255824 KB Output is correct
21 Correct 602 ms 255824 KB Output is correct
22 Correct 1202 ms 299636 KB Output is correct
23 Correct 1043 ms 299860 KB Output is correct
24 Correct 750 ms 304728 KB Output is correct
25 Correct 953 ms 351312 KB Output is correct
26 Correct 718 ms 349012 KB Output is correct
27 Correct 517 ms 336208 KB Output is correct
28 Correct 773 ms 304464 KB Output is correct
29 Correct 890 ms 351060 KB Output is correct
30 Correct 458 ms 351824 KB Output is correct
31 Correct 363 ms 339392 KB Output is correct
32 Correct 1020 ms 356644 KB Output is correct
33 Correct 985 ms 368208 KB Output is correct
34 Correct 1014 ms 361408 KB Output is correct
35 Correct 1030 ms 356808 KB Output is correct
36 Correct 994 ms 368504 KB Output is correct
37 Correct 1034 ms 361556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1437 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -