Submission #1052379

# Submission time Handle Problem Language Result Execution time Memory
1052379 2024-08-10T14:05:38 Z hotboy2703 Treatment Project (JOI20_treatment) C++17
100 / 100
465 ms 105420 KB
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll MAXN = 1e5+100;
const ll INF = 1e18;
ll dp[MAXN];
struct treatment{
    ll t,l,r,c;
};
treatment a[MAXN];
vector <pll> tree1[MAXN*4],tree2[MAXN*4];
vector <ll> val_t;
void update(ll id,ll l,ll r,ll pos){
    if (val_t[l] > a[pos].t || val_t[r] < a[pos].t)return;
    tree1[id].push_back(MP(a[pos].l - a[pos].t,pos));
    tree2[id].push_back(MP(a[pos].l + a[pos].t,pos));   
    if (l == r){
        return;
    }
    ll mid = (l + r) >> 1;
    update(id<<1,l,mid,pos);
    update(id<<1|1,mid+1,r,pos);
}
void build(ll id,ll l,ll r){
    sort(tree1[id].begin(),tree1[id].end(),greater <>());
    sort(tree2[id].begin(),tree2[id].end(),greater <>());
    if (l != r){
        ll mid = (l + r) >> 1;
        build(id<<1,l,mid);
        build(id<<1|1,mid+1,r);
    }
}
vector <ll> all;
void get1(ll id,ll l,ll r,ll pos){
    if (val_t[l] > a[pos].t)return;
    if (val_t[r] <= a[pos].t){
        while (!tree1[id].empty() && tree1[id].back().fi <= a[pos].r - a[pos].t + 1){
            all.push_back(tree1[id].back().se);
            tree1[id].pop_back();
        }
        return;
    }
    ll mid = (l + r) >> 1;
    get1(id<<1,l,mid,pos);
    get1(id<<1|1,mid+1,r,pos);
}
void get2(ll id,ll l,ll r,ll pos){
    if (val_t[r] < a[pos].t)return;
    if (val_t[l] >= a[pos].t){
            while (!tree2[id].empty() && tree2[id].back().fi <= a[pos].r + a[pos].t + 1){
            all.push_back(tree2[id].back().se);
            tree2[id].pop_back();
        }
        return;
    }
    ll mid = (l + r) >> 1;
    get2(id<<1,l,mid,pos);
    get2(id<<1|1,mid+1,r,pos);
}
ll n,m;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n>>m;
    for (ll i = 1;i <= m;i ++){
        cin>>a[i].t>>a[i].l>>a[i].r>>a[i].c;
        val_t.push_back(a[i].t);
    }
    sort(val_t.begin(),val_t.end());
    val_t.resize(unique(val_t.begin(),val_t.end())-val_t.begin());
    val_t.insert(val_t.begin(),0);
    for (ll i = 1;i <= m;i ++)update(1,1,sz(val_t)-1,i);
    build(1,1,sz(val_t)-1);
    priority_queue <pll,vector <pll> ,greater <> > q;
    for (ll i = 1;i <= m;i ++){
        if (a[i].l == 1){dp[i] = a[i].c;q.push(MP(a[i].c,i));}
        else dp[i] = INF;
    }
    while (!q.empty()){
        ll u = q.top().se;
        q.pop();
        all.clear();
        get1(1,1,sz(val_t)-1,u);
        get2(1,1,sz(val_t)-1,u);
        for (auto v:all){
            // cout<<v<<
            if (dp[v] == INF){
                dp[v] = dp[u] + a[v].c;
                q.push(MP(dp[v],v));
            }
        }
    }
    ll ans = INF;
    for (ll i = 1;i <= m;i ++)if (a[i].r == n)ans = min(ans,dp[i]);
    if (ans == INF)ans = -1;
cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 30372 KB Output is correct
2 Correct 46 ms 30256 KB Output is correct
3 Correct 72 ms 31216 KB Output is correct
4 Correct 59 ms 30452 KB Output is correct
5 Correct 51 ms 33200 KB Output is correct
6 Correct 46 ms 30308 KB Output is correct
7 Correct 49 ms 30268 KB Output is correct
8 Correct 45 ms 30316 KB Output is correct
9 Correct 57 ms 30212 KB Output is correct
10 Correct 56 ms 30088 KB Output is correct
11 Correct 73 ms 34416 KB Output is correct
12 Correct 50 ms 34804 KB Output is correct
13 Correct 75 ms 33084 KB Output is correct
14 Correct 73 ms 33264 KB Output is correct
15 Correct 69 ms 30232 KB Output is correct
16 Correct 46 ms 30300 KB Output is correct
17 Correct 56 ms 29436 KB Output is correct
18 Correct 53 ms 33652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21120 KB Output is correct
3 Correct 3 ms 21084 KB Output is correct
4 Correct 3 ms 21084 KB Output is correct
5 Correct 2 ms 21156 KB Output is correct
6 Correct 3 ms 21160 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 3 ms 21160 KB Output is correct
9 Correct 4 ms 21152 KB Output is correct
10 Correct 4 ms 21084 KB Output is correct
11 Correct 4 ms 21084 KB Output is correct
12 Correct 4 ms 21084 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21084 KB Output is correct
15 Correct 3 ms 21084 KB Output is correct
16 Correct 4 ms 21084 KB Output is correct
17 Correct 4 ms 21084 KB Output is correct
18 Correct 4 ms 21084 KB Output is correct
19 Correct 3 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21120 KB Output is correct
3 Correct 3 ms 21084 KB Output is correct
4 Correct 3 ms 21084 KB Output is correct
5 Correct 2 ms 21156 KB Output is correct
6 Correct 3 ms 21160 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 3 ms 21160 KB Output is correct
9 Correct 4 ms 21152 KB Output is correct
10 Correct 4 ms 21084 KB Output is correct
11 Correct 4 ms 21084 KB Output is correct
12 Correct 4 ms 21084 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21084 KB Output is correct
15 Correct 3 ms 21084 KB Output is correct
16 Correct 4 ms 21084 KB Output is correct
17 Correct 4 ms 21084 KB Output is correct
18 Correct 4 ms 21084 KB Output is correct
19 Correct 3 ms 21084 KB Output is correct
20 Correct 11 ms 24408 KB Output is correct
21 Correct 12 ms 24428 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 10 ms 23644 KB Output is correct
24 Correct 12 ms 24872 KB Output is correct
25 Correct 11 ms 24668 KB Output is correct
26 Correct 15 ms 24668 KB Output is correct
27 Correct 10 ms 24668 KB Output is correct
28 Correct 16 ms 24668 KB Output is correct
29 Correct 15 ms 24924 KB Output is correct
30 Correct 8 ms 24488 KB Output is correct
31 Correct 8 ms 24668 KB Output is correct
32 Correct 12 ms 24924 KB Output is correct
33 Correct 12 ms 24976 KB Output is correct
34 Correct 11 ms 24388 KB Output is correct
35 Correct 14 ms 24876 KB Output is correct
36 Correct 12 ms 24924 KB Output is correct
37 Correct 18 ms 24412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 30372 KB Output is correct
2 Correct 46 ms 30256 KB Output is correct
3 Correct 72 ms 31216 KB Output is correct
4 Correct 59 ms 30452 KB Output is correct
5 Correct 51 ms 33200 KB Output is correct
6 Correct 46 ms 30308 KB Output is correct
7 Correct 49 ms 30268 KB Output is correct
8 Correct 45 ms 30316 KB Output is correct
9 Correct 57 ms 30212 KB Output is correct
10 Correct 56 ms 30088 KB Output is correct
11 Correct 73 ms 34416 KB Output is correct
12 Correct 50 ms 34804 KB Output is correct
13 Correct 75 ms 33084 KB Output is correct
14 Correct 73 ms 33264 KB Output is correct
15 Correct 69 ms 30232 KB Output is correct
16 Correct 46 ms 30300 KB Output is correct
17 Correct 56 ms 29436 KB Output is correct
18 Correct 53 ms 33652 KB Output is correct
19 Correct 4 ms 21084 KB Output is correct
20 Correct 4 ms 21120 KB Output is correct
21 Correct 3 ms 21084 KB Output is correct
22 Correct 3 ms 21084 KB Output is correct
23 Correct 2 ms 21156 KB Output is correct
24 Correct 3 ms 21160 KB Output is correct
25 Correct 3 ms 21084 KB Output is correct
26 Correct 3 ms 21160 KB Output is correct
27 Correct 4 ms 21152 KB Output is correct
28 Correct 4 ms 21084 KB Output is correct
29 Correct 4 ms 21084 KB Output is correct
30 Correct 4 ms 21084 KB Output is correct
31 Correct 4 ms 21084 KB Output is correct
32 Correct 4 ms 21084 KB Output is correct
33 Correct 3 ms 21084 KB Output is correct
34 Correct 4 ms 21084 KB Output is correct
35 Correct 4 ms 21084 KB Output is correct
36 Correct 4 ms 21084 KB Output is correct
37 Correct 3 ms 21084 KB Output is correct
38 Correct 11 ms 24408 KB Output is correct
39 Correct 12 ms 24428 KB Output is correct
40 Correct 11 ms 23900 KB Output is correct
41 Correct 10 ms 23644 KB Output is correct
42 Correct 12 ms 24872 KB Output is correct
43 Correct 11 ms 24668 KB Output is correct
44 Correct 15 ms 24668 KB Output is correct
45 Correct 10 ms 24668 KB Output is correct
46 Correct 16 ms 24668 KB Output is correct
47 Correct 15 ms 24924 KB Output is correct
48 Correct 8 ms 24488 KB Output is correct
49 Correct 8 ms 24668 KB Output is correct
50 Correct 12 ms 24924 KB Output is correct
51 Correct 12 ms 24976 KB Output is correct
52 Correct 11 ms 24388 KB Output is correct
53 Correct 14 ms 24876 KB Output is correct
54 Correct 12 ms 24924 KB Output is correct
55 Correct 18 ms 24412 KB Output is correct
56 Correct 385 ms 94440 KB Output is correct
57 Correct 350 ms 95368 KB Output is correct
58 Correct 359 ms 93328 KB Output is correct
59 Correct 376 ms 94356 KB Output is correct
60 Correct 249 ms 86468 KB Output is correct
61 Correct 333 ms 93468 KB Output is correct
62 Correct 352 ms 94664 KB Output is correct
63 Correct 379 ms 101840 KB Output is correct
64 Correct 374 ms 101884 KB Output is correct
65 Correct 72 ms 34432 KB Output is correct
66 Correct 249 ms 84456 KB Output is correct
67 Correct 382 ms 100468 KB Output is correct
68 Correct 304 ms 100616 KB Output is correct
69 Correct 258 ms 98868 KB Output is correct
70 Correct 388 ms 100660 KB Output is correct
71 Correct 290 ms 100296 KB Output is correct
72 Correct 281 ms 100124 KB Output is correct
73 Correct 433 ms 100548 KB Output is correct
74 Correct 217 ms 99776 KB Output is correct
75 Correct 213 ms 99636 KB Output is correct
76 Correct 311 ms 100356 KB Output is correct
77 Correct 423 ms 105156 KB Output is correct
78 Correct 383 ms 98756 KB Output is correct
79 Correct 436 ms 101576 KB Output is correct
80 Correct 411 ms 96892 KB Output is correct
81 Correct 316 ms 100804 KB Output is correct
82 Correct 439 ms 96932 KB Output is correct
83 Correct 465 ms 101556 KB Output is correct
84 Correct 441 ms 100920 KB Output is correct
85 Correct 398 ms 101064 KB Output is correct
86 Correct 387 ms 100808 KB Output is correct
87 Correct 420 ms 100804 KB Output is correct
88 Correct 424 ms 102452 KB Output is correct
89 Correct 391 ms 100548 KB Output is correct
90 Correct 440 ms 105412 KB Output is correct
91 Correct 401 ms 102856 KB Output is correct
92 Correct 395 ms 101064 KB Output is correct
93 Correct 423 ms 100780 KB Output is correct
94 Correct 425 ms 102444 KB Output is correct
95 Correct 414 ms 100808 KB Output is correct
96 Correct 422 ms 105156 KB Output is correct
97 Correct 424 ms 104388 KB Output is correct
98 Correct 422 ms 104056 KB Output is correct
99 Correct 413 ms 104332 KB Output is correct
100 Correct 424 ms 105420 KB Output is correct
101 Correct 449 ms 104268 KB Output is correct
102 Correct 427 ms 105356 KB Output is correct
103 Correct 411 ms 101156 KB Output is correct