Submission #1038759

# Submission time Handle Problem Language Result Execution time Memory
1038759 2024-07-30T07:19:04 Z ibm2006 Two Dishes (JOI19_dishes) C++17
74 / 100
5493 ms 299460 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll inf=1e18;
ll n,m,i,j,k,l,r,x,y,z,w,s,t,a[1100000],b[1100000],seg[2200000],lazy[2200000],c[1100000],d[1100000],cost[1100000],add_cost[1100000],dp[1100000];
ll sum1[1100000],range[1100000],sum2[1100000];
vector<ll> del_list[1100000];
set<pair<ll,ll>> chain;
pair<ll,ll> p,q;
pair<ll,ll> find_chain(ll x)
{
    pair<ll,ll> p=*(--chain.lower_bound(make_pair(x,inf)));
    return p;
}
void propagate(ll x,ll y,ll z)
{
    if(z<1048576)
    {
        lazy[z*2]+=lazy[z];
        lazy[z*2+1]+=lazy[z];
    }
    seg[z]+=lazy[z];
    lazy[z]=0;
}
void f(ll x,ll y,ll z,ll w)
{
    propagate(x,y,z);
    if(y<l||x>r)
        return;
    if(l<=x&&y<=r)
    {
        lazy[z]+=w;
        propagate(x,y,z);
        return;
    }
    f(x,(x+y)/2,z*2,w);
    f((x+y)/2+1,y,z*2+1,w);
    seg[z]=max(seg[z*2],seg[z*2+1]);
}
ll g(ll x,ll y,ll z)
{
    propagate(x,y,z);
    if(y<l||x>r)
    {
        return -inf;
    }
    if(l<=x&&y<=r)
    {
        return seg[z];
    }
    return max(g(x,(x+y)/2,z*2),g((x+y)/2+1,y,z*2+1));
}
void add(ll x,ll y,ll z)
{
    l=x+1;
    r=y+1;
    f(1,1048576,1,z);
}
ll get_val(ll x)
{
    l=x+1;
    r=x+1;
    return g(1,1048576,1);
}
void reconstruct_chain(ll x)
{
    pair<ll,ll> p=find_chain(x);
    while(chain.upper_bound(p)!=chain.end())
    {
        pair<ll,ll> q=(*chain.upper_bound(p));
        y=get_val(p.second);
        z=get_val(q.first);
        //printf("(%lld,%lld,%lld,%lld)\n",p.first,p.second,q.first,q.second);
        if(z<=y+cost[p.second])
        {
            add(q.first,q.second,y+cost[p.second]-z);
            chain.erase(p);
            chain.erase(q);
            chain.insert({p.first,q.second});
            p.second=q.second;
        }
        else
            return;
    }
}
void show()
{
    return;
    ll i;
    for(i=0;i<=m;i++)
        printf("%lld ",get_val(i));
    printf("\n");
}
int main()
{
    scanf("%lld %lld",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%lld %lld %lld",&a[i],&c[i],&add_cost[i]);
        sum1[i]=sum1[i-1]+a[i];
    }
    for(i=1;i<=m;i++)
    {
        scanf("%lld %lld %lld",&b[i],&d[i],&cost[i-1]);
        sum2[i]=sum2[i-1]+b[i];
    }
    for(i=1;i<=n;i++)
    {
        range[i]=upper_bound(sum2,sum2+m+1,c[i]-sum1[i])-sum2-1;
        //printf("(%lld) ",range[i]);
    }
    //printf("\n");
    for(i=1;i<=m;i++)
    {
        x=upper_bound(sum1,sum1+n+1,d[i]-sum2[i])-sum1;
        del_list[x].push_back(i-1);
        //printf("(%lld)",x);
    }
    //printf("\n");
    for(auto xx:del_list[0])
    {
        cost[xx]=0;
    }
    for(i=1;i<=m;i++)
    {
        dp[i]=dp[i-1]+cost[i-1];
    }
    for(i=0;i<=m;i++)
    {
        add(i,i,dp[i]);
    }
    /*for(i=0;i<=m;i++)
    {
        printf("(%lld)",cost[i]);
    }
    printf("\n");
    */chain.insert({0,m});
    for(i=1;i<=n;i++)
    {show();
        for(auto xx:del_list[i])
        {
            //printf("{%lld}\n",xx);
            if(cost[xx]>0)
            {
                p=find_chain(xx);
            chain.erase(p);
            chain.insert({p.first,xx});
            if(xx+1<=p.second)
            chain.insert({xx+1,p.second});
            cost[xx]=0;
            }
            /*else
            {
                p=find_chain(xx);
                add(xx+1,p.second,-cost[xx]);
                cost[xx]=0;
            reconstruct_chain(xx);
            }*/
        }
        x=range[i];
        p=find_chain(x);
        if(x==-1)
            continue;
        if(add_cost[i]>0)
        {
            add(0,p.second,add_cost[i]);
            //printf("[%lld,%lld]\n",x,cost[x]);
        reconstruct_chain(x);
        }
        else
        {
            chain.erase(p);
            chain.insert({p.first,x});
            if(x+1<=p.second)
            chain.insert({x+1,p.second});
            add(0,x,add_cost[i]);
            reconstruct_chain(x);
        }
        for(auto xx:del_list[i])
        {
            //printf("{%lld}\n",xx);
            if(cost[xx]>0)
            {
            /*    p=find_chain(xx);
            chain.erase(p);
            chain.insert({p.first,xx});
            if(xx+1<=p.second)
            chain.insert({xx+1,p.second});
            cost[xx]=0;
            */}
            else
            {
                p=find_chain(xx);
                add(xx+1,p.second,-cost[xx]);
                cost[xx]=0;
            reconstruct_chain(xx);
            }
        }
    }
    s=-inf;
    show();
    for(i=m;i<=m;i++)
    {
        s=max(s,get_val(i));
    }
    printf("%lld",s);
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |     scanf("%lld %lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
dishes.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         scanf("%lld %lld %lld",&a[i],&c[i],&add_cost[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:104:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         scanf("%lld %lld %lld",&b[i],&d[i],&cost[i-1]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 429 ms 77012 KB Output is correct
2 Correct 413 ms 65708 KB Output is correct
3 Correct 214 ms 63240 KB Output is correct
4 Correct 412 ms 73520 KB Output is correct
5 Correct 10 ms 26460 KB Output is correct
6 Correct 451 ms 64168 KB Output is correct
7 Correct 99 ms 48912 KB Output is correct
8 Correct 99 ms 41044 KB Output is correct
9 Correct 184 ms 64192 KB Output is correct
10 Correct 535 ms 62032 KB Output is correct
11 Correct 167 ms 57792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 26460 KB Output is correct
2 Correct 11 ms 26492 KB Output is correct
3 Correct 10 ms 26460 KB Output is correct
4 Correct 10 ms 26492 KB Output is correct
5 Correct 10 ms 26456 KB Output is correct
6 Correct 10 ms 26460 KB Output is correct
7 Correct 11 ms 26456 KB Output is correct
8 Correct 11 ms 26488 KB Output is correct
9 Correct 11 ms 26460 KB Output is correct
10 Correct 11 ms 26460 KB Output is correct
11 Correct 11 ms 26356 KB Output is correct
12 Correct 11 ms 26456 KB Output is correct
13 Correct 11 ms 26456 KB Output is correct
14 Correct 10 ms 26460 KB Output is correct
15 Correct 11 ms 26460 KB Output is correct
16 Correct 10 ms 26460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 26460 KB Output is correct
2 Correct 11 ms 26492 KB Output is correct
3 Correct 10 ms 26460 KB Output is correct
4 Correct 10 ms 26492 KB Output is correct
5 Correct 10 ms 26456 KB Output is correct
6 Correct 10 ms 26460 KB Output is correct
7 Correct 11 ms 26456 KB Output is correct
8 Correct 11 ms 26488 KB Output is correct
9 Correct 11 ms 26460 KB Output is correct
10 Correct 11 ms 26460 KB Output is correct
11 Correct 11 ms 26356 KB Output is correct
12 Correct 11 ms 26456 KB Output is correct
13 Correct 11 ms 26456 KB Output is correct
14 Correct 10 ms 26460 KB Output is correct
15 Correct 11 ms 26460 KB Output is correct
16 Correct 10 ms 26460 KB Output is correct
17 Correct 14 ms 26968 KB Output is correct
18 Correct 14 ms 26784 KB Output is correct
19 Correct 17 ms 26716 KB Output is correct
20 Correct 13 ms 26716 KB Output is correct
21 Correct 15 ms 26716 KB Output is correct
22 Correct 23 ms 26536 KB Output is correct
23 Correct 17 ms 26716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 26460 KB Output is correct
2 Correct 11 ms 26492 KB Output is correct
3 Correct 10 ms 26460 KB Output is correct
4 Correct 10 ms 26492 KB Output is correct
5 Correct 10 ms 26456 KB Output is correct
6 Correct 10 ms 26460 KB Output is correct
7 Correct 11 ms 26456 KB Output is correct
8 Correct 11 ms 26488 KB Output is correct
9 Correct 11 ms 26460 KB Output is correct
10 Correct 11 ms 26460 KB Output is correct
11 Correct 11 ms 26356 KB Output is correct
12 Correct 11 ms 26456 KB Output is correct
13 Correct 11 ms 26456 KB Output is correct
14 Correct 10 ms 26460 KB Output is correct
15 Correct 11 ms 26460 KB Output is correct
16 Correct 10 ms 26460 KB Output is correct
17 Correct 14 ms 26968 KB Output is correct
18 Correct 14 ms 26784 KB Output is correct
19 Correct 17 ms 26716 KB Output is correct
20 Correct 13 ms 26716 KB Output is correct
21 Correct 15 ms 26716 KB Output is correct
22 Correct 23 ms 26536 KB Output is correct
23 Correct 17 ms 26716 KB Output is correct
24 Correct 186 ms 60664 KB Output is correct
25 Correct 287 ms 72892 KB Output is correct
26 Correct 177 ms 60500 KB Output is correct
27 Correct 384 ms 77652 KB Output is correct
28 Correct 327 ms 61640 KB Output is correct
29 Correct 175 ms 61232 KB Output is correct
30 Correct 752 ms 63316 KB Output is correct
31 Correct 228 ms 53348 KB Output is correct
32 Correct 104 ms 39388 KB Output is correct
33 Correct 480 ms 61892 KB Output is correct
34 Correct 641 ms 66756 KB Output is correct
35 Correct 893 ms 56896 KB Output is correct
36 Correct 905 ms 56860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 26460 KB Output is correct
2 Correct 11 ms 26492 KB Output is correct
3 Correct 10 ms 26460 KB Output is correct
4 Correct 10 ms 26492 KB Output is correct
5 Correct 10 ms 26456 KB Output is correct
6 Correct 10 ms 26460 KB Output is correct
7 Correct 11 ms 26456 KB Output is correct
8 Correct 11 ms 26488 KB Output is correct
9 Correct 11 ms 26460 KB Output is correct
10 Correct 11 ms 26460 KB Output is correct
11 Correct 11 ms 26356 KB Output is correct
12 Correct 11 ms 26456 KB Output is correct
13 Correct 11 ms 26456 KB Output is correct
14 Correct 10 ms 26460 KB Output is correct
15 Correct 11 ms 26460 KB Output is correct
16 Correct 10 ms 26460 KB Output is correct
17 Correct 14 ms 26968 KB Output is correct
18 Correct 14 ms 26784 KB Output is correct
19 Correct 17 ms 26716 KB Output is correct
20 Correct 13 ms 26716 KB Output is correct
21 Correct 15 ms 26716 KB Output is correct
22 Correct 23 ms 26536 KB Output is correct
23 Correct 17 ms 26716 KB Output is correct
24 Correct 186 ms 60664 KB Output is correct
25 Correct 287 ms 72892 KB Output is correct
26 Correct 177 ms 60500 KB Output is correct
27 Correct 384 ms 77652 KB Output is correct
28 Correct 327 ms 61640 KB Output is correct
29 Correct 175 ms 61232 KB Output is correct
30 Correct 752 ms 63316 KB Output is correct
31 Correct 228 ms 53348 KB Output is correct
32 Correct 104 ms 39388 KB Output is correct
33 Correct 480 ms 61892 KB Output is correct
34 Correct 641 ms 66756 KB Output is correct
35 Correct 893 ms 56896 KB Output is correct
36 Correct 905 ms 56860 KB Output is correct
37 Correct 215 ms 63548 KB Output is correct
38 Correct 442 ms 80740 KB Output is correct
39 Correct 827 ms 77992 KB Output is correct
40 Correct 587 ms 65500 KB Output is correct
41 Correct 11 ms 26460 KB Output is correct
42 Correct 952 ms 66208 KB Output is correct
43 Correct 507 ms 64580 KB Output is correct
44 Correct 682 ms 69416 KB Output is correct
45 Correct 916 ms 59988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 26460 KB Output is correct
2 Correct 11 ms 26492 KB Output is correct
3 Correct 10 ms 26460 KB Output is correct
4 Correct 10 ms 26492 KB Output is correct
5 Correct 10 ms 26456 KB Output is correct
6 Correct 10 ms 26460 KB Output is correct
7 Correct 11 ms 26456 KB Output is correct
8 Correct 11 ms 26488 KB Output is correct
9 Correct 11 ms 26460 KB Output is correct
10 Correct 11 ms 26460 KB Output is correct
11 Correct 11 ms 26356 KB Output is correct
12 Correct 11 ms 26456 KB Output is correct
13 Correct 11 ms 26456 KB Output is correct
14 Correct 10 ms 26460 KB Output is correct
15 Correct 11 ms 26460 KB Output is correct
16 Correct 10 ms 26460 KB Output is correct
17 Correct 14 ms 26968 KB Output is correct
18 Correct 14 ms 26784 KB Output is correct
19 Correct 17 ms 26716 KB Output is correct
20 Correct 13 ms 26716 KB Output is correct
21 Correct 15 ms 26716 KB Output is correct
22 Correct 23 ms 26536 KB Output is correct
23 Correct 17 ms 26716 KB Output is correct
24 Correct 186 ms 60664 KB Output is correct
25 Correct 287 ms 72892 KB Output is correct
26 Correct 177 ms 60500 KB Output is correct
27 Correct 384 ms 77652 KB Output is correct
28 Correct 327 ms 61640 KB Output is correct
29 Correct 175 ms 61232 KB Output is correct
30 Correct 752 ms 63316 KB Output is correct
31 Correct 228 ms 53348 KB Output is correct
32 Correct 104 ms 39388 KB Output is correct
33 Correct 480 ms 61892 KB Output is correct
34 Correct 641 ms 66756 KB Output is correct
35 Correct 893 ms 56896 KB Output is correct
36 Correct 905 ms 56860 KB Output is correct
37 Correct 215 ms 63548 KB Output is correct
38 Correct 442 ms 80740 KB Output is correct
39 Correct 827 ms 77992 KB Output is correct
40 Correct 587 ms 65500 KB Output is correct
41 Correct 11 ms 26460 KB Output is correct
42 Correct 952 ms 66208 KB Output is correct
43 Correct 507 ms 64580 KB Output is correct
44 Correct 682 ms 69416 KB Output is correct
45 Correct 916 ms 59988 KB Output is correct
46 Correct 1039 ms 213836 KB Output is correct
47 Correct 2125 ms 299460 KB Output is correct
48 Correct 3794 ms 285928 KB Output is correct
49 Correct 2844 ms 223388 KB Output is correct
50 Correct 5385 ms 227124 KB Output is correct
51 Correct 2618 ms 216284 KB Output is correct
52 Correct 3815 ms 234760 KB Output is correct
53 Correct 5493 ms 195432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 429 ms 77012 KB Output is correct
2 Correct 413 ms 65708 KB Output is correct
3 Correct 214 ms 63240 KB Output is correct
4 Correct 412 ms 73520 KB Output is correct
5 Correct 10 ms 26460 KB Output is correct
6 Correct 451 ms 64168 KB Output is correct
7 Correct 99 ms 48912 KB Output is correct
8 Correct 99 ms 41044 KB Output is correct
9 Correct 184 ms 64192 KB Output is correct
10 Correct 535 ms 62032 KB Output is correct
11 Correct 167 ms 57792 KB Output is correct
12 Correct 10 ms 26460 KB Output is correct
13 Correct 11 ms 26492 KB Output is correct
14 Correct 10 ms 26460 KB Output is correct
15 Correct 10 ms 26492 KB Output is correct
16 Correct 10 ms 26456 KB Output is correct
17 Correct 10 ms 26460 KB Output is correct
18 Correct 11 ms 26456 KB Output is correct
19 Correct 11 ms 26488 KB Output is correct
20 Correct 11 ms 26460 KB Output is correct
21 Correct 11 ms 26460 KB Output is correct
22 Correct 11 ms 26356 KB Output is correct
23 Correct 11 ms 26456 KB Output is correct
24 Correct 11 ms 26456 KB Output is correct
25 Correct 10 ms 26460 KB Output is correct
26 Correct 11 ms 26460 KB Output is correct
27 Correct 10 ms 26460 KB Output is correct
28 Correct 14 ms 26968 KB Output is correct
29 Correct 14 ms 26784 KB Output is correct
30 Correct 17 ms 26716 KB Output is correct
31 Correct 13 ms 26716 KB Output is correct
32 Correct 15 ms 26716 KB Output is correct
33 Correct 23 ms 26536 KB Output is correct
34 Correct 17 ms 26716 KB Output is correct
35 Correct 186 ms 60664 KB Output is correct
36 Correct 287 ms 72892 KB Output is correct
37 Correct 177 ms 60500 KB Output is correct
38 Correct 384 ms 77652 KB Output is correct
39 Correct 327 ms 61640 KB Output is correct
40 Correct 175 ms 61232 KB Output is correct
41 Correct 752 ms 63316 KB Output is correct
42 Correct 228 ms 53348 KB Output is correct
43 Correct 104 ms 39388 KB Output is correct
44 Correct 480 ms 61892 KB Output is correct
45 Correct 641 ms 66756 KB Output is correct
46 Correct 893 ms 56896 KB Output is correct
47 Correct 905 ms 56860 KB Output is correct
48 Correct 215 ms 63548 KB Output is correct
49 Correct 442 ms 80740 KB Output is correct
50 Correct 827 ms 77992 KB Output is correct
51 Correct 587 ms 65500 KB Output is correct
52 Correct 11 ms 26460 KB Output is correct
53 Correct 952 ms 66208 KB Output is correct
54 Correct 507 ms 64580 KB Output is correct
55 Correct 682 ms 69416 KB Output is correct
56 Correct 916 ms 59988 KB Output is correct
57 Correct 491 ms 76548 KB Output is correct
58 Incorrect 257 ms 68588 KB Output isn't correct
59 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 429 ms 77012 KB Output is correct
2 Correct 413 ms 65708 KB Output is correct
3 Correct 214 ms 63240 KB Output is correct
4 Correct 412 ms 73520 KB Output is correct
5 Correct 10 ms 26460 KB Output is correct
6 Correct 451 ms 64168 KB Output is correct
7 Correct 99 ms 48912 KB Output is correct
8 Correct 99 ms 41044 KB Output is correct
9 Correct 184 ms 64192 KB Output is correct
10 Correct 535 ms 62032 KB Output is correct
11 Correct 167 ms 57792 KB Output is correct
12 Correct 10 ms 26460 KB Output is correct
13 Correct 11 ms 26492 KB Output is correct
14 Correct 10 ms 26460 KB Output is correct
15 Correct 10 ms 26492 KB Output is correct
16 Correct 10 ms 26456 KB Output is correct
17 Correct 10 ms 26460 KB Output is correct
18 Correct 11 ms 26456 KB Output is correct
19 Correct 11 ms 26488 KB Output is correct
20 Correct 11 ms 26460 KB Output is correct
21 Correct 11 ms 26460 KB Output is correct
22 Correct 11 ms 26356 KB Output is correct
23 Correct 11 ms 26456 KB Output is correct
24 Correct 11 ms 26456 KB Output is correct
25 Correct 10 ms 26460 KB Output is correct
26 Correct 11 ms 26460 KB Output is correct
27 Correct 10 ms 26460 KB Output is correct
28 Correct 14 ms 26968 KB Output is correct
29 Correct 14 ms 26784 KB Output is correct
30 Correct 17 ms 26716 KB Output is correct
31 Correct 13 ms 26716 KB Output is correct
32 Correct 15 ms 26716 KB Output is correct
33 Correct 23 ms 26536 KB Output is correct
34 Correct 17 ms 26716 KB Output is correct
35 Correct 186 ms 60664 KB Output is correct
36 Correct 287 ms 72892 KB Output is correct
37 Correct 177 ms 60500 KB Output is correct
38 Correct 384 ms 77652 KB Output is correct
39 Correct 327 ms 61640 KB Output is correct
40 Correct 175 ms 61232 KB Output is correct
41 Correct 752 ms 63316 KB Output is correct
42 Correct 228 ms 53348 KB Output is correct
43 Correct 104 ms 39388 KB Output is correct
44 Correct 480 ms 61892 KB Output is correct
45 Correct 641 ms 66756 KB Output is correct
46 Correct 893 ms 56896 KB Output is correct
47 Correct 905 ms 56860 KB Output is correct
48 Correct 215 ms 63548 KB Output is correct
49 Correct 442 ms 80740 KB Output is correct
50 Correct 827 ms 77992 KB Output is correct
51 Correct 587 ms 65500 KB Output is correct
52 Correct 11 ms 26460 KB Output is correct
53 Correct 952 ms 66208 KB Output is correct
54 Correct 507 ms 64580 KB Output is correct
55 Correct 682 ms 69416 KB Output is correct
56 Correct 916 ms 59988 KB Output is correct
57 Correct 1039 ms 213836 KB Output is correct
58 Correct 2125 ms 299460 KB Output is correct
59 Correct 3794 ms 285928 KB Output is correct
60 Correct 2844 ms 223388 KB Output is correct
61 Correct 5385 ms 227124 KB Output is correct
62 Correct 2618 ms 216284 KB Output is correct
63 Correct 3815 ms 234760 KB Output is correct
64 Correct 5493 ms 195432 KB Output is correct
65 Correct 491 ms 76548 KB Output is correct
66 Incorrect 257 ms 68588 KB Output isn't correct
67 Halted 0 ms 0 KB -