답안 #295295

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295295 2020-09-09T15:09:42 Z 반딧불(#5812) 치료 계획 (JOI20_treatment) C++17
100 / 100
981 ms 91260 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Plan{
    ll t, l, r, cost;
    Plan(){}
    Plan(ll t, ll l, ll r, ll cost): t(t), l(l), r(r), cost(cost){}
};

struct Point{
    ll x, y; int idx;
    Point(){}
    Point(ll x, ll y, int idx): x(x), y(y), idx(idx){}

    bool operator<(const Point &r)const{
        return y>r.y;
    }
};

struct dat{
    int x; ll y;
    dat(){}
    dat(int x, ll y): x(x), y(y){}

    bool operator<(const dat &r)const{
        return y>r.y;
    }
};

vector<int> retVal;
struct segTree{
    vector<Point> tree[400002];
    void initialize(int i, int l, int r){
        sort(tree[i].begin(), tree[i].end());
        if(l==r) return;
        int m = (l+r)>>1;
        initialize(i*2, l, m), initialize(i*2+1, m+1, r);
    }
    void pushPoint(int i, int l, int r, Point p){
        tree[i].push_back(p);
        if(l==r) return;
        int m = (l+r)>>1;
        if(p.x <= m) pushPoint(i*2, l, m, p);
        else pushPoint(i*2+1, m+1, r, p);
    }

    void rectQuery(int i, int l, int r, int xLim, ll yLim){
        if(xLim < l) return;
        if(r<=xLim){
            while(!tree[i].empty() && tree[i].back().y <= yLim){
                retVal.push_back(tree[i].back().idx);
                tree[i].pop_back();
            }
            return;
        }
        int m = (l+r)>>1;
        rectQuery(i*2, l, m, xLim, yLim), rectQuery(i*2+1, m+1, r, xLim, yLim);
    }
} tree;

int n, m;
Plan arr[100002];
bool chk[100002];
ll ans = LLONG_MAX;
priority_queue<dat> pq;
vector<Point> pointVec;
vector<ll> renVec;

void makeSegTree(){
    for(auto &x: pointVec) renVec.push_back(x.x);
    sort(renVec.begin(), renVec.end());
    renVec.erase(unique(renVec.begin(), renVec.end()), renVec.end());
    for(auto &x: pointVec) x.x = lower_bound(renVec.begin(), renVec.end(), x.x) - renVec.begin() + 1;

    for(auto &x: pointVec) tree.pushPoint(1, 1, m, x);
    tree.initialize(1, 1, m);
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=m; i++){
        scanf("%lld %lld %lld %lld", &arr[i].t, &arr[i].l, &arr[i].r, &arr[i].cost);
        arr[i].r++;
        if(arr[i].l == 1) pq.push(dat(i, arr[i].cost));
        else pointVec.push_back(Point(arr[i].l + arr[i].t, arr[i].l - arr[i].t, i));
    }

    makeSegTree();

    while(!pq.empty()){
        auto tmp = pq.top(); pq.pop();
        if(chk[tmp.x]) continue;
        int tx = tmp.x; ll ty = tmp.y;
        chk[tx] = 1;
        if(arr[tx].r == n+1) ans = min(ans, ty);

        int xLim = arr[tx].r + arr[tx].t; ll yLim = arr[tx].r - arr[tx].t;
        xLim = upper_bound(renVec.begin(), renVec.end(), xLim) - renVec.begin();

        retVal.clear(); retVal.shrink_to_fit();
        tree.rectQuery(1, 1, m, xLim, yLim);
        for(auto nxt: retVal){
            if(chk[nxt]) continue;
            pq.push(dat(nxt, ty+arr[nxt].cost));
        }
    }
    printf("%lld", ans == LLONG_MAX ? -1 : ans);
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   83 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
treatment.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   85 |         scanf("%lld %lld %lld %lld", &arr[i].t, &arr[i].l, &arr[i].r, &arr[i].cost);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 493 ms 69616 KB Output is correct
2 Correct 380 ms 72032 KB Output is correct
3 Correct 497 ms 66068 KB Output is correct
4 Correct 531 ms 66964 KB Output is correct
5 Correct 375 ms 77152 KB Output is correct
6 Correct 288 ms 73956 KB Output is correct
7 Correct 285 ms 67688 KB Output is correct
8 Correct 194 ms 67176 KB Output is correct
9 Correct 221 ms 72800 KB Output is correct
10 Correct 210 ms 67172 KB Output is correct
11 Correct 821 ms 90444 KB Output is correct
12 Correct 806 ms 90324 KB Output is correct
13 Correct 796 ms 81964 KB Output is correct
14 Correct 907 ms 81880 KB Output is correct
15 Correct 465 ms 72220 KB Output is correct
16 Correct 473 ms 72676 KB Output is correct
17 Correct 441 ms 71528 KB Output is correct
18 Correct 658 ms 89560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9728 KB Output is correct
2 Correct 8 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 10 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 8 ms 9728 KB Output is correct
19 Correct 7 ms 9728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9728 KB Output is correct
2 Correct 8 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 10 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 8 ms 9728 KB Output is correct
19 Correct 7 ms 9728 KB Output is correct
20 Correct 18 ms 12224 KB Output is correct
21 Correct 21 ms 12264 KB Output is correct
22 Correct 21 ms 12608 KB Output is correct
23 Correct 32 ms 12600 KB Output is correct
24 Correct 24 ms 12512 KB Output is correct
25 Correct 21 ms 12484 KB Output is correct
26 Correct 21 ms 12608 KB Output is correct
27 Correct 18 ms 12608 KB Output is correct
28 Correct 23 ms 12512 KB Output is correct
29 Correct 20 ms 12484 KB Output is correct
30 Correct 18 ms 12608 KB Output is correct
31 Correct 16 ms 12480 KB Output is correct
32 Correct 26 ms 13240 KB Output is correct
33 Correct 23 ms 13232 KB Output is correct
34 Correct 23 ms 12644 KB Output is correct
35 Correct 24 ms 13516 KB Output is correct
36 Correct 23 ms 13216 KB Output is correct
37 Correct 21 ms 12608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 493 ms 69616 KB Output is correct
2 Correct 380 ms 72032 KB Output is correct
3 Correct 497 ms 66068 KB Output is correct
4 Correct 531 ms 66964 KB Output is correct
5 Correct 375 ms 77152 KB Output is correct
6 Correct 288 ms 73956 KB Output is correct
7 Correct 285 ms 67688 KB Output is correct
8 Correct 194 ms 67176 KB Output is correct
9 Correct 221 ms 72800 KB Output is correct
10 Correct 210 ms 67172 KB Output is correct
11 Correct 821 ms 90444 KB Output is correct
12 Correct 806 ms 90324 KB Output is correct
13 Correct 796 ms 81964 KB Output is correct
14 Correct 907 ms 81880 KB Output is correct
15 Correct 465 ms 72220 KB Output is correct
16 Correct 473 ms 72676 KB Output is correct
17 Correct 441 ms 71528 KB Output is correct
18 Correct 658 ms 89560 KB Output is correct
19 Correct 6 ms 9728 KB Output is correct
20 Correct 8 ms 9728 KB Output is correct
21 Correct 7 ms 9728 KB Output is correct
22 Correct 7 ms 9728 KB Output is correct
23 Correct 7 ms 9728 KB Output is correct
24 Correct 7 ms 9728 KB Output is correct
25 Correct 7 ms 9728 KB Output is correct
26 Correct 7 ms 9728 KB Output is correct
27 Correct 7 ms 9728 KB Output is correct
28 Correct 7 ms 9728 KB Output is correct
29 Correct 7 ms 9728 KB Output is correct
30 Correct 7 ms 9728 KB Output is correct
31 Correct 7 ms 9728 KB Output is correct
32 Correct 7 ms 9728 KB Output is correct
33 Correct 10 ms 9728 KB Output is correct
34 Correct 7 ms 9728 KB Output is correct
35 Correct 7 ms 9728 KB Output is correct
36 Correct 8 ms 9728 KB Output is correct
37 Correct 7 ms 9728 KB Output is correct
38 Correct 18 ms 12224 KB Output is correct
39 Correct 21 ms 12264 KB Output is correct
40 Correct 21 ms 12608 KB Output is correct
41 Correct 32 ms 12600 KB Output is correct
42 Correct 24 ms 12512 KB Output is correct
43 Correct 21 ms 12484 KB Output is correct
44 Correct 21 ms 12608 KB Output is correct
45 Correct 18 ms 12608 KB Output is correct
46 Correct 23 ms 12512 KB Output is correct
47 Correct 20 ms 12484 KB Output is correct
48 Correct 18 ms 12608 KB Output is correct
49 Correct 16 ms 12480 KB Output is correct
50 Correct 26 ms 13240 KB Output is correct
51 Correct 23 ms 13232 KB Output is correct
52 Correct 23 ms 12644 KB Output is correct
53 Correct 24 ms 13516 KB Output is correct
54 Correct 23 ms 13216 KB Output is correct
55 Correct 21 ms 12608 KB Output is correct
56 Correct 387 ms 63012 KB Output is correct
57 Correct 412 ms 61860 KB Output is correct
58 Correct 469 ms 70880 KB Output is correct
59 Correct 450 ms 71264 KB Output is correct
60 Correct 470 ms 72928 KB Output is correct
61 Correct 438 ms 71008 KB Output is correct
62 Correct 423 ms 62884 KB Output is correct
63 Correct 412 ms 72800 KB Output is correct
64 Correct 403 ms 72676 KB Output is correct
65 Correct 423 ms 72420 KB Output is correct
66 Correct 424 ms 71908 KB Output is correct
67 Correct 522 ms 72792 KB Output is correct
68 Correct 439 ms 71920 KB Output is correct
69 Correct 352 ms 71652 KB Output is correct
70 Correct 594 ms 72800 KB Output is correct
71 Correct 420 ms 71904 KB Output is correct
72 Correct 367 ms 72036 KB Output is correct
73 Correct 551 ms 72544 KB Output is correct
74 Correct 312 ms 71776 KB Output is correct
75 Correct 271 ms 71648 KB Output is correct
76 Correct 789 ms 90836 KB Output is correct
77 Correct 928 ms 91212 KB Output is correct
78 Correct 826 ms 82536 KB Output is correct
79 Correct 556 ms 72804 KB Output is correct
80 Correct 483 ms 72800 KB Output is correct
81 Correct 387 ms 72520 KB Output is correct
82 Correct 506 ms 73060 KB Output is correct
83 Correct 520 ms 72548 KB Output is correct
84 Correct 523 ms 71908 KB Output is correct
85 Correct 444 ms 73056 KB Output is correct
86 Correct 454 ms 72680 KB Output is correct
87 Correct 426 ms 72932 KB Output is correct
88 Correct 429 ms 79180 KB Output is correct
89 Correct 467 ms 72864 KB Output is correct
90 Correct 957 ms 90948 KB Output is correct
91 Correct 693 ms 82912 KB Output is correct
92 Correct 450 ms 72612 KB Output is correct
93 Correct 528 ms 72672 KB Output is correct
94 Correct 475 ms 74336 KB Output is correct
95 Correct 498 ms 72676 KB Output is correct
96 Correct 981 ms 91092 KB Output is correct
97 Correct 928 ms 91260 KB Output is correct
98 Correct 875 ms 91020 KB Output is correct
99 Correct 919 ms 91092 KB Output is correct
100 Correct 608 ms 78064 KB Output is correct
101 Correct 799 ms 90964 KB Output is correct
102 Correct 742 ms 83296 KB Output is correct
103 Correct 484 ms 75620 KB Output is correct