Submission #1018619

# Submission time Handle Problem Language Result Execution time Memory
1018619 2024-07-10T07:30:34 Z Tuanlinh123 Two Dishes (JOI19_dishes) C++17
100 / 100
3858 ms 248604 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;
 
const ll maxn=1000005, inf=1e18;
namespace SegTree
{
    ll n;
    struct Node
    {
        ll Min, lzs, lza;
 
        inline void act(ll a, ll s)
        {
            Min+=s, (lza==inf?lzs:lza)+=s;
            if (a!=inf) Min=lza=a, lzs=0;
        }
    } St[maxn*4];
 
    void Move(ll i)
    {
    	ll a=St[i].lza, s=St[i].lzs;
    	St[i*2].act(a, s), St[i*2+1].act(a, s);
     	St[i].lza=inf, St[i].lzs=0;
    }
 
    void update(ll i, ll Start, ll End, ll l, ll r, ll a, ll s)
    {
        if (Start>=l && End<=r) {St[i].act(a, s); return;}
        ll mid=(Start+End)/2; Move(i);
        if (mid>=l) update(i*2, Start, mid, l, r, a, s);
        if (mid+1<=r) update(i*2+1, mid+1, End, l, r, a, s);
        St[i].Min=min(St[i*2].Min, St[i*2+1].Min);
    }
    void add(ll l, ll r, ll v) {update(1, 0, n, l, r, inf, v);}
    void ass(ll l, ll r, ll v) {update(1, 0, n, l, r, v, 0);}
 
    ll Find(ll i, ll Start, ll End, ll idx, ll v)
    {
        if (Start==End) return Start;
        ll mid=(Start+End)/2; Move(i);
        if (mid+1<=idx || St[i*2+1].Min<=v) 
            return Find(i*2+1, mid+1, End, idx, v);
        return Find(i*2, Start, mid, idx, v);
    }
    ll Find(ll idx, ll v) {return Find(1, 0, n, idx, v);}
 
    ll query(ll i, ll Start, ll End, ll idx)
    {
        if (Start==End) return St[i].Min;
        ll mid=(Start+End)/2; Move(i);
        if (mid>=idx) return query(i*2, Start, mid, idx);
        return query(i*2+1, mid+1, End, idx);
    }
    ll query(ll idx){return query(1, 0, n, idx);}
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, m, sum=0; cin >> n >> m, SegTree::n=m;
    vector <ll> a(n), s(n), p(n), b(m), t(m), q(m);
    vector <vector <pll>> H(n);
    for (ll i=0; i<n; i++) cin >> a[i] >> s[i] >> p[i];
    for (ll j=0; j<m; j++) cin >> b[j] >> t[j] >> q[j];
    for (ll i=1; i<n; i++) a[i]+=a[i-1];
    for (ll i=1; i<m; i++) b[i]+=b[i-1];
    for (ll i=0; i<n; i++)
    {
        if (s[i]-a[i]<0) continue; sum+=p[i];
        ll pos=lower_bound(b.begin(), b.end(), s[i]-a[i]+1)-b.begin();
        if (pos<m) H[i].pb({pos+1, -p[i]});
    }
    for (ll i=0; i<m; i++)
    {
        if (t[i]-b[i]<0) continue;
        ll pos=lower_bound(a.begin(), a.end(), t[i]-b[i]+1)-a.begin();
        if (pos<n) H[pos].pb({i+1, q[i]});
        else sum+=q[i];
    }
    SegTree::ass(0, m, sum);
    for (ll i=0; i<n; i++)
    {
        vector <pll> range, r;
        sort(H[i].begin(), H[i].end());
        for (auto [p, w]:H[i])
        {
            SegTree::add(p, m, w);
            if (!sz(range) || range.back().fi!=p)
                range.pb({p, w});
            else range.back().se+=w;
        }
        range.pb({m+1, 0});
        for (ll j=0, sum=0; j<sz(range); j++)
            r.pb({range[j].fi-1, sum}), sum+=range[j].se;
        vector <ll> mi(sz(r), -inf);
        for (ll j=1; j<sz(mi); j++)
            mi[j]=max(mi[j-1], SegTree::query(r[j-1].fi));
        for (ll j=sz(mi)-1; j>=0; j--)
        {
            ll st=j?r[j-1].fi+1:0;
            if (SegTree::query(st)>=mi[j]) continue;
            SegTree::ass(st, SegTree::Find(st, mi[j]), mi[j]);
        }
        // for (ll j=0; j<=m; j++) cout << SegTree::query(j) << " "; cout << "\n";
    }
    cout << SegTree::query(m);
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:78:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   78 |         if (s[i]-a[i]<0) continue; sum+=p[i];
      |         ^~
dishes.cpp:78:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   78 |         if (s[i]-a[i]<0) continue; sum+=p[i];
      |                                    ^~~
# Verdict Execution time Memory Grader output
1 Correct 302 ms 35648 KB Output is correct
2 Correct 332 ms 48296 KB Output is correct
3 Correct 121 ms 27984 KB Output is correct
4 Correct 215 ms 41252 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 282 ms 44596 KB Output is correct
7 Correct 45 ms 11856 KB Output is correct
8 Correct 60 ms 16724 KB Output is correct
9 Correct 128 ms 28896 KB Output is correct
10 Correct 282 ms 43604 KB Output is correct
11 Correct 106 ms 22232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 856 KB Output is correct
19 Correct 4 ms 856 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 3 ms 704 KB Output is correct
22 Correct 4 ms 864 KB Output is correct
23 Correct 4 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 856 KB Output is correct
19 Correct 4 ms 856 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 3 ms 704 KB Output is correct
22 Correct 4 ms 864 KB Output is correct
23 Correct 4 ms 856 KB Output is correct
24 Correct 250 ms 31324 KB Output is correct
25 Correct 224 ms 53208 KB Output is correct
26 Correct 262 ms 43604 KB Output is correct
27 Correct 207 ms 43600 KB Output is correct
28 Correct 287 ms 40532 KB Output is correct
29 Correct 116 ms 25684 KB Output is correct
30 Correct 657 ms 49024 KB Output is correct
31 Correct 122 ms 28824 KB Output is correct
32 Correct 64 ms 18000 KB Output is correct
33 Correct 482 ms 42740 KB Output is correct
34 Correct 520 ms 46224 KB Output is correct
35 Correct 666 ms 42580 KB Output is correct
36 Correct 700 ms 42408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 856 KB Output is correct
19 Correct 4 ms 856 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 3 ms 704 KB Output is correct
22 Correct 4 ms 864 KB Output is correct
23 Correct 4 ms 856 KB Output is correct
24 Correct 250 ms 31324 KB Output is correct
25 Correct 224 ms 53208 KB Output is correct
26 Correct 262 ms 43604 KB Output is correct
27 Correct 207 ms 43600 KB Output is correct
28 Correct 287 ms 40532 KB Output is correct
29 Correct 116 ms 25684 KB Output is correct
30 Correct 657 ms 49024 KB Output is correct
31 Correct 122 ms 28824 KB Output is correct
32 Correct 64 ms 18000 KB Output is correct
33 Correct 482 ms 42740 KB Output is correct
34 Correct 520 ms 46224 KB Output is correct
35 Correct 666 ms 42580 KB Output is correct
36 Correct 700 ms 42408 KB Output is correct
37 Correct 279 ms 46656 KB Output is correct
38 Correct 240 ms 46816 KB Output is correct
39 Correct 281 ms 47196 KB Output is correct
40 Correct 384 ms 47184 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 718 ms 52112 KB Output is correct
43 Correct 391 ms 45244 KB Output is correct
44 Correct 506 ms 48976 KB Output is correct
45 Correct 611 ms 45852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 856 KB Output is correct
19 Correct 4 ms 856 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 3 ms 704 KB Output is correct
22 Correct 4 ms 864 KB Output is correct
23 Correct 4 ms 856 KB Output is correct
24 Correct 250 ms 31324 KB Output is correct
25 Correct 224 ms 53208 KB Output is correct
26 Correct 262 ms 43604 KB Output is correct
27 Correct 207 ms 43600 KB Output is correct
28 Correct 287 ms 40532 KB Output is correct
29 Correct 116 ms 25684 KB Output is correct
30 Correct 657 ms 49024 KB Output is correct
31 Correct 122 ms 28824 KB Output is correct
32 Correct 64 ms 18000 KB Output is correct
33 Correct 482 ms 42740 KB Output is correct
34 Correct 520 ms 46224 KB Output is correct
35 Correct 666 ms 42580 KB Output is correct
36 Correct 700 ms 42408 KB Output is correct
37 Correct 279 ms 46656 KB Output is correct
38 Correct 240 ms 46816 KB Output is correct
39 Correct 281 ms 47196 KB Output is correct
40 Correct 384 ms 47184 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 718 ms 52112 KB Output is correct
43 Correct 391 ms 45244 KB Output is correct
44 Correct 506 ms 48976 KB Output is correct
45 Correct 611 ms 45852 KB Output is correct
46 Correct 1379 ms 221632 KB Output is correct
47 Correct 1163 ms 221244 KB Output is correct
48 Correct 1364 ms 223512 KB Output is correct
49 Correct 1796 ms 223568 KB Output is correct
50 Correct 3854 ms 247712 KB Output is correct
51 Correct 2149 ms 210820 KB Output is correct
52 Correct 2491 ms 222796 KB Output is correct
53 Correct 3512 ms 214760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 35648 KB Output is correct
2 Correct 332 ms 48296 KB Output is correct
3 Correct 121 ms 27984 KB Output is correct
4 Correct 215 ms 41252 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 282 ms 44596 KB Output is correct
7 Correct 45 ms 11856 KB Output is correct
8 Correct 60 ms 16724 KB Output is correct
9 Correct 128 ms 28896 KB Output is correct
10 Correct 282 ms 43604 KB Output is correct
11 Correct 106 ms 22232 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 4 ms 856 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 704 KB Output is correct
33 Correct 4 ms 864 KB Output is correct
34 Correct 4 ms 856 KB Output is correct
35 Correct 250 ms 31324 KB Output is correct
36 Correct 224 ms 53208 KB Output is correct
37 Correct 262 ms 43604 KB Output is correct
38 Correct 207 ms 43600 KB Output is correct
39 Correct 287 ms 40532 KB Output is correct
40 Correct 116 ms 25684 KB Output is correct
41 Correct 657 ms 49024 KB Output is correct
42 Correct 122 ms 28824 KB Output is correct
43 Correct 64 ms 18000 KB Output is correct
44 Correct 482 ms 42740 KB Output is correct
45 Correct 520 ms 46224 KB Output is correct
46 Correct 666 ms 42580 KB Output is correct
47 Correct 700 ms 42408 KB Output is correct
48 Correct 279 ms 46656 KB Output is correct
49 Correct 240 ms 46816 KB Output is correct
50 Correct 281 ms 47196 KB Output is correct
51 Correct 384 ms 47184 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 718 ms 52112 KB Output is correct
54 Correct 391 ms 45244 KB Output is correct
55 Correct 506 ms 48976 KB Output is correct
56 Correct 611 ms 45852 KB Output is correct
57 Correct 222 ms 47044 KB Output is correct
58 Correct 261 ms 47196 KB Output is correct
59 Correct 355 ms 48212 KB Output is correct
60 Correct 255 ms 48212 KB Output is correct
61 Correct 407 ms 49232 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 618 ms 52052 KB Output is correct
64 Correct 368 ms 45580 KB Output is correct
65 Correct 467 ms 48864 KB Output is correct
66 Correct 589 ms 45396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 35648 KB Output is correct
2 Correct 332 ms 48296 KB Output is correct
3 Correct 121 ms 27984 KB Output is correct
4 Correct 215 ms 41252 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 282 ms 44596 KB Output is correct
7 Correct 45 ms 11856 KB Output is correct
8 Correct 60 ms 16724 KB Output is correct
9 Correct 128 ms 28896 KB Output is correct
10 Correct 282 ms 43604 KB Output is correct
11 Correct 106 ms 22232 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 4 ms 856 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 704 KB Output is correct
33 Correct 4 ms 864 KB Output is correct
34 Correct 4 ms 856 KB Output is correct
35 Correct 250 ms 31324 KB Output is correct
36 Correct 224 ms 53208 KB Output is correct
37 Correct 262 ms 43604 KB Output is correct
38 Correct 207 ms 43600 KB Output is correct
39 Correct 287 ms 40532 KB Output is correct
40 Correct 116 ms 25684 KB Output is correct
41 Correct 657 ms 49024 KB Output is correct
42 Correct 122 ms 28824 KB Output is correct
43 Correct 64 ms 18000 KB Output is correct
44 Correct 482 ms 42740 KB Output is correct
45 Correct 520 ms 46224 KB Output is correct
46 Correct 666 ms 42580 KB Output is correct
47 Correct 700 ms 42408 KB Output is correct
48 Correct 279 ms 46656 KB Output is correct
49 Correct 240 ms 46816 KB Output is correct
50 Correct 281 ms 47196 KB Output is correct
51 Correct 384 ms 47184 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 718 ms 52112 KB Output is correct
54 Correct 391 ms 45244 KB Output is correct
55 Correct 506 ms 48976 KB Output is correct
56 Correct 611 ms 45852 KB Output is correct
57 Correct 1379 ms 221632 KB Output is correct
58 Correct 1163 ms 221244 KB Output is correct
59 Correct 1364 ms 223512 KB Output is correct
60 Correct 1796 ms 223568 KB Output is correct
61 Correct 3854 ms 247712 KB Output is correct
62 Correct 2149 ms 210820 KB Output is correct
63 Correct 2491 ms 222796 KB Output is correct
64 Correct 3512 ms 214760 KB Output is correct
65 Correct 222 ms 47044 KB Output is correct
66 Correct 261 ms 47196 KB Output is correct
67 Correct 355 ms 48212 KB Output is correct
68 Correct 255 ms 48212 KB Output is correct
69 Correct 407 ms 49232 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 618 ms 52052 KB Output is correct
72 Correct 368 ms 45580 KB Output is correct
73 Correct 467 ms 48864 KB Output is correct
74 Correct 589 ms 45396 KB Output is correct
75 Correct 1130 ms 223152 KB Output is correct
76 Correct 1387 ms 223288 KB Output is correct
77 Correct 1816 ms 225704 KB Output is correct
78 Correct 1382 ms 225920 KB Output is correct
79 Correct 3858 ms 248604 KB Output is correct
80 Correct 2074 ms 212532 KB Output is correct
81 Correct 2603 ms 222280 KB Output is correct
82 Correct 3575 ms 215972 KB Output is correct
83 Correct 3519 ms 232604 KB Output is correct