Submission #737449

# Submission time Handle Problem Language Result Execution time Memory
737449 2023-05-07T08:05:31 Z Ronin13 Fuel Station (NOI20_fuelstation) C++14
20 / 100
938 ms 740264 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);
    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 << ans;
    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:103: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]
  103 |     for(int i = 0; i < B.size(); i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 281 ms 704688 KB Output is correct
2 Correct 264 ms 704800 KB Output is correct
3 Correct 308 ms 704808 KB Output is correct
4 Correct 263 ms 704844 KB Output is correct
5 Correct 278 ms 704788 KB Output is correct
6 Correct 265 ms 704740 KB Output is correct
7 Correct 260 ms 704800 KB Output is correct
8 Correct 259 ms 704832 KB Output is correct
9 Correct 261 ms 704824 KB Output is correct
10 Correct 255 ms 704788 KB Output is correct
11 Correct 273 ms 704696 KB Output is correct
12 Correct 275 ms 704836 KB Output is correct
13 Correct 253 ms 704712 KB Output is correct
14 Correct 255 ms 704712 KB Output is correct
15 Correct 259 ms 704820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 848 ms 739728 KB Output is correct
2 Correct 873 ms 739656 KB Output is correct
3 Correct 867 ms 739496 KB Output is correct
4 Correct 834 ms 739528 KB Output is correct
5 Correct 839 ms 740144 KB Output is correct
6 Correct 856 ms 738980 KB Output is correct
7 Correct 934 ms 738972 KB Output is correct
8 Correct 817 ms 739492 KB Output is correct
9 Correct 875 ms 740240 KB Output is correct
10 Correct 856 ms 738964 KB Output is correct
11 Correct 876 ms 738956 KB Output is correct
12 Correct 856 ms 739608 KB Output is correct
13 Correct 877 ms 738988 KB Output is correct
14 Correct 871 ms 739620 KB Output is correct
15 Correct 906 ms 739596 KB Output is correct
16 Correct 938 ms 740240 KB Output is correct
17 Correct 897 ms 740264 KB Output is correct
18 Correct 889 ms 739624 KB Output is correct
19 Correct 911 ms 739632 KB Output is correct
20 Correct 911 ms 739744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 352 ms 704716 KB Output is correct
2 Correct 277 ms 705728 KB Output is correct
3 Correct 266 ms 705736 KB Output is correct
4 Correct 271 ms 705716 KB Output is correct
5 Correct 271 ms 705720 KB Output is correct
6 Correct 268 ms 705740 KB Output is correct
7 Correct 278 ms 705692 KB Output is correct
8 Incorrect 255 ms 704784 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 352 ms 704716 KB Output is correct
2 Correct 277 ms 705728 KB Output is correct
3 Correct 266 ms 705736 KB Output is correct
4 Correct 271 ms 705716 KB Output is correct
5 Correct 271 ms 705720 KB Output is correct
6 Correct 268 ms 705740 KB Output is correct
7 Correct 278 ms 705692 KB Output is correct
8 Incorrect 255 ms 704784 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 281 ms 704688 KB Output is correct
2 Correct 264 ms 704800 KB Output is correct
3 Correct 308 ms 704808 KB Output is correct
4 Correct 263 ms 704844 KB Output is correct
5 Correct 278 ms 704788 KB Output is correct
6 Correct 265 ms 704740 KB Output is correct
7 Correct 260 ms 704800 KB Output is correct
8 Correct 259 ms 704832 KB Output is correct
9 Correct 261 ms 704824 KB Output is correct
10 Correct 255 ms 704788 KB Output is correct
11 Correct 273 ms 704696 KB Output is correct
12 Correct 275 ms 704836 KB Output is correct
13 Correct 253 ms 704712 KB Output is correct
14 Correct 255 ms 704712 KB Output is correct
15 Correct 259 ms 704820 KB Output is correct
16 Correct 258 ms 704696 KB Output is correct
17 Correct 269 ms 704828 KB Output is correct
18 Correct 268 ms 704796 KB Output is correct
19 Correct 275 ms 704780 KB Output is correct
20 Correct 258 ms 704844 KB Output is correct
21 Correct 256 ms 704736 KB Output is correct
22 Incorrect 260 ms 704848 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 281 ms 704688 KB Output is correct
2 Correct 264 ms 704800 KB Output is correct
3 Correct 308 ms 704808 KB Output is correct
4 Correct 263 ms 704844 KB Output is correct
5 Correct 278 ms 704788 KB Output is correct
6 Correct 265 ms 704740 KB Output is correct
7 Correct 260 ms 704800 KB Output is correct
8 Correct 259 ms 704832 KB Output is correct
9 Correct 261 ms 704824 KB Output is correct
10 Correct 255 ms 704788 KB Output is correct
11 Correct 273 ms 704696 KB Output is correct
12 Correct 275 ms 704836 KB Output is correct
13 Correct 253 ms 704712 KB Output is correct
14 Correct 255 ms 704712 KB Output is correct
15 Correct 259 ms 704820 KB Output is correct
16 Correct 352 ms 704716 KB Output is correct
17 Correct 277 ms 705728 KB Output is correct
18 Correct 266 ms 705736 KB Output is correct
19 Correct 271 ms 705716 KB Output is correct
20 Correct 271 ms 705720 KB Output is correct
21 Correct 268 ms 705740 KB Output is correct
22 Correct 278 ms 705692 KB Output is correct
23 Incorrect 255 ms 704784 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 281 ms 704688 KB Output is correct
2 Correct 264 ms 704800 KB Output is correct
3 Correct 308 ms 704808 KB Output is correct
4 Correct 263 ms 704844 KB Output is correct
5 Correct 278 ms 704788 KB Output is correct
6 Correct 265 ms 704740 KB Output is correct
7 Correct 260 ms 704800 KB Output is correct
8 Correct 259 ms 704832 KB Output is correct
9 Correct 261 ms 704824 KB Output is correct
10 Correct 255 ms 704788 KB Output is correct
11 Correct 273 ms 704696 KB Output is correct
12 Correct 275 ms 704836 KB Output is correct
13 Correct 253 ms 704712 KB Output is correct
14 Correct 255 ms 704712 KB Output is correct
15 Correct 259 ms 704820 KB Output is correct
16 Correct 848 ms 739728 KB Output is correct
17 Correct 873 ms 739656 KB Output is correct
18 Correct 867 ms 739496 KB Output is correct
19 Correct 834 ms 739528 KB Output is correct
20 Correct 839 ms 740144 KB Output is correct
21 Correct 856 ms 738980 KB Output is correct
22 Correct 934 ms 738972 KB Output is correct
23 Correct 817 ms 739492 KB Output is correct
24 Correct 875 ms 740240 KB Output is correct
25 Correct 856 ms 738964 KB Output is correct
26 Correct 876 ms 738956 KB Output is correct
27 Correct 856 ms 739608 KB Output is correct
28 Correct 877 ms 738988 KB Output is correct
29 Correct 871 ms 739620 KB Output is correct
30 Correct 906 ms 739596 KB Output is correct
31 Correct 938 ms 740240 KB Output is correct
32 Correct 897 ms 740264 KB Output is correct
33 Correct 889 ms 739624 KB Output is correct
34 Correct 911 ms 739632 KB Output is correct
35 Correct 911 ms 739744 KB Output is correct
36 Correct 352 ms 704716 KB Output is correct
37 Correct 277 ms 705728 KB Output is correct
38 Correct 266 ms 705736 KB Output is correct
39 Correct 271 ms 705716 KB Output is correct
40 Correct 271 ms 705720 KB Output is correct
41 Correct 268 ms 705740 KB Output is correct
42 Correct 278 ms 705692 KB Output is correct
43 Incorrect 255 ms 704784 KB Output isn't correct
44 Halted 0 ms 0 KB -