Submission #1070145

# Submission time Handle Problem Language Result Execution time Memory
1070145 2024-08-22T11:53:59 Z heeew Two Dishes (JOI19_dishes) C++14
100 / 100
3276 ms 248144 KB
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;

const int MAX_N=1000010;
const lint INF=2.1e+15;

struct Seg
{
    lint sum;
    lint v,lazy;
    void setv(lint vp,lint lp)
    {
        v=max(v+lp,vp);
        lazy+=lp;
    }
};

int n,m;
lint t1[MAX_N],t2[MAX_N],c1[MAX_N],c2[MAX_N],s1[MAX_N],s2[MAX_N];
lint ts1[MAX_N],ts2[MAX_N],ci[MAX_N];
Seg seg[MAX_N<<2];
vint endp[MAX_N];

void update_lazy(int i)
{
    seg[i<<1].sum+=seg[i].sum;
    seg[i<<1|1].sum+=seg[i].sum;
    seg[i<<1].setv(seg[i].v,seg[i].lazy);
    seg[i<<1|1].setv(seg[i].v,seg[i].lazy);
    seg[i].sum=0;
    seg[i].v=-INF;
    seg[i].lazy=0;
}

void update_sum(int i,int s,int e,int l,int r,lint v)
{
    if(s>=r || e<=l)return;
    if(l<=s && e<=r)
    {
        seg[i].sum+=v;
        return;
    }
    update_lazy(i);
    update_sum(i<<1,s,(s+e)>>1,l,r,v);
    update_sum(i<<1|1,(s+e)>>1,e,l,r,v);
}

void update_(int i,int s,int e,int l,int r,lint add,lint cut)
{
    if(s>=r || e<=l)return;
    if(l<=s && e<=r)
    {
        seg[i].setv(cut,add);
        return;
    }
    update_lazy(i);
    update_(i<<1,s,(s+e)>>1,l,r,add,cut);
    update_(i<<1|1,(s+e)>>1,e,l,r,add,cut);
}

lint find_(int i,int s,int e,int x,int t)
{
    if(s>x || e<=x)return 0;
    if(s==x && x+1==e)return seg[i].v+seg[i].sum*t;
    update_lazy(i);
    return find_(i<<1,s,(s+e)>>1,x,t)+find_(i<<1|1,(s+e)>>1,e,x,t);
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> m;
    for(int i=1;i<=n;i++)
    {
        cin >> t1[i] >> c1[i] >> s1[i];
        ts1[i]=t1[i]+ts1[i-1];
    }
    for(int i=1;i<=m;i++)
    {
        cin >> t2[i] >> c2[i] >> s2[i];
        ts2[i]=t2[i]+ts2[i-1];
    }
    for(int i=1;i<=n;i++)
    {
        int p=upper_bound(ts2,ts2+m+1,c1[i]-ts1[i])-ts2;
        if(!p)continue;
        endp[p].push_back(i);
        update_sum(1,0,n+1,i,n+1,s1[i]);
    }
    for(int i=1;i<=m;i++)
        ci[i]=upper_bound(ts1,ts1+n+1,c2[i]-ts2[i])-ts1;
    for(int i=1;i<=m;i++)
    {
        vint cutted;
        lint cut=-INF;
        update_(1,0,n+1,0,ci[i],s2[i],cut);
        cutted.push_back(ci[i]);
        for(auto j : endp[i])
        {
            update_sum(1,0,n+1,j,n+1,-s1[j]);
            update_(1,0,n+1,j,n+1,s1[j],cut);
            cutted.push_back(j);
        }
        sort(cutted.begin(),cutted.end());
        for(auto p : cutted)
        {
            if(!p)continue;
            cut=find_(1,0,n+1,p-1,0);
            update_(1,0,n+1,p,n+1,0,cut);
        }
        cutted.clear();
    }
    cout << find_(1,0,n+1,n,1);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 331 ms 68480 KB Output is correct
2 Correct 312 ms 68436 KB Output is correct
3 Correct 166 ms 72776 KB Output is correct
4 Correct 257 ms 75904 KB Output is correct
5 Correct 6 ms 39512 KB Output is correct
6 Correct 289 ms 75024 KB Output is correct
7 Correct 62 ms 49488 KB Output is correct
8 Correct 106 ms 63540 KB Output is correct
9 Correct 171 ms 73220 KB Output is correct
10 Correct 335 ms 74972 KB Output is correct
11 Correct 137 ms 70052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 39512 KB Output is correct
2 Correct 6 ms 39644 KB Output is correct
3 Correct 5 ms 39516 KB Output is correct
4 Correct 5 ms 39516 KB Output is correct
5 Correct 7 ms 39512 KB Output is correct
6 Correct 7 ms 39516 KB Output is correct
7 Correct 6 ms 39600 KB Output is correct
8 Correct 6 ms 39516 KB Output is correct
9 Correct 7 ms 39516 KB Output is correct
10 Correct 5 ms 39516 KB Output is correct
11 Correct 6 ms 39516 KB Output is correct
12 Correct 9 ms 39640 KB Output is correct
13 Correct 6 ms 39516 KB Output is correct
14 Correct 8 ms 39532 KB Output is correct
15 Correct 9 ms 39596 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 39512 KB Output is correct
2 Correct 6 ms 39644 KB Output is correct
3 Correct 5 ms 39516 KB Output is correct
4 Correct 5 ms 39516 KB Output is correct
5 Correct 7 ms 39512 KB Output is correct
6 Correct 7 ms 39516 KB Output is correct
7 Correct 6 ms 39600 KB Output is correct
8 Correct 6 ms 39516 KB Output is correct
9 Correct 7 ms 39516 KB Output is correct
10 Correct 5 ms 39516 KB Output is correct
11 Correct 6 ms 39516 KB Output is correct
12 Correct 9 ms 39640 KB Output is correct
13 Correct 6 ms 39516 KB Output is correct
14 Correct 8 ms 39532 KB Output is correct
15 Correct 9 ms 39596 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39768 KB Output is correct
18 Correct 10 ms 39772 KB Output is correct
19 Correct 9 ms 39772 KB Output is correct
20 Correct 9 ms 39772 KB Output is correct
21 Correct 13 ms 39772 KB Output is correct
22 Correct 9 ms 39748 KB Output is correct
23 Correct 8 ms 39516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 39512 KB Output is correct
2 Correct 6 ms 39644 KB Output is correct
3 Correct 5 ms 39516 KB Output is correct
4 Correct 5 ms 39516 KB Output is correct
5 Correct 7 ms 39512 KB Output is correct
6 Correct 7 ms 39516 KB Output is correct
7 Correct 6 ms 39600 KB Output is correct
8 Correct 6 ms 39516 KB Output is correct
9 Correct 7 ms 39516 KB Output is correct
10 Correct 5 ms 39516 KB Output is correct
11 Correct 6 ms 39516 KB Output is correct
12 Correct 9 ms 39640 KB Output is correct
13 Correct 6 ms 39516 KB Output is correct
14 Correct 8 ms 39532 KB Output is correct
15 Correct 9 ms 39596 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39768 KB Output is correct
18 Correct 10 ms 39772 KB Output is correct
19 Correct 9 ms 39772 KB Output is correct
20 Correct 9 ms 39772 KB Output is correct
21 Correct 13 ms 39772 KB Output is correct
22 Correct 9 ms 39748 KB Output is correct
23 Correct 8 ms 39516 KB Output is correct
24 Correct 299 ms 72724 KB Output is correct
25 Correct 246 ms 70804 KB Output is correct
26 Correct 301 ms 76720 KB Output is correct
27 Correct 224 ms 70980 KB Output is correct
28 Correct 252 ms 72420 KB Output is correct
29 Correct 195 ms 71844 KB Output is correct
30 Correct 547 ms 74228 KB Output is correct
31 Correct 70 ms 48844 KB Output is correct
32 Correct 137 ms 63176 KB Output is correct
33 Correct 310 ms 72652 KB Output is correct
34 Correct 466 ms 72900 KB Output is correct
35 Correct 540 ms 71288 KB Output is correct
36 Correct 491 ms 71240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 39512 KB Output is correct
2 Correct 6 ms 39644 KB Output is correct
3 Correct 5 ms 39516 KB Output is correct
4 Correct 5 ms 39516 KB Output is correct
5 Correct 7 ms 39512 KB Output is correct
6 Correct 7 ms 39516 KB Output is correct
7 Correct 6 ms 39600 KB Output is correct
8 Correct 6 ms 39516 KB Output is correct
9 Correct 7 ms 39516 KB Output is correct
10 Correct 5 ms 39516 KB Output is correct
11 Correct 6 ms 39516 KB Output is correct
12 Correct 9 ms 39640 KB Output is correct
13 Correct 6 ms 39516 KB Output is correct
14 Correct 8 ms 39532 KB Output is correct
15 Correct 9 ms 39596 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39768 KB Output is correct
18 Correct 10 ms 39772 KB Output is correct
19 Correct 9 ms 39772 KB Output is correct
20 Correct 9 ms 39772 KB Output is correct
21 Correct 13 ms 39772 KB Output is correct
22 Correct 9 ms 39748 KB Output is correct
23 Correct 8 ms 39516 KB Output is correct
24 Correct 299 ms 72724 KB Output is correct
25 Correct 246 ms 70804 KB Output is correct
26 Correct 301 ms 76720 KB Output is correct
27 Correct 224 ms 70980 KB Output is correct
28 Correct 252 ms 72420 KB Output is correct
29 Correct 195 ms 71844 KB Output is correct
30 Correct 547 ms 74228 KB Output is correct
31 Correct 70 ms 48844 KB Output is correct
32 Correct 137 ms 63176 KB Output is correct
33 Correct 310 ms 72652 KB Output is correct
34 Correct 466 ms 72900 KB Output is correct
35 Correct 540 ms 71288 KB Output is correct
36 Correct 491 ms 71240 KB Output is correct
37 Correct 273 ms 78672 KB Output is correct
38 Correct 246 ms 72756 KB Output is correct
39 Correct 333 ms 76764 KB Output is correct
40 Correct 332 ms 77324 KB Output is correct
41 Correct 6 ms 39512 KB Output is correct
42 Correct 460 ms 75928 KB Output is correct
43 Correct 299 ms 74280 KB Output is correct
44 Correct 386 ms 74448 KB Output is correct
45 Correct 448 ms 72848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 39512 KB Output is correct
2 Correct 6 ms 39644 KB Output is correct
3 Correct 5 ms 39516 KB Output is correct
4 Correct 5 ms 39516 KB Output is correct
5 Correct 7 ms 39512 KB Output is correct
6 Correct 7 ms 39516 KB Output is correct
7 Correct 6 ms 39600 KB Output is correct
8 Correct 6 ms 39516 KB Output is correct
9 Correct 7 ms 39516 KB Output is correct
10 Correct 5 ms 39516 KB Output is correct
11 Correct 6 ms 39516 KB Output is correct
12 Correct 9 ms 39640 KB Output is correct
13 Correct 6 ms 39516 KB Output is correct
14 Correct 8 ms 39532 KB Output is correct
15 Correct 9 ms 39596 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39768 KB Output is correct
18 Correct 10 ms 39772 KB Output is correct
19 Correct 9 ms 39772 KB Output is correct
20 Correct 9 ms 39772 KB Output is correct
21 Correct 13 ms 39772 KB Output is correct
22 Correct 9 ms 39748 KB Output is correct
23 Correct 8 ms 39516 KB Output is correct
24 Correct 299 ms 72724 KB Output is correct
25 Correct 246 ms 70804 KB Output is correct
26 Correct 301 ms 76720 KB Output is correct
27 Correct 224 ms 70980 KB Output is correct
28 Correct 252 ms 72420 KB Output is correct
29 Correct 195 ms 71844 KB Output is correct
30 Correct 547 ms 74228 KB Output is correct
31 Correct 70 ms 48844 KB Output is correct
32 Correct 137 ms 63176 KB Output is correct
33 Correct 310 ms 72652 KB Output is correct
34 Correct 466 ms 72900 KB Output is correct
35 Correct 540 ms 71288 KB Output is correct
36 Correct 491 ms 71240 KB Output is correct
37 Correct 273 ms 78672 KB Output is correct
38 Correct 246 ms 72756 KB Output is correct
39 Correct 333 ms 76764 KB Output is correct
40 Correct 332 ms 77324 KB Output is correct
41 Correct 6 ms 39512 KB Output is correct
42 Correct 460 ms 75928 KB Output is correct
43 Correct 299 ms 74280 KB Output is correct
44 Correct 386 ms 74448 KB Output is correct
45 Correct 448 ms 72848 KB Output is correct
46 Correct 1433 ms 211856 KB Output is correct
47 Correct 1126 ms 182156 KB Output is correct
48 Correct 1781 ms 204884 KB Output is correct
49 Correct 1782 ms 204804 KB Output is correct
50 Correct 3015 ms 199844 KB Output is correct
51 Correct 1701 ms 190156 KB Output is correct
52 Correct 2242 ms 187844 KB Output is correct
53 Correct 2783 ms 184012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 331 ms 68480 KB Output is correct
2 Correct 312 ms 68436 KB Output is correct
3 Correct 166 ms 72776 KB Output is correct
4 Correct 257 ms 75904 KB Output is correct
5 Correct 6 ms 39512 KB Output is correct
6 Correct 289 ms 75024 KB Output is correct
7 Correct 62 ms 49488 KB Output is correct
8 Correct 106 ms 63540 KB Output is correct
9 Correct 171 ms 73220 KB Output is correct
10 Correct 335 ms 74972 KB Output is correct
11 Correct 137 ms 70052 KB Output is correct
12 Correct 5 ms 39512 KB Output is correct
13 Correct 6 ms 39644 KB Output is correct
14 Correct 5 ms 39516 KB Output is correct
15 Correct 5 ms 39516 KB Output is correct
16 Correct 7 ms 39512 KB Output is correct
17 Correct 7 ms 39516 KB Output is correct
18 Correct 6 ms 39600 KB Output is correct
19 Correct 6 ms 39516 KB Output is correct
20 Correct 7 ms 39516 KB Output is correct
21 Correct 5 ms 39516 KB Output is correct
22 Correct 6 ms 39516 KB Output is correct
23 Correct 9 ms 39640 KB Output is correct
24 Correct 6 ms 39516 KB Output is correct
25 Correct 8 ms 39532 KB Output is correct
26 Correct 9 ms 39596 KB Output is correct
27 Correct 8 ms 39516 KB Output is correct
28 Correct 9 ms 39768 KB Output is correct
29 Correct 10 ms 39772 KB Output is correct
30 Correct 9 ms 39772 KB Output is correct
31 Correct 9 ms 39772 KB Output is correct
32 Correct 13 ms 39772 KB Output is correct
33 Correct 9 ms 39748 KB Output is correct
34 Correct 8 ms 39516 KB Output is correct
35 Correct 299 ms 72724 KB Output is correct
36 Correct 246 ms 70804 KB Output is correct
37 Correct 301 ms 76720 KB Output is correct
38 Correct 224 ms 70980 KB Output is correct
39 Correct 252 ms 72420 KB Output is correct
40 Correct 195 ms 71844 KB Output is correct
41 Correct 547 ms 74228 KB Output is correct
42 Correct 70 ms 48844 KB Output is correct
43 Correct 137 ms 63176 KB Output is correct
44 Correct 310 ms 72652 KB Output is correct
45 Correct 466 ms 72900 KB Output is correct
46 Correct 540 ms 71288 KB Output is correct
47 Correct 491 ms 71240 KB Output is correct
48 Correct 273 ms 78672 KB Output is correct
49 Correct 246 ms 72756 KB Output is correct
50 Correct 333 ms 76764 KB Output is correct
51 Correct 332 ms 77324 KB Output is correct
52 Correct 6 ms 39512 KB Output is correct
53 Correct 460 ms 75928 KB Output is correct
54 Correct 299 ms 74280 KB Output is correct
55 Correct 386 ms 74448 KB Output is correct
56 Correct 448 ms 72848 KB Output is correct
57 Correct 273 ms 78352 KB Output is correct
58 Correct 207 ms 65232 KB Output is correct
59 Correct 322 ms 70996 KB Output is correct
60 Correct 333 ms 83028 KB Output is correct
61 Correct 466 ms 79700 KB Output is correct
62 Correct 5 ms 39516 KB Output is correct
63 Correct 501 ms 82604 KB Output is correct
64 Correct 308 ms 80468 KB Output is correct
65 Correct 397 ms 80976 KB Output is correct
66 Correct 444 ms 76052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 331 ms 68480 KB Output is correct
2 Correct 312 ms 68436 KB Output is correct
3 Correct 166 ms 72776 KB Output is correct
4 Correct 257 ms 75904 KB Output is correct
5 Correct 6 ms 39512 KB Output is correct
6 Correct 289 ms 75024 KB Output is correct
7 Correct 62 ms 49488 KB Output is correct
8 Correct 106 ms 63540 KB Output is correct
9 Correct 171 ms 73220 KB Output is correct
10 Correct 335 ms 74972 KB Output is correct
11 Correct 137 ms 70052 KB Output is correct
12 Correct 5 ms 39512 KB Output is correct
13 Correct 6 ms 39644 KB Output is correct
14 Correct 5 ms 39516 KB Output is correct
15 Correct 5 ms 39516 KB Output is correct
16 Correct 7 ms 39512 KB Output is correct
17 Correct 7 ms 39516 KB Output is correct
18 Correct 6 ms 39600 KB Output is correct
19 Correct 6 ms 39516 KB Output is correct
20 Correct 7 ms 39516 KB Output is correct
21 Correct 5 ms 39516 KB Output is correct
22 Correct 6 ms 39516 KB Output is correct
23 Correct 9 ms 39640 KB Output is correct
24 Correct 6 ms 39516 KB Output is correct
25 Correct 8 ms 39532 KB Output is correct
26 Correct 9 ms 39596 KB Output is correct
27 Correct 8 ms 39516 KB Output is correct
28 Correct 9 ms 39768 KB Output is correct
29 Correct 10 ms 39772 KB Output is correct
30 Correct 9 ms 39772 KB Output is correct
31 Correct 9 ms 39772 KB Output is correct
32 Correct 13 ms 39772 KB Output is correct
33 Correct 9 ms 39748 KB Output is correct
34 Correct 8 ms 39516 KB Output is correct
35 Correct 299 ms 72724 KB Output is correct
36 Correct 246 ms 70804 KB Output is correct
37 Correct 301 ms 76720 KB Output is correct
38 Correct 224 ms 70980 KB Output is correct
39 Correct 252 ms 72420 KB Output is correct
40 Correct 195 ms 71844 KB Output is correct
41 Correct 547 ms 74228 KB Output is correct
42 Correct 70 ms 48844 KB Output is correct
43 Correct 137 ms 63176 KB Output is correct
44 Correct 310 ms 72652 KB Output is correct
45 Correct 466 ms 72900 KB Output is correct
46 Correct 540 ms 71288 KB Output is correct
47 Correct 491 ms 71240 KB Output is correct
48 Correct 273 ms 78672 KB Output is correct
49 Correct 246 ms 72756 KB Output is correct
50 Correct 333 ms 76764 KB Output is correct
51 Correct 332 ms 77324 KB Output is correct
52 Correct 6 ms 39512 KB Output is correct
53 Correct 460 ms 75928 KB Output is correct
54 Correct 299 ms 74280 KB Output is correct
55 Correct 386 ms 74448 KB Output is correct
56 Correct 448 ms 72848 KB Output is correct
57 Correct 1433 ms 211856 KB Output is correct
58 Correct 1126 ms 182156 KB Output is correct
59 Correct 1781 ms 204884 KB Output is correct
60 Correct 1782 ms 204804 KB Output is correct
61 Correct 3015 ms 199844 KB Output is correct
62 Correct 1701 ms 190156 KB Output is correct
63 Correct 2242 ms 187844 KB Output is correct
64 Correct 2783 ms 184012 KB Output is correct
65 Correct 273 ms 78352 KB Output is correct
66 Correct 207 ms 65232 KB Output is correct
67 Correct 322 ms 70996 KB Output is correct
68 Correct 333 ms 83028 KB Output is correct
69 Correct 466 ms 79700 KB Output is correct
70 Correct 5 ms 39516 KB Output is correct
71 Correct 501 ms 82604 KB Output is correct
72 Correct 308 ms 80468 KB Output is correct
73 Correct 397 ms 80976 KB Output is correct
74 Correct 444 ms 76052 KB Output is correct
75 Correct 1488 ms 248144 KB Output is correct
76 Correct 1162 ms 219148 KB Output is correct
77 Correct 1882 ms 233304 KB Output is correct
78 Correct 1807 ms 235348 KB Output is correct
79 Correct 3097 ms 235548 KB Output is correct
80 Correct 1829 ms 223204 KB Output is correct
81 Correct 2600 ms 222720 KB Output is correct
82 Correct 3276 ms 202676 KB Output is correct
83 Correct 3275 ms 222840 KB Output is correct