Submission #737459

# Submission time Handle Problem Language Result Execution time Memory
737459 2023-05-07T08:16:25 Z Ronin13 Fuel Station (NOI20_fuelstation) C++14
20 / 100
1345 ms 737472 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 10000001;
vector <ll> bit(nmax);

const ll mod = 1e9 + 7;

int lsb(int x){
    return x & -x;
}

void add(int pos, ll v, int n){
    while(pos <= n){
        bit[pos] += v;
        pos += lsb(pos);
    }
}

ll get(int pos){
    ll res = 0;
    while(pos){
        res += bit[pos];
        pos -= lsb(pos);
    }
    return res;
}

vector <ll> t(4 * nmax), lazy(4 * nmax);

void push(int v){
    t[2 * v] += lazy[v];
    lazy[2 * v] += lazy[v];
    t[2 * v + 1] += lazy[v];
    lazy[2 * v + 1] += lazy[v];
    lazy[v] = 0;
}



void upd(int v, int l, int r, int pos, ll val){
    if(l > pos || r < pos)
        return;
    if(l == r){
        t[v] = val;
        return;
    }
    int m = (l + r) / 2;
    push(v);
    upd(2 * v, l, m, pos, val);
    upd(2 * v + 1, m + 1,r, pos, val);
    t[v] = max(t[2 * v], t[2 * v + 1]);
}

void upd_ran(int v, int l, int r, int st, int fin, ll val){
    if(l > fin || r < st)
        return;
    if(l >= st && r <= fin){
        t[v] += val;
        lazy[v] += val;
        return;
    }
    int m = (l + r) / 2;
    push(v);
    upd_ran(2 * v, l, m, st, fin, val);
    upd_ran(2 * v + 1, m + 1, r, st, fin, val);
    t[v] = max(t[2 * v], t[2 * v + 1]);
}


int main(){
    int n; cin >> n;
    int d; cin >> d;
    ll a[n + 1], b[n + 1];
    ll x[n + 1];
    ll pos[n + 2];
    for(int i = 1; i <= n; i++)
        cin >> x[i] >> a[i] >> b[i];
    map  <int,int> mp;
    vector <pll> cmp;
    for(int i= 1; i <= n; i++){
        cmp.pb({x[i], i});
    }
    cmp.pb({d, 0});
    sort(cmp.begin(), cmp.end());
    for(int i= 0; i < cmp.size(); i++)
        pos[cmp[i].s] = i + 1;
    vector <pll> B;
    for(int i = 1; i <=n; i++){
        B.pb({b[i], i});
    }
    sort(B.begin(), B.end());
    upd(1, 1, n + 1, n + 1, d);
    for(int i = 1; i<= n; i++)
        upd(1, 1, n + 1, pos[i], x[i]);
    ll ans = d;

    for(int i = 0; i < B.size(); i++){
        int p = B[i].s;
        ll xx = get(pos[p] - 1);
        upd(1, 1, n + 1, pos[p], x[p] - xx);
        upd_ran(1, 1, n + 1, pos[p] + 1, n + 1, -a[p]);
        add(pos[p], a[p], n + 1);
        if(B[i].f >= t[1]){
            ans = min(t[1], ans);
            continue;
        }
    }
    cout << max(ans, 0LL);
    return 0;
}

Compilation message

FuelStation.cpp: In function 'int main()':
FuelStation.cpp:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for(int i= 0; i < cmp.size(); i++)
      |                   ~~^~~~~~~~~~~~
FuelStation.cpp:105:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |     for(int i = 0; i < B.size(); i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 285 ms 704716 KB Output is correct
2 Correct 273 ms 704824 KB Output is correct
3 Correct 268 ms 704772 KB Output is correct
4 Correct 268 ms 704796 KB Output is correct
5 Correct 303 ms 704712 KB Output is correct
6 Correct 304 ms 704688 KB Output is correct
7 Correct 393 ms 704852 KB Output is correct
8 Correct 265 ms 704768 KB Output is correct
9 Correct 259 ms 704896 KB Output is correct
10 Correct 307 ms 704772 KB Output is correct
11 Correct 288 ms 704692 KB Output is correct
12 Correct 303 ms 704712 KB Output is correct
13 Correct 271 ms 704776 KB Output is correct
14 Correct 302 ms 704752 KB Output is correct
15 Correct 302 ms 704736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1345 ms 735156 KB Output is correct
2 Correct 1068 ms 735652 KB Output is correct
3 Correct 1188 ms 735516 KB Output is correct
4 Correct 923 ms 735812 KB Output is correct
5 Correct 933 ms 737172 KB Output is correct
6 Correct 944 ms 736060 KB Output is correct
7 Correct 940 ms 737472 KB Output is correct
8 Correct 919 ms 737324 KB Output is correct
9 Correct 950 ms 736224 KB Output is correct
10 Correct 931 ms 737412 KB Output is correct
11 Correct 1049 ms 737176 KB Output is correct
12 Correct 1043 ms 735768 KB Output is correct
13 Correct 1064 ms 735628 KB Output is correct
14 Correct 1032 ms 735212 KB Output is correct
15 Correct 951 ms 734808 KB Output is correct
16 Correct 966 ms 734528 KB Output is correct
17 Correct 966 ms 734120 KB Output is correct
18 Correct 1058 ms 734032 KB Output is correct
19 Correct 904 ms 733864 KB Output is correct
20 Correct 938 ms 733716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 704768 KB Output is correct
2 Correct 283 ms 705856 KB Output is correct
3 Correct 278 ms 705736 KB Output is correct
4 Correct 280 ms 705696 KB Output is correct
5 Correct 279 ms 705764 KB Output is correct
6 Correct 279 ms 705712 KB Output is correct
7 Correct 276 ms 705712 KB Output is correct
8 Incorrect 264 ms 704796 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 268 ms 704768 KB Output is correct
2 Correct 283 ms 705856 KB Output is correct
3 Correct 278 ms 705736 KB Output is correct
4 Correct 280 ms 705696 KB Output is correct
5 Correct 279 ms 705764 KB Output is correct
6 Correct 279 ms 705712 KB Output is correct
7 Correct 276 ms 705712 KB Output is correct
8 Incorrect 264 ms 704796 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 285 ms 704716 KB Output is correct
2 Correct 273 ms 704824 KB Output is correct
3 Correct 268 ms 704772 KB Output is correct
4 Correct 268 ms 704796 KB Output is correct
5 Correct 303 ms 704712 KB Output is correct
6 Correct 304 ms 704688 KB Output is correct
7 Correct 393 ms 704852 KB Output is correct
8 Correct 265 ms 704768 KB Output is correct
9 Correct 259 ms 704896 KB Output is correct
10 Correct 307 ms 704772 KB Output is correct
11 Correct 288 ms 704692 KB Output is correct
12 Correct 303 ms 704712 KB Output is correct
13 Correct 271 ms 704776 KB Output is correct
14 Correct 302 ms 704752 KB Output is correct
15 Correct 302 ms 704736 KB Output is correct
16 Correct 277 ms 704804 KB Output is correct
17 Correct 265 ms 704704 KB Output is correct
18 Correct 269 ms 704740 KB Output is correct
19 Correct 279 ms 704776 KB Output is correct
20 Correct 285 ms 704732 KB Output is correct
21 Correct 261 ms 704824 KB Output is correct
22 Incorrect 269 ms 704844 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 285 ms 704716 KB Output is correct
2 Correct 273 ms 704824 KB Output is correct
3 Correct 268 ms 704772 KB Output is correct
4 Correct 268 ms 704796 KB Output is correct
5 Correct 303 ms 704712 KB Output is correct
6 Correct 304 ms 704688 KB Output is correct
7 Correct 393 ms 704852 KB Output is correct
8 Correct 265 ms 704768 KB Output is correct
9 Correct 259 ms 704896 KB Output is correct
10 Correct 307 ms 704772 KB Output is correct
11 Correct 288 ms 704692 KB Output is correct
12 Correct 303 ms 704712 KB Output is correct
13 Correct 271 ms 704776 KB Output is correct
14 Correct 302 ms 704752 KB Output is correct
15 Correct 302 ms 704736 KB Output is correct
16 Correct 268 ms 704768 KB Output is correct
17 Correct 283 ms 705856 KB Output is correct
18 Correct 278 ms 705736 KB Output is correct
19 Correct 280 ms 705696 KB Output is correct
20 Correct 279 ms 705764 KB Output is correct
21 Correct 279 ms 705712 KB Output is correct
22 Correct 276 ms 705712 KB Output is correct
23 Incorrect 264 ms 704796 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 285 ms 704716 KB Output is correct
2 Correct 273 ms 704824 KB Output is correct
3 Correct 268 ms 704772 KB Output is correct
4 Correct 268 ms 704796 KB Output is correct
5 Correct 303 ms 704712 KB Output is correct
6 Correct 304 ms 704688 KB Output is correct
7 Correct 393 ms 704852 KB Output is correct
8 Correct 265 ms 704768 KB Output is correct
9 Correct 259 ms 704896 KB Output is correct
10 Correct 307 ms 704772 KB Output is correct
11 Correct 288 ms 704692 KB Output is correct
12 Correct 303 ms 704712 KB Output is correct
13 Correct 271 ms 704776 KB Output is correct
14 Correct 302 ms 704752 KB Output is correct
15 Correct 302 ms 704736 KB Output is correct
16 Correct 1345 ms 735156 KB Output is correct
17 Correct 1068 ms 735652 KB Output is correct
18 Correct 1188 ms 735516 KB Output is correct
19 Correct 923 ms 735812 KB Output is correct
20 Correct 933 ms 737172 KB Output is correct
21 Correct 944 ms 736060 KB Output is correct
22 Correct 940 ms 737472 KB Output is correct
23 Correct 919 ms 737324 KB Output is correct
24 Correct 950 ms 736224 KB Output is correct
25 Correct 931 ms 737412 KB Output is correct
26 Correct 1049 ms 737176 KB Output is correct
27 Correct 1043 ms 735768 KB Output is correct
28 Correct 1064 ms 735628 KB Output is correct
29 Correct 1032 ms 735212 KB Output is correct
30 Correct 951 ms 734808 KB Output is correct
31 Correct 966 ms 734528 KB Output is correct
32 Correct 966 ms 734120 KB Output is correct
33 Correct 1058 ms 734032 KB Output is correct
34 Correct 904 ms 733864 KB Output is correct
35 Correct 938 ms 733716 KB Output is correct
36 Correct 268 ms 704768 KB Output is correct
37 Correct 283 ms 705856 KB Output is correct
38 Correct 278 ms 705736 KB Output is correct
39 Correct 280 ms 705696 KB Output is correct
40 Correct 279 ms 705764 KB Output is correct
41 Correct 279 ms 705712 KB Output is correct
42 Correct 276 ms 705712 KB Output is correct
43 Incorrect 264 ms 704796 KB Output isn't correct
44 Halted 0 ms 0 KB -