Submission #170680

# Submission time Handle Problem Language Result Execution time Memory
170680 2019-12-26T04:19:55 Z puppies_and_rainbows Two Dishes (JOI19_dishes) C++14
100 / 100
6209 ms 272368 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int inf=100000000000000000;
int it[4100000];
pair<int, int> lazy[4100000];

pair<int, int> merge(pair<int, int> u, pair<int, int> v)
{
    return {u.first+v.first, max(u.second, v.second+u.first)};
}

void down(int id, int l, int r)
{
    it[id]=max(it[id]+lazy[id].first, lazy[id].second);
    if(true)
    {
        lazy[id*2]=merge(lazy[id], lazy[id*2]);
        lazy[id*2+1]=merge(lazy[id], lazy[id*2+1]);
    }
    lazy[id]={0, -inf};
}

void update(int id, int l, int r, int u, int v, pair<int, int> val)
{
    down(id, l, r);
    if(l>v||r<u)
    {
        return;
    }
    if(l>=u&&r<=v)
    {
        lazy[id]=val;
        down(id, l, r);
        return;
    }
    int mid=(l+r)/2;
    update(id*2, l, mid, u, v, val);
    update(id*2+1, mid+1, r, u, v, val);
    it[id]=max(it[id*2], it[id*2+1]);
}

int get(int id, int l, int r, int pos)
{
    down(id, l, r);
    if(l==r) return it[id];
    int mid=(l+r)/2;
    if(pos<=mid) return get(id*2, l, mid, pos);
    else return get(id*2+1, mid+1, r, pos);
}

int a[1000005], s[1000005], p[1000005];
int b[1000005], t[1000005], q[1000005];
int n, m;
vector<pair<int, int> > events[1000005];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //update(1,0,5,1,5,{1,0});
    //update(1,0,5,1,5,{1,0});
    //cout<<get(1,0,5,4);
    //return 0;
    //freopen("dishes.inp", "r", stdin);
    //freopen("dishes.out", "w", stdout);
    cin>>n>>m;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i]>>s[i]>>p[i];
        a[i]+=a[i-1];
    }
    for(int i=1; i<=m; i++)
    {
        cin>>b[i]>>t[i]>>q[i];
        b[i]+=b[i-1];
    }
    int dora=0;
    for(int i=1; i<=n; i++)
    {
        int ok=upper_bound(b, b+m+1, s[i]-a[i])-b;
        if(ok>=1)
        {
            events[ok-1].push_back({i, p[i]});
        }
    }
    for(int i=1; i<=m; i++)
    {
        dora+=q[i]; q[i]=-q[i];
        int ok=upper_bound(a, a+n+1, t[i]-b[i])-a;
        if(ok<=n)
        {
            events[i-1].push_back({ok, q[i]});
        }
    }
    fill(lazy, lazy+n*4+5, (pair<int, int>){0, -inf});
    for(int p=0; p<m; p++)
    {
        for(auto i:events[p])
        {
            //cout<<i.first<<" "<<i.second<<endl;
            update(1, 0, n, i.first, n, {i.second, -inf});
        }
        for(auto i:events[p])
        {
            if(i.first)
            {
                //cout<<get(1, 0, n, i.first-1)<<endl;
                update(1, 0, n, i.first, n, {0, get(1, 0, n, i.first-1)});
            }
        }
        for(int i=0; i<=n; i++)
        {
            //cout<<get(1, 0, n, i)<<" ";
        }
        //cout<<endl;
    }
    for(auto i:events[m])
    {
        update(1, 0, n, i.first, n, {i.second, -inf});
    }
    cout<<dora+get(1, 0, n, n);
}
# Verdict Execution time Memory Grader output
1 Correct 669 ms 62488 KB Output is correct
2 Correct 662 ms 76732 KB Output is correct
3 Correct 362 ms 70400 KB Output is correct
4 Correct 540 ms 71288 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 613 ms 75092 KB Output is correct
7 Correct 135 ms 36060 KB Output is correct
8 Correct 245 ms 59372 KB Output is correct
9 Correct 371 ms 71592 KB Output is correct
10 Correct 646 ms 70840 KB Output is correct
11 Correct 288 ms 64864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 23800 KB Output is correct
2 Correct 29 ms 23928 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 23 ms 23900 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 23 ms 23928 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 23 ms 23932 KB Output is correct
14 Correct 24 ms 23900 KB Output is correct
15 Correct 23 ms 23928 KB Output is correct
16 Correct 23 ms 23844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 23800 KB Output is correct
2 Correct 29 ms 23928 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 23 ms 23900 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 23 ms 23928 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 23 ms 23932 KB Output is correct
14 Correct 24 ms 23900 KB Output is correct
15 Correct 23 ms 23928 KB Output is correct
16 Correct 23 ms 23844 KB Output is correct
17 Correct 27 ms 24312 KB Output is correct
18 Correct 27 ms 24324 KB Output is correct
19 Correct 29 ms 24312 KB Output is correct
20 Correct 27 ms 24312 KB Output is correct
21 Correct 28 ms 24312 KB Output is correct
22 Correct 28 ms 24312 KB Output is correct
23 Correct 28 ms 24312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 23800 KB Output is correct
2 Correct 29 ms 23928 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 23 ms 23900 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 23 ms 23928 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 23 ms 23932 KB Output is correct
14 Correct 24 ms 23900 KB Output is correct
15 Correct 23 ms 23928 KB Output is correct
16 Correct 23 ms 23844 KB Output is correct
17 Correct 27 ms 24312 KB Output is correct
18 Correct 27 ms 24324 KB Output is correct
19 Correct 29 ms 24312 KB Output is correct
20 Correct 27 ms 24312 KB Output is correct
21 Correct 28 ms 24312 KB Output is correct
22 Correct 28 ms 24312 KB Output is correct
23 Correct 28 ms 24312 KB Output is correct
24 Correct 470 ms 70688 KB Output is correct
25 Correct 565 ms 72340 KB Output is correct
26 Correct 478 ms 73580 KB Output is correct
27 Correct 507 ms 72296 KB Output is correct
28 Correct 491 ms 70208 KB Output is correct
29 Correct 335 ms 68456 KB Output is correct
30 Correct 978 ms 74584 KB Output is correct
31 Correct 132 ms 37112 KB Output is correct
32 Correct 294 ms 57836 KB Output is correct
33 Correct 618 ms 72056 KB Output is correct
34 Correct 872 ms 73448 KB Output is correct
35 Correct 927 ms 68216 KB Output is correct
36 Correct 914 ms 68172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 23800 KB Output is correct
2 Correct 29 ms 23928 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 23 ms 23900 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 23 ms 23928 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 23 ms 23932 KB Output is correct
14 Correct 24 ms 23900 KB Output is correct
15 Correct 23 ms 23928 KB Output is correct
16 Correct 23 ms 23844 KB Output is correct
17 Correct 27 ms 24312 KB Output is correct
18 Correct 27 ms 24324 KB Output is correct
19 Correct 29 ms 24312 KB Output is correct
20 Correct 27 ms 24312 KB Output is correct
21 Correct 28 ms 24312 KB Output is correct
22 Correct 28 ms 24312 KB Output is correct
23 Correct 28 ms 24312 KB Output is correct
24 Correct 470 ms 70688 KB Output is correct
25 Correct 565 ms 72340 KB Output is correct
26 Correct 478 ms 73580 KB Output is correct
27 Correct 507 ms 72296 KB Output is correct
28 Correct 491 ms 70208 KB Output is correct
29 Correct 335 ms 68456 KB Output is correct
30 Correct 978 ms 74584 KB Output is correct
31 Correct 132 ms 37112 KB Output is correct
32 Correct 294 ms 57836 KB Output is correct
33 Correct 618 ms 72056 KB Output is correct
34 Correct 872 ms 73448 KB Output is correct
35 Correct 927 ms 68216 KB Output is correct
36 Correct 914 ms 68172 KB Output is correct
37 Correct 508 ms 76680 KB Output is correct
38 Correct 534 ms 75380 KB Output is correct
39 Correct 702 ms 74488 KB Output is correct
40 Correct 693 ms 74360 KB Output is correct
41 Correct 24 ms 23800 KB Output is correct
42 Correct 1004 ms 77724 KB Output is correct
43 Correct 651 ms 75180 KB Output is correct
44 Correct 829 ms 76268 KB Output is correct
45 Correct 937 ms 71316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 23800 KB Output is correct
2 Correct 29 ms 23928 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 23 ms 23900 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 23 ms 23928 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 23 ms 23932 KB Output is correct
14 Correct 24 ms 23900 KB Output is correct
15 Correct 23 ms 23928 KB Output is correct
16 Correct 23 ms 23844 KB Output is correct
17 Correct 27 ms 24312 KB Output is correct
18 Correct 27 ms 24324 KB Output is correct
19 Correct 29 ms 24312 KB Output is correct
20 Correct 27 ms 24312 KB Output is correct
21 Correct 28 ms 24312 KB Output is correct
22 Correct 28 ms 24312 KB Output is correct
23 Correct 28 ms 24312 KB Output is correct
24 Correct 470 ms 70688 KB Output is correct
25 Correct 565 ms 72340 KB Output is correct
26 Correct 478 ms 73580 KB Output is correct
27 Correct 507 ms 72296 KB Output is correct
28 Correct 491 ms 70208 KB Output is correct
29 Correct 335 ms 68456 KB Output is correct
30 Correct 978 ms 74584 KB Output is correct
31 Correct 132 ms 37112 KB Output is correct
32 Correct 294 ms 57836 KB Output is correct
33 Correct 618 ms 72056 KB Output is correct
34 Correct 872 ms 73448 KB Output is correct
35 Correct 927 ms 68216 KB Output is correct
36 Correct 914 ms 68172 KB Output is correct
37 Correct 508 ms 76680 KB Output is correct
38 Correct 534 ms 75380 KB Output is correct
39 Correct 702 ms 74488 KB Output is correct
40 Correct 693 ms 74360 KB Output is correct
41 Correct 24 ms 23800 KB Output is correct
42 Correct 1004 ms 77724 KB Output is correct
43 Correct 651 ms 75180 KB Output is correct
44 Correct 829 ms 76268 KB Output is correct
45 Correct 937 ms 71316 KB Output is correct
46 Correct 2630 ms 261720 KB Output is correct
47 Correct 2783 ms 260616 KB Output is correct
48 Correct 3724 ms 254156 KB Output is correct
49 Correct 3645 ms 254812 KB Output is correct
50 Correct 6209 ms 270080 KB Output is correct
51 Correct 3545 ms 255872 KB Output is correct
52 Correct 4609 ms 257196 KB Output is correct
53 Correct 5643 ms 239120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 669 ms 62488 KB Output is correct
2 Correct 662 ms 76732 KB Output is correct
3 Correct 362 ms 70400 KB Output is correct
4 Correct 540 ms 71288 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 613 ms 75092 KB Output is correct
7 Correct 135 ms 36060 KB Output is correct
8 Correct 245 ms 59372 KB Output is correct
9 Correct 371 ms 71592 KB Output is correct
10 Correct 646 ms 70840 KB Output is correct
11 Correct 288 ms 64864 KB Output is correct
12 Correct 28 ms 23800 KB Output is correct
13 Correct 29 ms 23928 KB Output is correct
14 Correct 23 ms 23928 KB Output is correct
15 Correct 23 ms 23900 KB Output is correct
16 Correct 23 ms 23928 KB Output is correct
17 Correct 23 ms 23928 KB Output is correct
18 Correct 24 ms 23800 KB Output is correct
19 Correct 23 ms 23928 KB Output is correct
20 Correct 23 ms 23928 KB Output is correct
21 Correct 23 ms 23928 KB Output is correct
22 Correct 23 ms 23928 KB Output is correct
23 Correct 23 ms 23928 KB Output is correct
24 Correct 23 ms 23932 KB Output is correct
25 Correct 24 ms 23900 KB Output is correct
26 Correct 23 ms 23928 KB Output is correct
27 Correct 23 ms 23844 KB Output is correct
28 Correct 27 ms 24312 KB Output is correct
29 Correct 27 ms 24324 KB Output is correct
30 Correct 29 ms 24312 KB Output is correct
31 Correct 27 ms 24312 KB Output is correct
32 Correct 28 ms 24312 KB Output is correct
33 Correct 28 ms 24312 KB Output is correct
34 Correct 28 ms 24312 KB Output is correct
35 Correct 470 ms 70688 KB Output is correct
36 Correct 565 ms 72340 KB Output is correct
37 Correct 478 ms 73580 KB Output is correct
38 Correct 507 ms 72296 KB Output is correct
39 Correct 491 ms 70208 KB Output is correct
40 Correct 335 ms 68456 KB Output is correct
41 Correct 978 ms 74584 KB Output is correct
42 Correct 132 ms 37112 KB Output is correct
43 Correct 294 ms 57836 KB Output is correct
44 Correct 618 ms 72056 KB Output is correct
45 Correct 872 ms 73448 KB Output is correct
46 Correct 927 ms 68216 KB Output is correct
47 Correct 914 ms 68172 KB Output is correct
48 Correct 508 ms 76680 KB Output is correct
49 Correct 534 ms 75380 KB Output is correct
50 Correct 702 ms 74488 KB Output is correct
51 Correct 693 ms 74360 KB Output is correct
52 Correct 24 ms 23800 KB Output is correct
53 Correct 1004 ms 77724 KB Output is correct
54 Correct 651 ms 75180 KB Output is correct
55 Correct 829 ms 76268 KB Output is correct
56 Correct 937 ms 71316 KB Output is correct
57 Correct 513 ms 77020 KB Output is correct
58 Correct 552 ms 75956 KB Output is correct
59 Correct 705 ms 75384 KB Output is correct
60 Correct 700 ms 75384 KB Output is correct
61 Correct 1000 ms 74744 KB Output is correct
62 Correct 23 ms 23928 KB Output is correct
63 Correct 1010 ms 77816 KB Output is correct
64 Correct 646 ms 75044 KB Output is correct
65 Correct 835 ms 76148 KB Output is correct
66 Correct 925 ms 71288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 669 ms 62488 KB Output is correct
2 Correct 662 ms 76732 KB Output is correct
3 Correct 362 ms 70400 KB Output is correct
4 Correct 540 ms 71288 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 613 ms 75092 KB Output is correct
7 Correct 135 ms 36060 KB Output is correct
8 Correct 245 ms 59372 KB Output is correct
9 Correct 371 ms 71592 KB Output is correct
10 Correct 646 ms 70840 KB Output is correct
11 Correct 288 ms 64864 KB Output is correct
12 Correct 28 ms 23800 KB Output is correct
13 Correct 29 ms 23928 KB Output is correct
14 Correct 23 ms 23928 KB Output is correct
15 Correct 23 ms 23900 KB Output is correct
16 Correct 23 ms 23928 KB Output is correct
17 Correct 23 ms 23928 KB Output is correct
18 Correct 24 ms 23800 KB Output is correct
19 Correct 23 ms 23928 KB Output is correct
20 Correct 23 ms 23928 KB Output is correct
21 Correct 23 ms 23928 KB Output is correct
22 Correct 23 ms 23928 KB Output is correct
23 Correct 23 ms 23928 KB Output is correct
24 Correct 23 ms 23932 KB Output is correct
25 Correct 24 ms 23900 KB Output is correct
26 Correct 23 ms 23928 KB Output is correct
27 Correct 23 ms 23844 KB Output is correct
28 Correct 27 ms 24312 KB Output is correct
29 Correct 27 ms 24324 KB Output is correct
30 Correct 29 ms 24312 KB Output is correct
31 Correct 27 ms 24312 KB Output is correct
32 Correct 28 ms 24312 KB Output is correct
33 Correct 28 ms 24312 KB Output is correct
34 Correct 28 ms 24312 KB Output is correct
35 Correct 470 ms 70688 KB Output is correct
36 Correct 565 ms 72340 KB Output is correct
37 Correct 478 ms 73580 KB Output is correct
38 Correct 507 ms 72296 KB Output is correct
39 Correct 491 ms 70208 KB Output is correct
40 Correct 335 ms 68456 KB Output is correct
41 Correct 978 ms 74584 KB Output is correct
42 Correct 132 ms 37112 KB Output is correct
43 Correct 294 ms 57836 KB Output is correct
44 Correct 618 ms 72056 KB Output is correct
45 Correct 872 ms 73448 KB Output is correct
46 Correct 927 ms 68216 KB Output is correct
47 Correct 914 ms 68172 KB Output is correct
48 Correct 508 ms 76680 KB Output is correct
49 Correct 534 ms 75380 KB Output is correct
50 Correct 702 ms 74488 KB Output is correct
51 Correct 693 ms 74360 KB Output is correct
52 Correct 24 ms 23800 KB Output is correct
53 Correct 1004 ms 77724 KB Output is correct
54 Correct 651 ms 75180 KB Output is correct
55 Correct 829 ms 76268 KB Output is correct
56 Correct 937 ms 71316 KB Output is correct
57 Correct 2630 ms 261720 KB Output is correct
58 Correct 2783 ms 260616 KB Output is correct
59 Correct 3724 ms 254156 KB Output is correct
60 Correct 3645 ms 254812 KB Output is correct
61 Correct 6209 ms 270080 KB Output is correct
62 Correct 3545 ms 255872 KB Output is correct
63 Correct 4609 ms 257196 KB Output is correct
64 Correct 5643 ms 239120 KB Output is correct
65 Correct 513 ms 77020 KB Output is correct
66 Correct 552 ms 75956 KB Output is correct
67 Correct 705 ms 75384 KB Output is correct
68 Correct 700 ms 75384 KB Output is correct
69 Correct 1000 ms 74744 KB Output is correct
70 Correct 23 ms 23928 KB Output is correct
71 Correct 1010 ms 77816 KB Output is correct
72 Correct 646 ms 75044 KB Output is correct
73 Correct 835 ms 76148 KB Output is correct
74 Correct 925 ms 71288 KB Output is correct
75 Correct 2630 ms 266524 KB Output is correct
76 Correct 2825 ms 261472 KB Output is correct
77 Correct 3691 ms 256416 KB Output is correct
78 Correct 3708 ms 256908 KB Output is correct
79 Correct 6124 ms 272368 KB Output is correct
80 Correct 3711 ms 255352 KB Output is correct
81 Correct 4733 ms 256232 KB Output is correct
82 Correct 5740 ms 239920 KB Output is correct
83 Correct 5694 ms 257984 KB Output is correct