Submission #375820

# Submission time Handle Problem Language Result Execution time Memory
375820 2021-03-10T03:05:40 Z jainbot27 Two Dishes (JOI19_dishes) C++17
100 / 100
7332 ms 319260 KB
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()

#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const char nl = '\n';
const int mxN = 1e6+10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;

//use to make shit go faster (magic from KACTL)
static char buf[450 << 20];
void* operator new(size_t s) {
    static size_t i = sizeof buf;
    assert(s < i);
    return (void*)&buf[i -= s];
}
void operator delete(void*) {}
// implicit lazy segment tree adapted from KACTL
template<class V> struct Node {
    Node *l = 0, *r = 0;
    const V no_op = infLL;
    int lo, hi; V madd = 0, val = 0;
    Node(int lo,int hi):lo(lo),hi(hi){} 
    Node(vector<V>& v, int lo, int hi) : lo(lo), hi(hi) {
        if (lo + 1 < hi) {
            int mid = lo + (hi - lo)/2;
            l = new Node(v, lo, mid); r = new Node(v, mid, hi);
            val = l->val+r->val;
        }
        else val = v[lo];
    }
    V query(int L, int R) {
        if (R <= lo || hi <= L) return -infLL;
        if (L <= lo && hi <= R) return val;
        push();
        return max(l->query(L, R), r->query(L, R));
    }
    void mx(int L, V x) {
        if(lo==hi-1) {
            if(val < x) {
                val = x;
                madd = x;
            }
        }
        else{
            push();
            int m = (lo+hi)/2; if(L<m) l->mx(L, x);
            else r->mx(L, x);
            val = max(l->val, r->val);
        }
    }
    void add(int L, int R, V x) {
        if (R <= lo || hi <= L) return;
        if (L <= lo && hi <= R) {
            madd += x;
            val += x;
        }
        else {
            push(), l->add(L, R, x), r->add(L, R, x);
            val = max(l->val, r->val);
        }
    }
    void push() {
        if (!l) {
            int mid = lo + (hi - lo)/2;
            l = new Node(lo, mid); r = new Node(mid, hi);
        }
        if(madd) l->add(lo,hi,madd), r->add(lo,hi,madd), madd = 0;
    }
};

Node<ll>* st = new Node<ll>(0, mxN);
pair<int, pair<ll, ll>> a[mxN], b[mxN];
ll pa[mxN], pb[mxN];
ll ans;
map<pii, ll> mp;
int n, m;

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    FOR(i, 1, n+1){
        cin >> a[i].f >> a[i].s.f >> a[i].s.s;
        pa[i] = pa[i-1]+a[i].f;
    }
    FOR(i, 1, m+1){
        cin >> b[i].f >> b[i].s.f >> b[i].s.s;
        pb[i] = pb[i-1]+b[i].f;
    }
    FOR(i, 1, n+1){
        if(pa[i]>a[i].s.f) continue;
        if(pb[m]+pa[i]<=a[i].s.f) {
            ans += a[i].s.s ;
            continue;
        }
        //mp[{i-1, -(lower_bound(pb+1, pb+1+m, a[i].s.f-pa[i]+1)-pb-1+1)}] += a[i].s.s;
        int pt = lower_bound(pb+1, pb+m+1, a[i].s.f-pa[i]+1)-pb;
        pt--;
        mp[{i-1, -(pt+1)}]+=a[i].s.s;
    } 
    FOR(i, 1, m+1){
        if(pb[i]>b[i].s.f) continue;
        if(pb[i]+pa[n]<=b[i].s.f) {
            ans += b[i].s.s;
            continue;
        }
        ans += b[i].s.s;
        int pt = lower_bound(pa+1, pa+n+1, b[i].s.f-pb[i]+1)-pa;
        pt--;
        mp[{pt, -i}]-=b[i].s.s;
    }
    trav(cur, mp){
        int x = cur.f.f, y = -cur.f.s, z = cur.s;
        //cout << x << ' ' << y << ' ' << z << endl;
        ll t = st->query(0, y);
        //cout << t  << endl;
        st->mx(y, t);
        //cout << "WE GOT HERE" << endl;
        st->add(0, y, z);
    }
    cout << st->query(0, mxN)+ans << nl;
    return 0;
}

Compilation message

dishes.cpp: In function 'int32_t main()':
dishes.cpp:135:13: warning: unused variable 'x' [-Wunused-variable]
  135 |         int x = cur.f.f, y = -cur.f.s, z = cur.s;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 435 ms 41196 KB Output is correct
2 Correct 408 ms 39916 KB Output is correct
3 Correct 168 ms 12908 KB Output is correct
4 Correct 313 ms 30188 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 375 ms 34924 KB Output is correct
7 Correct 86 ms 6636 KB Output is correct
8 Correct 88 ms 6636 KB Output is correct
9 Correct 174 ms 13036 KB Output is correct
10 Correct 375 ms 41068 KB Output is correct
11 Correct 140 ms 12908 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
# 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 4 ms 620 KB Output is correct
18 Correct 5 ms 876 KB Output is correct
19 Correct 6 ms 876 KB Output is correct
20 Correct 4 ms 748 KB Output is correct
21 Correct 5 ms 876 KB Output is correct
22 Correct 6 ms 876 KB Output is correct
23 Correct 6 ms 876 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 4 ms 620 KB Output is correct
18 Correct 5 ms 876 KB Output is correct
19 Correct 6 ms 876 KB Output is correct
20 Correct 4 ms 748 KB Output is correct
21 Correct 5 ms 876 KB Output is correct
22 Correct 6 ms 876 KB Output is correct
23 Correct 6 ms 876 KB Output is correct
24 Correct 297 ms 22636 KB Output is correct
25 Correct 357 ms 51820 KB Output is correct
26 Correct 360 ms 51968 KB Output is correct
27 Correct 392 ms 51820 KB Output is correct
28 Correct 355 ms 43628 KB Output is correct
29 Correct 153 ms 24300 KB Output is correct
30 Correct 1010 ms 60904 KB Output is correct
31 Correct 199 ms 32876 KB Output is correct
32 Correct 142 ms 16620 KB Output is correct
33 Correct 562 ms 50156 KB Output is correct
34 Correct 797 ms 55660 KB Output is correct
35 Correct 1002 ms 54380 KB Output is correct
36 Correct 942 ms 54304 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 4 ms 620 KB Output is correct
18 Correct 5 ms 876 KB Output is correct
19 Correct 6 ms 876 KB Output is correct
20 Correct 4 ms 748 KB Output is correct
21 Correct 5 ms 876 KB Output is correct
22 Correct 6 ms 876 KB Output is correct
23 Correct 6 ms 876 KB Output is correct
24 Correct 297 ms 22636 KB Output is correct
25 Correct 357 ms 51820 KB Output is correct
26 Correct 360 ms 51968 KB Output is correct
27 Correct 392 ms 51820 KB Output is correct
28 Correct 355 ms 43628 KB Output is correct
29 Correct 153 ms 24300 KB Output is correct
30 Correct 1010 ms 60904 KB Output is correct
31 Correct 199 ms 32876 KB Output is correct
32 Correct 142 ms 16620 KB Output is correct
33 Correct 562 ms 50156 KB Output is correct
34 Correct 797 ms 55660 KB Output is correct
35 Correct 1002 ms 54380 KB Output is correct
36 Correct 942 ms 54304 KB Output is correct
37 Correct 366 ms 54736 KB Output is correct
38 Correct 374 ms 54892 KB Output is correct
39 Correct 383 ms 52076 KB Output is correct
40 Correct 383 ms 52204 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1022 ms 63596 KB Output is correct
43 Correct 578 ms 53244 KB Output is correct
44 Correct 781 ms 58200 KB Output is correct
45 Correct 984 ms 57580 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 4 ms 620 KB Output is correct
18 Correct 5 ms 876 KB Output is correct
19 Correct 6 ms 876 KB Output is correct
20 Correct 4 ms 748 KB Output is correct
21 Correct 5 ms 876 KB Output is correct
22 Correct 6 ms 876 KB Output is correct
23 Correct 6 ms 876 KB Output is correct
24 Correct 297 ms 22636 KB Output is correct
25 Correct 357 ms 51820 KB Output is correct
26 Correct 360 ms 51968 KB Output is correct
27 Correct 392 ms 51820 KB Output is correct
28 Correct 355 ms 43628 KB Output is correct
29 Correct 153 ms 24300 KB Output is correct
30 Correct 1010 ms 60904 KB Output is correct
31 Correct 199 ms 32876 KB Output is correct
32 Correct 142 ms 16620 KB Output is correct
33 Correct 562 ms 50156 KB Output is correct
34 Correct 797 ms 55660 KB Output is correct
35 Correct 1002 ms 54380 KB Output is correct
36 Correct 942 ms 54304 KB Output is correct
37 Correct 366 ms 54736 KB Output is correct
38 Correct 374 ms 54892 KB Output is correct
39 Correct 383 ms 52076 KB Output is correct
40 Correct 383 ms 52204 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1022 ms 63596 KB Output is correct
43 Correct 578 ms 53244 KB Output is correct
44 Correct 781 ms 58200 KB Output is correct
45 Correct 984 ms 57580 KB Output is correct
46 Correct 1911 ms 274128 KB Output is correct
47 Correct 1925 ms 273884 KB Output is correct
48 Correct 2029 ms 260320 KB Output is correct
49 Correct 1990 ms 260380 KB Output is correct
50 Correct 7332 ms 319260 KB Output is correct
51 Correct 3714 ms 260356 KB Output is correct
52 Correct 4770 ms 272480 KB Output is correct
53 Correct 6834 ms 284448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 435 ms 41196 KB Output is correct
2 Correct 408 ms 39916 KB Output is correct
3 Correct 168 ms 12908 KB Output is correct
4 Correct 313 ms 30188 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 375 ms 34924 KB Output is correct
7 Correct 86 ms 6636 KB Output is correct
8 Correct 88 ms 6636 KB Output is correct
9 Correct 174 ms 13036 KB Output is correct
10 Correct 375 ms 41068 KB Output is correct
11 Correct 140 ms 12908 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 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 4 ms 620 KB Output is correct
29 Correct 5 ms 876 KB Output is correct
30 Correct 6 ms 876 KB Output is correct
31 Correct 4 ms 748 KB Output is correct
32 Correct 5 ms 876 KB Output is correct
33 Correct 6 ms 876 KB Output is correct
34 Correct 6 ms 876 KB Output is correct
35 Correct 297 ms 22636 KB Output is correct
36 Correct 357 ms 51820 KB Output is correct
37 Correct 360 ms 51968 KB Output is correct
38 Correct 392 ms 51820 KB Output is correct
39 Correct 355 ms 43628 KB Output is correct
40 Correct 153 ms 24300 KB Output is correct
41 Correct 1010 ms 60904 KB Output is correct
42 Correct 199 ms 32876 KB Output is correct
43 Correct 142 ms 16620 KB Output is correct
44 Correct 562 ms 50156 KB Output is correct
45 Correct 797 ms 55660 KB Output is correct
46 Correct 1002 ms 54380 KB Output is correct
47 Correct 942 ms 54304 KB Output is correct
48 Correct 366 ms 54736 KB Output is correct
49 Correct 374 ms 54892 KB Output is correct
50 Correct 383 ms 52076 KB Output is correct
51 Correct 383 ms 52204 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1022 ms 63596 KB Output is correct
54 Correct 578 ms 53244 KB Output is correct
55 Correct 781 ms 58200 KB Output is correct
56 Correct 984 ms 57580 KB Output is correct
57 Correct 374 ms 55300 KB Output is correct
58 Correct 375 ms 55276 KB Output is correct
59 Correct 405 ms 53100 KB Output is correct
60 Correct 407 ms 53100 KB Output is correct
61 Correct 1032 ms 61164 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1158 ms 63736 KB Output is correct
64 Correct 576 ms 52316 KB Output is correct
65 Correct 789 ms 59344 KB Output is correct
66 Correct 1018 ms 57108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 435 ms 41196 KB Output is correct
2 Correct 408 ms 39916 KB Output is correct
3 Correct 168 ms 12908 KB Output is correct
4 Correct 313 ms 30188 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 375 ms 34924 KB Output is correct
7 Correct 86 ms 6636 KB Output is correct
8 Correct 88 ms 6636 KB Output is correct
9 Correct 174 ms 13036 KB Output is correct
10 Correct 375 ms 41068 KB Output is correct
11 Correct 140 ms 12908 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 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 4 ms 620 KB Output is correct
29 Correct 5 ms 876 KB Output is correct
30 Correct 6 ms 876 KB Output is correct
31 Correct 4 ms 748 KB Output is correct
32 Correct 5 ms 876 KB Output is correct
33 Correct 6 ms 876 KB Output is correct
34 Correct 6 ms 876 KB Output is correct
35 Correct 297 ms 22636 KB Output is correct
36 Correct 357 ms 51820 KB Output is correct
37 Correct 360 ms 51968 KB Output is correct
38 Correct 392 ms 51820 KB Output is correct
39 Correct 355 ms 43628 KB Output is correct
40 Correct 153 ms 24300 KB Output is correct
41 Correct 1010 ms 60904 KB Output is correct
42 Correct 199 ms 32876 KB Output is correct
43 Correct 142 ms 16620 KB Output is correct
44 Correct 562 ms 50156 KB Output is correct
45 Correct 797 ms 55660 KB Output is correct
46 Correct 1002 ms 54380 KB Output is correct
47 Correct 942 ms 54304 KB Output is correct
48 Correct 366 ms 54736 KB Output is correct
49 Correct 374 ms 54892 KB Output is correct
50 Correct 383 ms 52076 KB Output is correct
51 Correct 383 ms 52204 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1022 ms 63596 KB Output is correct
54 Correct 578 ms 53244 KB Output is correct
55 Correct 781 ms 58200 KB Output is correct
56 Correct 984 ms 57580 KB Output is correct
57 Correct 1911 ms 274128 KB Output is correct
58 Correct 1925 ms 273884 KB Output is correct
59 Correct 2029 ms 260320 KB Output is correct
60 Correct 1990 ms 260380 KB Output is correct
61 Correct 7332 ms 319260 KB Output is correct
62 Correct 3714 ms 260356 KB Output is correct
63 Correct 4770 ms 272480 KB Output is correct
64 Correct 6834 ms 284448 KB Output is correct
65 Correct 374 ms 55300 KB Output is correct
66 Correct 375 ms 55276 KB Output is correct
67 Correct 405 ms 53100 KB Output is correct
68 Correct 407 ms 53100 KB Output is correct
69 Correct 1032 ms 61164 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1158 ms 63736 KB Output is correct
72 Correct 576 ms 52316 KB Output is correct
73 Correct 789 ms 59344 KB Output is correct
74 Correct 1018 ms 57108 KB Output is correct
75 Correct 2015 ms 275720 KB Output is correct
76 Correct 1921 ms 275652 KB Output is correct
77 Correct 1997 ms 262604 KB Output is correct
78 Correct 2012 ms 262740 KB Output is correct
79 Correct 7110 ms 319188 KB Output is correct
80 Correct 3566 ms 255772 KB Output is correct
81 Correct 4735 ms 282896 KB Output is correct
82 Correct 6557 ms 286476 KB Output is correct
83 Correct 6619 ms 301084 KB Output is correct