Submission #534832

# Submission time Handle Problem Language Result Execution time Memory
534832 2022-03-09T03:22:07 Z qwerasdfzxcl Treatment Project (JOI20_treatment) C++14
100 / 100
235 ms 22872 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
constexpr ll INF = 1e18;
constexpr int INF2 = 2e9;
ll dist[100100];
struct Fenwick{
    vector<pair<int, int>> tree[100100];
    int sz;
    void init(int n){sz = n;}
    void init2(){for (int i=0;i<=sz;i++) sort(tree[i].begin(), tree[i].end(), greater<pair<int, int>>());}
    void update(int x, int y, int i){
        while(x<=sz){
            tree[x].emplace_back(y, i);
            x += x&-x;
        }
    }
    pair<int, int> query(int x){
        pair<int, int> ret = {INF2, 0};
        while(x){
            while(!tree[x].empty() && dist[tree[x].back().second]!=INF) tree[x].pop_back();
            if (!tree[x].empty()) ret = min(ret, tree[x].back());
            x -= x&-x;
        }
        return ret;
    }
    int pop(int x, int y){
        auto [val, idx] = query(x);
        if (val>y) return 0;
        return idx;
    }
}tree;
int T[100100], L[100100], R[100100], C[100100];

void compress(vector<int> &v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
inline int getidx(const vector<int> &v, int x) {return lower_bound(v.begin(), v.end(), x) - v.begin();}
inline int getidx2(const vector<int> &v, int x) {return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;}

int main(){
    int X, n;
    scanf("%d %d", &X, &n);

    vector<int> x;
    x.push_back(-INF2);
    for (int i=1;i<=n;i++){
        scanf("%d %d %d %d", T+i, L+i, R+i, C+i);
        x.push_back(L[i] + T[i]);
    }

    compress(x);
    tree.init(n+2);

    fill(dist+1, dist+n+1, INF);
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    for (int i=1;i<=n;i++){
        tree.update(getidx(x, L[i]+T[i]), L[i]-T[i], i);
        if (L[i]==1){
            dist[i] = C[i];
            pq.emplace(C[i], i);
        }
    }

    tree.init2();

    while(!pq.empty()){
        auto [c, s] = pq.top(); pq.pop();
        int xc = getidx2(x, R[s]+1+T[s]), yc = R[s]+1-T[s], v;
        while(true){
            v = tree.pop(xc, yc);
            if (!v) break;
            dist[v] = c + C[v];
            pq.emplace(dist[v], v);
        }
    }

    ll ans = INF;
    for (int i=1;i<=n;i++) if (R[i]==X) ans = min(ans, dist[i]);
    printf("%lld\n", ans==INF?-1:ans);
    return 0;
}

Compilation message

treatment.cpp: In member function 'int Fenwick::pop(int, int)':
treatment.cpp:29:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |         auto [val, idx] = query(x);
      |              ^
treatment.cpp: In function 'int main()':
treatment.cpp:67:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   67 |         auto [c, s] = pq.top(); pq.pop();
      |              ^
treatment.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d %d", &X, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~
treatment.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d %d %d %d", T+i, L+i, R+i, C+i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 153 ms 14212 KB Output is correct
2 Correct 176 ms 17312 KB Output is correct
3 Correct 148 ms 19772 KB Output is correct
4 Correct 146 ms 18992 KB Output is correct
5 Correct 200 ms 22872 KB Output is correct
6 Correct 150 ms 19524 KB Output is correct
7 Correct 160 ms 19400 KB Output is correct
8 Correct 163 ms 20856 KB Output is correct
9 Correct 149 ms 19624 KB Output is correct
10 Correct 128 ms 19412 KB Output is correct
11 Correct 161 ms 20984 KB Output is correct
12 Correct 173 ms 20808 KB Output is correct
13 Correct 201 ms 21012 KB Output is correct
14 Correct 171 ms 20880 KB Output is correct
15 Correct 182 ms 18264 KB Output is correct
16 Correct 153 ms 18292 KB Output is correct
17 Correct 186 ms 17852 KB Output is correct
18 Correct 161 ms 20432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2576 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 1 ms 2636 KB Output is correct
17 Correct 2 ms 2656 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2576 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 1 ms 2636 KB Output is correct
17 Correct 2 ms 2656 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 11 ms 3328 KB Output is correct
21 Correct 10 ms 3424 KB Output is correct
22 Correct 8 ms 3292 KB Output is correct
23 Correct 7 ms 3304 KB Output is correct
24 Correct 8 ms 3432 KB Output is correct
25 Correct 8 ms 3288 KB Output is correct
26 Correct 7 ms 3276 KB Output is correct
27 Correct 6 ms 3304 KB Output is correct
28 Correct 8 ms 3396 KB Output is correct
29 Correct 8 ms 3320 KB Output is correct
30 Correct 6 ms 3276 KB Output is correct
31 Correct 5 ms 3320 KB Output is correct
32 Correct 9 ms 3560 KB Output is correct
33 Correct 8 ms 3560 KB Output is correct
34 Correct 8 ms 3268 KB Output is correct
35 Correct 10 ms 3436 KB Output is correct
36 Correct 8 ms 3404 KB Output is correct
37 Correct 7 ms 3276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 14212 KB Output is correct
2 Correct 176 ms 17312 KB Output is correct
3 Correct 148 ms 19772 KB Output is correct
4 Correct 146 ms 18992 KB Output is correct
5 Correct 200 ms 22872 KB Output is correct
6 Correct 150 ms 19524 KB Output is correct
7 Correct 160 ms 19400 KB Output is correct
8 Correct 163 ms 20856 KB Output is correct
9 Correct 149 ms 19624 KB Output is correct
10 Correct 128 ms 19412 KB Output is correct
11 Correct 161 ms 20984 KB Output is correct
12 Correct 173 ms 20808 KB Output is correct
13 Correct 201 ms 21012 KB Output is correct
14 Correct 171 ms 20880 KB Output is correct
15 Correct 182 ms 18264 KB Output is correct
16 Correct 153 ms 18292 KB Output is correct
17 Correct 186 ms 17852 KB Output is correct
18 Correct 161 ms 20432 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 1 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 2 ms 2576 KB Output is correct
27 Correct 2 ms 2652 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 2 ms 2636 KB Output is correct
30 Correct 2 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 2 ms 2636 KB Output is correct
33 Correct 2 ms 2636 KB Output is correct
34 Correct 1 ms 2636 KB Output is correct
35 Correct 2 ms 2656 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 2 ms 2636 KB Output is correct
38 Correct 11 ms 3328 KB Output is correct
39 Correct 10 ms 3424 KB Output is correct
40 Correct 8 ms 3292 KB Output is correct
41 Correct 7 ms 3304 KB Output is correct
42 Correct 8 ms 3432 KB Output is correct
43 Correct 8 ms 3288 KB Output is correct
44 Correct 7 ms 3276 KB Output is correct
45 Correct 6 ms 3304 KB Output is correct
46 Correct 8 ms 3396 KB Output is correct
47 Correct 8 ms 3320 KB Output is correct
48 Correct 6 ms 3276 KB Output is correct
49 Correct 5 ms 3320 KB Output is correct
50 Correct 9 ms 3560 KB Output is correct
51 Correct 8 ms 3560 KB Output is correct
52 Correct 8 ms 3268 KB Output is correct
53 Correct 10 ms 3436 KB Output is correct
54 Correct 8 ms 3404 KB Output is correct
55 Correct 7 ms 3276 KB Output is correct
56 Correct 174 ms 17872 KB Output is correct
57 Correct 200 ms 19224 KB Output is correct
58 Correct 148 ms 17996 KB Output is correct
59 Correct 178 ms 18104 KB Output is correct
60 Correct 155 ms 17608 KB Output is correct
61 Correct 168 ms 18036 KB Output is correct
62 Correct 158 ms 17876 KB Output is correct
63 Correct 148 ms 17436 KB Output is correct
64 Correct 163 ms 17460 KB Output is correct
65 Correct 168 ms 17464 KB Output is correct
66 Correct 161 ms 17632 KB Output is correct
67 Correct 193 ms 19384 KB Output is correct
68 Correct 159 ms 18716 KB Output is correct
69 Correct 129 ms 18760 KB Output is correct
70 Correct 194 ms 18896 KB Output is correct
71 Correct 159 ms 18904 KB Output is correct
72 Correct 149 ms 18912 KB Output is correct
73 Correct 195 ms 18840 KB Output is correct
74 Correct 121 ms 19388 KB Output is correct
75 Correct 98 ms 18912 KB Output is correct
76 Correct 235 ms 21040 KB Output is correct
77 Correct 182 ms 21172 KB Output is correct
78 Correct 168 ms 21200 KB Output is correct
79 Correct 199 ms 18832 KB Output is correct
80 Correct 176 ms 19000 KB Output is correct
81 Correct 128 ms 18748 KB Output is correct
82 Correct 180 ms 18392 KB Output is correct
83 Correct 166 ms 18452 KB Output is correct
84 Correct 200 ms 17232 KB Output is correct
85 Correct 150 ms 19020 KB Output is correct
86 Correct 189 ms 18800 KB Output is correct
87 Correct 153 ms 19004 KB Output is correct
88 Correct 169 ms 19796 KB Output is correct
89 Correct 179 ms 18932 KB Output is correct
90 Correct 178 ms 21300 KB Output is correct
91 Correct 177 ms 19992 KB Output is correct
92 Correct 170 ms 19180 KB Output is correct
93 Correct 186 ms 18812 KB Output is correct
94 Correct 193 ms 19220 KB Output is correct
95 Correct 183 ms 19132 KB Output is correct
96 Correct 233 ms 21252 KB Output is correct
97 Correct 176 ms 21276 KB Output is correct
98 Correct 194 ms 21424 KB Output is correct
99 Correct 177 ms 21628 KB Output is correct
100 Correct 175 ms 21956 KB Output is correct
101 Correct 173 ms 21184 KB Output is correct
102 Correct 175 ms 21784 KB Output is correct
103 Correct 155 ms 18748 KB Output is correct