답안 #963963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963963 2024-04-16T05:57:07 Z Tuanlinh123 Two Dishes (JOI19_dishes) C++17
100 / 100
4530 ms 248564 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)
    {
        if (St[i].lza!=inf)
        {
            ll t=St[i].lza; St[i].lza=inf;
            St[i*2].lza=St[i*2].Min=t, St[i*2].lzs=0;
            St[i*2+1].lza=St[i*2+1].Min=t, St[i*2+1].lzs=0;
        }
        else if (St[i].lzs)
        {
            ll t=St[i].lzs; St[i].lzs=0;
            (St[i*2].lza==inf?St[i*2].lzs:St[i*2].lza)+=t, St[i*2].Min+=t;
            (St[i*2+1].lza==inf?St[i*2+1].lzs:St[i*2+1].lza)+=t, St[i*2+1].Min+=t;
        }
    }

    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:87:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   87 |         if (s[i]-a[i]<0) continue; sum+=p[i];
      |         ^~
dishes.cpp:87:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   87 |         if (s[i]-a[i]<0) continue; sum+=p[i];
      |                                    ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 303 ms 49100 KB Output is correct
2 Correct 352 ms 48208 KB Output is correct
3 Correct 133 ms 27984 KB Output is correct
4 Correct 221 ms 41296 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 300 ms 44600 KB Output is correct
7 Correct 61 ms 11936 KB Output is correct
8 Correct 67 ms 16636 KB Output is correct
9 Correct 146 ms 28764 KB Output is correct
10 Correct 295 ms 43736 KB Output is correct
11 Correct 104 ms 22348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 424 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 424 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 4 ms 856 KB Output is correct
23 Correct 5 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 424 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 4 ms 856 KB Output is correct
23 Correct 5 ms 860 KB Output is correct
24 Correct 266 ms 31312 KB Output is correct
25 Correct 208 ms 49844 KB Output is correct
26 Correct 312 ms 43732 KB Output is correct
27 Correct 216 ms 43612 KB Output is correct
28 Correct 284 ms 40748 KB Output is correct
29 Correct 126 ms 25952 KB Output is correct
30 Correct 655 ms 49028 KB Output is correct
31 Correct 93 ms 28748 KB Output is correct
32 Correct 73 ms 18004 KB Output is correct
33 Correct 444 ms 42608 KB Output is correct
34 Correct 478 ms 45968 KB Output is correct
35 Correct 634 ms 42576 KB Output is correct
36 Correct 603 ms 42416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 424 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 4 ms 856 KB Output is correct
23 Correct 5 ms 860 KB Output is correct
24 Correct 266 ms 31312 KB Output is correct
25 Correct 208 ms 49844 KB Output is correct
26 Correct 312 ms 43732 KB Output is correct
27 Correct 216 ms 43612 KB Output is correct
28 Correct 284 ms 40748 KB Output is correct
29 Correct 126 ms 25952 KB Output is correct
30 Correct 655 ms 49028 KB Output is correct
31 Correct 93 ms 28748 KB Output is correct
32 Correct 73 ms 18004 KB Output is correct
33 Correct 444 ms 42608 KB Output is correct
34 Correct 478 ms 45968 KB Output is correct
35 Correct 634 ms 42576 KB Output is correct
36 Correct 603 ms 42416 KB Output is correct
37 Correct 301 ms 46796 KB Output is correct
38 Correct 231 ms 46696 KB Output is correct
39 Correct 267 ms 47196 KB Output is correct
40 Correct 366 ms 47428 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 631 ms 52116 KB Output is correct
43 Correct 373 ms 45396 KB Output is correct
44 Correct 486 ms 48896 KB Output is correct
45 Correct 677 ms 45848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 424 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 4 ms 856 KB Output is correct
23 Correct 5 ms 860 KB Output is correct
24 Correct 266 ms 31312 KB Output is correct
25 Correct 208 ms 49844 KB Output is correct
26 Correct 312 ms 43732 KB Output is correct
27 Correct 216 ms 43612 KB Output is correct
28 Correct 284 ms 40748 KB Output is correct
29 Correct 126 ms 25952 KB Output is correct
30 Correct 655 ms 49028 KB Output is correct
31 Correct 93 ms 28748 KB Output is correct
32 Correct 73 ms 18004 KB Output is correct
33 Correct 444 ms 42608 KB Output is correct
34 Correct 478 ms 45968 KB Output is correct
35 Correct 634 ms 42576 KB Output is correct
36 Correct 603 ms 42416 KB Output is correct
37 Correct 301 ms 46796 KB Output is correct
38 Correct 231 ms 46696 KB Output is correct
39 Correct 267 ms 47196 KB Output is correct
40 Correct 366 ms 47428 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 631 ms 52116 KB Output is correct
43 Correct 373 ms 45396 KB Output is correct
44 Correct 486 ms 48896 KB Output is correct
45 Correct 677 ms 45848 KB Output is correct
46 Correct 1553 ms 221584 KB Output is correct
47 Correct 1319 ms 221352 KB Output is correct
48 Correct 1596 ms 223560 KB Output is correct
49 Correct 2185 ms 223292 KB Output is correct
50 Correct 4530 ms 247960 KB Output is correct
51 Correct 2366 ms 210704 KB Output is correct
52 Correct 2723 ms 222732 KB Output is correct
53 Correct 3859 ms 214788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 303 ms 49100 KB Output is correct
2 Correct 352 ms 48208 KB Output is correct
3 Correct 133 ms 27984 KB Output is correct
4 Correct 221 ms 41296 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 300 ms 44600 KB Output is correct
7 Correct 61 ms 11936 KB Output is correct
8 Correct 67 ms 16636 KB Output is correct
9 Correct 146 ms 28764 KB Output is correct
10 Correct 295 ms 43736 KB Output is correct
11 Correct 104 ms 22348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 424 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 4 ms 860 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 4 ms 856 KB Output is correct
34 Correct 5 ms 860 KB Output is correct
35 Correct 266 ms 31312 KB Output is correct
36 Correct 208 ms 49844 KB Output is correct
37 Correct 312 ms 43732 KB Output is correct
38 Correct 216 ms 43612 KB Output is correct
39 Correct 284 ms 40748 KB Output is correct
40 Correct 126 ms 25952 KB Output is correct
41 Correct 655 ms 49028 KB Output is correct
42 Correct 93 ms 28748 KB Output is correct
43 Correct 73 ms 18004 KB Output is correct
44 Correct 444 ms 42608 KB Output is correct
45 Correct 478 ms 45968 KB Output is correct
46 Correct 634 ms 42576 KB Output is correct
47 Correct 603 ms 42416 KB Output is correct
48 Correct 301 ms 46796 KB Output is correct
49 Correct 231 ms 46696 KB Output is correct
50 Correct 267 ms 47196 KB Output is correct
51 Correct 366 ms 47428 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 631 ms 52116 KB Output is correct
54 Correct 373 ms 45396 KB Output is correct
55 Correct 486 ms 48896 KB Output is correct
56 Correct 677 ms 45848 KB Output is correct
57 Correct 230 ms 47160 KB Output is correct
58 Correct 290 ms 47208 KB Output is correct
59 Correct 394 ms 48228 KB Output is correct
60 Correct 311 ms 48296 KB Output is correct
61 Correct 480 ms 49464 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 661 ms 52064 KB Output is correct
64 Correct 396 ms 45616 KB Output is correct
65 Correct 479 ms 48720 KB Output is correct
66 Correct 611 ms 45632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 303 ms 49100 KB Output is correct
2 Correct 352 ms 48208 KB Output is correct
3 Correct 133 ms 27984 KB Output is correct
4 Correct 221 ms 41296 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 300 ms 44600 KB Output is correct
7 Correct 61 ms 11936 KB Output is correct
8 Correct 67 ms 16636 KB Output is correct
9 Correct 146 ms 28764 KB Output is correct
10 Correct 295 ms 43736 KB Output is correct
11 Correct 104 ms 22348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 424 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 4 ms 860 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 4 ms 856 KB Output is correct
34 Correct 5 ms 860 KB Output is correct
35 Correct 266 ms 31312 KB Output is correct
36 Correct 208 ms 49844 KB Output is correct
37 Correct 312 ms 43732 KB Output is correct
38 Correct 216 ms 43612 KB Output is correct
39 Correct 284 ms 40748 KB Output is correct
40 Correct 126 ms 25952 KB Output is correct
41 Correct 655 ms 49028 KB Output is correct
42 Correct 93 ms 28748 KB Output is correct
43 Correct 73 ms 18004 KB Output is correct
44 Correct 444 ms 42608 KB Output is correct
45 Correct 478 ms 45968 KB Output is correct
46 Correct 634 ms 42576 KB Output is correct
47 Correct 603 ms 42416 KB Output is correct
48 Correct 301 ms 46796 KB Output is correct
49 Correct 231 ms 46696 KB Output is correct
50 Correct 267 ms 47196 KB Output is correct
51 Correct 366 ms 47428 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 631 ms 52116 KB Output is correct
54 Correct 373 ms 45396 KB Output is correct
55 Correct 486 ms 48896 KB Output is correct
56 Correct 677 ms 45848 KB Output is correct
57 Correct 1553 ms 221584 KB Output is correct
58 Correct 1319 ms 221352 KB Output is correct
59 Correct 1596 ms 223560 KB Output is correct
60 Correct 2185 ms 223292 KB Output is correct
61 Correct 4530 ms 247960 KB Output is correct
62 Correct 2366 ms 210704 KB Output is correct
63 Correct 2723 ms 222732 KB Output is correct
64 Correct 3859 ms 214788 KB Output is correct
65 Correct 230 ms 47160 KB Output is correct
66 Correct 290 ms 47208 KB Output is correct
67 Correct 394 ms 48228 KB Output is correct
68 Correct 311 ms 48296 KB Output is correct
69 Correct 480 ms 49464 KB Output is correct
70 Correct 1 ms 468 KB Output is correct
71 Correct 661 ms 52064 KB Output is correct
72 Correct 396 ms 45616 KB Output is correct
73 Correct 479 ms 48720 KB Output is correct
74 Correct 611 ms 45632 KB Output is correct
75 Correct 1222 ms 223268 KB Output is correct
76 Correct 1537 ms 223568 KB Output is correct
77 Correct 2028 ms 225860 KB Output is correct
78 Correct 1615 ms 226040 KB Output is correct
79 Correct 4307 ms 248564 KB Output is correct
80 Correct 2353 ms 212412 KB Output is correct
81 Correct 2943 ms 222520 KB Output is correct
82 Correct 4037 ms 216112 KB Output is correct
83 Correct 3925 ms 232384 KB Output is correct