Submission #348252

# Submission time Handle Problem Language Result Execution time Memory
348252 2021-01-14T12:00:36 Z nickmet2004 Treatment Project (JOI20_treatment) C++11
100 / 100
249 ms 17900 KB
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N = 1e5 + 5 , inf = 1e18;
int n , m , T[N] , L[N], R[N] , C[N];
int a[N] , pos[N] , D[N];
vector<pair<int, int> > v;
struct Node{
    int val , v;
    Node(){}
    Node(int val , int v) : val(val) ,v(v){}
    Node operator+(const Node &A){
        if(val <= A.val) return (*this);
        else return A;
    }
}E[1<<20];
void upd(Node A , int id , int l = 0 , int r = n - 1 , int pos = 0){
    if(id < l || id > r) return;
    if(l == r){
        E[pos] = A; return;
    }
    int mid = (l + r) >> 1;
    upd(A , id , l , mid , pos * 2 + 1); upd(A ,id , mid + 1 , r ,pos * 2 + 2);
    E[pos] = E[pos * 2 + 1] + E[pos * 2 + 2];
}
Node get(int L , int R ,int l =0 , int r = n - 1,  int pos = 0){
    if(r < L || R < l) return Node(inf ,-1);
    if(L <= l && r <= R) return E[pos];
    int mid = (l + r) >> 1;
    return get(L , R , l , mid , pos * 2 + 1) + get(L , R ,mid + 1 , r , pos *2 + 2);
}

 main (){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> m >> n;
    for(int i = 0;i < n; ++i){
        cin >> T[i] >> L[i] >> R[i] >> C[i]; --L[i];
        v.emplace_back(L[i] + T[i] , i);
    }
    sort(v.begin() , v.end());
    for(int i = 0; i < n; ++i){
        int id = v[i].s;
        //cout << id << " id ";
        a[i] = L[id] - T[id];
        pos[id] = i;
        upd(Node(a[i] , id) , i);
    }//cout << endl;
    priority_queue<pair<int , int> > pq;
    for(int i = 0; i < n; ++i){
        if(L[i] == 0){
            pq.push({-C[i] , i});
            upd(Node(inf , i) , pos[i]);
        }
    }
    //cout << E[6].v << " ka " << endl;
    int ans = inf;
    while(!pq.empty()){
        auto tp = pq.top(); pq.pop();
        int i = tp.s , w= tp.f;
        //cout << w << " w "  << endl;
        if(R[i] == m) ans = min(ans , -w);
        int Y = upper_bound(v.begin() , v.end(), make_pair(R[i] + T[i] , m))- v.begin()-1 ;
        while(1){
            Node X = get(0 , Y);
            //cout << X.val << " " << X.v <<  " Xval " << endl;
            if(X.val <= R[i] - T[i]){
                //cout << X.v << " " << i << endl;
                pq.push({w - C[X.v] , X.v});
                upd(Node(inf , -1) , pos[X.v]);
            } else break;
        }
    }
    if(ans == inf)ans=-1;
    cout << ans;
}

Compilation message

treatment.cpp:35:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 |  main (){
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 167 ms 10988 KB Output is correct
2 Correct 120 ms 14052 KB Output is correct
3 Correct 160 ms 14548 KB Output is correct
4 Correct 161 ms 14820 KB Output is correct
5 Correct 179 ms 16868 KB Output is correct
6 Correct 165 ms 14052 KB Output is correct
7 Correct 158 ms 13952 KB Output is correct
8 Correct 84 ms 13924 KB Output is correct
9 Correct 80 ms 13924 KB Output is correct
10 Correct 81 ms 13924 KB Output is correct
11 Correct 185 ms 16996 KB Output is correct
12 Correct 188 ms 17076 KB Output is correct
13 Correct 213 ms 16868 KB Output is correct
14 Correct 212 ms 16868 KB Output is correct
15 Correct 182 ms 13924 KB Output is correct
16 Correct 180 ms 13924 KB Output is correct
17 Correct 173 ms 13156 KB Output is correct
18 Correct 182 ms 16228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 7 ms 1180 KB Output is correct
21 Correct 8 ms 1180 KB Output is correct
22 Correct 8 ms 1260 KB Output is correct
23 Correct 7 ms 1260 KB Output is correct
24 Correct 8 ms 1260 KB Output is correct
25 Correct 9 ms 1260 KB Output is correct
26 Correct 8 ms 1260 KB Output is correct
27 Correct 7 ms 1260 KB Output is correct
28 Correct 8 ms 1280 KB Output is correct
29 Correct 8 ms 1260 KB Output is correct
30 Correct 5 ms 1388 KB Output is correct
31 Correct 5 ms 1388 KB Output is correct
32 Correct 9 ms 1388 KB Output is correct
33 Correct 8 ms 1408 KB Output is correct
34 Correct 8 ms 1260 KB Output is correct
35 Correct 9 ms 1260 KB Output is correct
36 Correct 8 ms 1260 KB Output is correct
37 Correct 8 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 10988 KB Output is correct
2 Correct 120 ms 14052 KB Output is correct
3 Correct 160 ms 14548 KB Output is correct
4 Correct 161 ms 14820 KB Output is correct
5 Correct 179 ms 16868 KB Output is correct
6 Correct 165 ms 14052 KB Output is correct
7 Correct 158 ms 13952 KB Output is correct
8 Correct 84 ms 13924 KB Output is correct
9 Correct 80 ms 13924 KB Output is correct
10 Correct 81 ms 13924 KB Output is correct
11 Correct 185 ms 16996 KB Output is correct
12 Correct 188 ms 17076 KB Output is correct
13 Correct 213 ms 16868 KB Output is correct
14 Correct 212 ms 16868 KB Output is correct
15 Correct 182 ms 13924 KB Output is correct
16 Correct 180 ms 13924 KB Output is correct
17 Correct 173 ms 13156 KB Output is correct
18 Correct 182 ms 16228 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 7 ms 1180 KB Output is correct
39 Correct 8 ms 1180 KB Output is correct
40 Correct 8 ms 1260 KB Output is correct
41 Correct 7 ms 1260 KB Output is correct
42 Correct 8 ms 1260 KB Output is correct
43 Correct 9 ms 1260 KB Output is correct
44 Correct 8 ms 1260 KB Output is correct
45 Correct 7 ms 1260 KB Output is correct
46 Correct 8 ms 1280 KB Output is correct
47 Correct 8 ms 1260 KB Output is correct
48 Correct 5 ms 1388 KB Output is correct
49 Correct 5 ms 1388 KB Output is correct
50 Correct 9 ms 1388 KB Output is correct
51 Correct 8 ms 1408 KB Output is correct
52 Correct 8 ms 1260 KB Output is correct
53 Correct 9 ms 1260 KB Output is correct
54 Correct 8 ms 1260 KB Output is correct
55 Correct 8 ms 1260 KB Output is correct
56 Correct 172 ms 14948 KB Output is correct
57 Correct 181 ms 14564 KB Output is correct
58 Correct 175 ms 13156 KB Output is correct
59 Correct 176 ms 13584 KB Output is correct
60 Correct 194 ms 14308 KB Output is correct
61 Correct 172 ms 13156 KB Output is correct
62 Correct 172 ms 14948 KB Output is correct
63 Correct 172 ms 14052 KB Output is correct
64 Correct 178 ms 14072 KB Output is correct
65 Correct 174 ms 14180 KB Output is correct
66 Correct 163 ms 14308 KB Output is correct
67 Correct 214 ms 14692 KB Output is correct
68 Correct 199 ms 14692 KB Output is correct
69 Correct 181 ms 14820 KB Output is correct
70 Correct 219 ms 14864 KB Output is correct
71 Correct 203 ms 14820 KB Output is correct
72 Correct 177 ms 14820 KB Output is correct
73 Correct 215 ms 14820 KB Output is correct
74 Correct 86 ms 14692 KB Output is correct
75 Correct 84 ms 14764 KB Output is correct
76 Correct 205 ms 17380 KB Output is correct
77 Correct 234 ms 17900 KB Output is correct
78 Correct 223 ms 17252 KB Output is correct
79 Correct 225 ms 14692 KB Output is correct
80 Correct 190 ms 14436 KB Output is correct
81 Correct 96 ms 14692 KB Output is correct
82 Correct 192 ms 13800 KB Output is correct
83 Correct 198 ms 13924 KB Output is correct
84 Correct 223 ms 13924 KB Output is correct
85 Correct 156 ms 14812 KB Output is correct
86 Correct 170 ms 14692 KB Output is correct
87 Correct 160 ms 14692 KB Output is correct
88 Correct 181 ms 14692 KB Output is correct
89 Correct 172 ms 14692 KB Output is correct
90 Correct 238 ms 17720 KB Output is correct
91 Correct 202 ms 16484 KB Output is correct
92 Correct 175 ms 14692 KB Output is correct
93 Correct 222 ms 14692 KB Output is correct
94 Correct 195 ms 14964 KB Output is correct
95 Correct 205 ms 14692 KB Output is correct
96 Correct 249 ms 17636 KB Output is correct
97 Correct 233 ms 17844 KB Output is correct
98 Correct 236 ms 17748 KB Output is correct
99 Correct 239 ms 17636 KB Output is correct
100 Correct 203 ms 17636 KB Output is correct
101 Correct 228 ms 17636 KB Output is correct
102 Correct 220 ms 17892 KB Output is correct
103 Correct 153 ms 15076 KB Output is correct