답안 #1047043

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

const int Nmax=100010, INF=1e18, S=(1<<17);
int N, M, ans=INF, D[Nmax];
struct Data {
    int t, l, r, c;
}A[Nmax];
vector<int> T, X1, X2;
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);
        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, 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;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1665 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 45656 KB Output is correct
2 Correct 22 ms 46064 KB Output is correct
3 Correct 18 ms 46172 KB Output is correct
4 Correct 20 ms 46172 KB Output is correct
5 Correct 22 ms 46168 KB Output is correct
6 Correct 21 ms 46020 KB Output is correct
7 Correct 22 ms 46172 KB Output is correct
8 Correct 19 ms 46168 KB Output is correct
9 Correct 18 ms 46172 KB Output is correct
10 Correct 20 ms 46088 KB Output is correct
11 Correct 19 ms 46168 KB Output is correct
12 Correct 18 ms 46168 KB Output is correct
13 Correct 18 ms 46324 KB Output is correct
14 Correct 18 ms 46184 KB Output is correct
15 Correct 18 ms 46232 KB Output is correct
16 Correct 18 ms 46168 KB Output is correct
17 Correct 18 ms 46172 KB Output is correct
18 Correct 20 ms 46168 KB Output is correct
19 Correct 19 ms 46172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 45656 KB Output is correct
2 Correct 22 ms 46064 KB Output is correct
3 Correct 18 ms 46172 KB Output is correct
4 Correct 20 ms 46172 KB Output is correct
5 Correct 22 ms 46168 KB Output is correct
6 Correct 21 ms 46020 KB Output is correct
7 Correct 22 ms 46172 KB Output is correct
8 Correct 19 ms 46168 KB Output is correct
9 Correct 18 ms 46172 KB Output is correct
10 Correct 20 ms 46088 KB Output is correct
11 Correct 19 ms 46168 KB Output is correct
12 Correct 18 ms 46168 KB Output is correct
13 Correct 18 ms 46324 KB Output is correct
14 Correct 18 ms 46184 KB Output is correct
15 Correct 18 ms 46232 KB Output is correct
16 Correct 18 ms 46168 KB Output is correct
17 Correct 18 ms 46172 KB Output is correct
18 Correct 20 ms 46168 KB Output is correct
19 Correct 19 ms 46172 KB Output is correct
20 Correct 512 ms 195408 KB Output is correct
21 Correct 495 ms 195448 KB Output is correct
22 Correct 981 ms 235360 KB Output is correct
23 Correct 844 ms 235344 KB Output is correct
24 Correct 627 ms 239056 KB Output is correct
25 Correct 739 ms 281940 KB Output is correct
26 Correct 619 ms 279404 KB Output is correct
27 Correct 463 ms 269648 KB Output is correct
28 Correct 632 ms 238676 KB Output is correct
29 Correct 680 ms 281436 KB Output is correct
30 Correct 363 ms 280288 KB Output is correct
31 Correct 279 ms 271696 KB Output is correct
32 Correct 866 ms 287116 KB Output is correct
33 Correct 787 ms 291156 KB Output is correct
34 Correct 815 ms 282704 KB Output is correct
35 Correct 814 ms 286960 KB Output is correct
36 Correct 816 ms 291400 KB Output is correct
37 Correct 852 ms 282708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1665 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -