답안 #1070093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070093 2024-08-22T11:38:10 Z heeew Two Dishes (JOI19_dishes) C++14
74 / 100
3131 ms 245152 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=1.557e+18;

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=min(seg[i<<1].v,seg[i<<1|1].v);
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 351 ms 78932 KB Output is correct
2 Correct 332 ms 79188 KB Output is correct
3 Correct 173 ms 76152 KB Output is correct
4 Correct 264 ms 79140 KB Output is correct
5 Correct 6 ms 39516 KB Output is correct
6 Correct 300 ms 78500 KB Output is correct
7 Correct 61 ms 51204 KB Output is correct
8 Correct 81 ms 65076 KB Output is correct
9 Correct 169 ms 76988 KB Output is correct
10 Correct 327 ms 76888 KB Output is correct
11 Correct 134 ms 71888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 39512 KB Output is correct
2 Correct 6 ms 39516 KB Output is correct
3 Correct 6 ms 39516 KB Output is correct
4 Correct 6 ms 39512 KB Output is correct
5 Correct 5 ms 39548 KB Output is correct
6 Correct 5 ms 39516 KB Output is correct
7 Correct 6 ms 39516 KB Output is correct
8 Correct 6 ms 39512 KB Output is correct
9 Correct 5 ms 39516 KB Output is correct
10 Correct 5 ms 39528 KB Output is correct
11 Correct 6 ms 39516 KB Output is correct
12 Correct 6 ms 39540 KB Output is correct
13 Correct 7 ms 39516 KB Output is correct
14 Correct 6 ms 39516 KB Output is correct
15 Correct 5 ms 39516 KB Output is correct
16 Correct 5 ms 39516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 39512 KB Output is correct
2 Correct 6 ms 39516 KB Output is correct
3 Correct 6 ms 39516 KB Output is correct
4 Correct 6 ms 39512 KB Output is correct
5 Correct 5 ms 39548 KB Output is correct
6 Correct 5 ms 39516 KB Output is correct
7 Correct 6 ms 39516 KB Output is correct
8 Correct 6 ms 39512 KB Output is correct
9 Correct 5 ms 39516 KB Output is correct
10 Correct 5 ms 39528 KB Output is correct
11 Correct 6 ms 39516 KB Output is correct
12 Correct 6 ms 39540 KB Output is correct
13 Correct 7 ms 39516 KB Output is correct
14 Correct 6 ms 39516 KB Output is correct
15 Correct 5 ms 39516 KB Output is correct
16 Correct 5 ms 39516 KB Output is correct
17 Correct 8 ms 39772 KB Output is correct
18 Correct 7 ms 39768 KB Output is correct
19 Correct 9 ms 39772 KB Output is correct
20 Correct 8 ms 39772 KB Output is correct
21 Correct 8 ms 39772 KB Output is correct
22 Correct 9 ms 39516 KB Output is correct
23 Correct 8 ms 39516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 39512 KB Output is correct
2 Correct 6 ms 39516 KB Output is correct
3 Correct 6 ms 39516 KB Output is correct
4 Correct 6 ms 39512 KB Output is correct
5 Correct 5 ms 39548 KB Output is correct
6 Correct 5 ms 39516 KB Output is correct
7 Correct 6 ms 39516 KB Output is correct
8 Correct 6 ms 39512 KB Output is correct
9 Correct 5 ms 39516 KB Output is correct
10 Correct 5 ms 39528 KB Output is correct
11 Correct 6 ms 39516 KB Output is correct
12 Correct 6 ms 39540 KB Output is correct
13 Correct 7 ms 39516 KB Output is correct
14 Correct 6 ms 39516 KB Output is correct
15 Correct 5 ms 39516 KB Output is correct
16 Correct 5 ms 39516 KB Output is correct
17 Correct 8 ms 39772 KB Output is correct
18 Correct 7 ms 39768 KB Output is correct
19 Correct 9 ms 39772 KB Output is correct
20 Correct 8 ms 39772 KB Output is correct
21 Correct 8 ms 39772 KB Output is correct
22 Correct 9 ms 39516 KB Output is correct
23 Correct 8 ms 39516 KB Output is correct
24 Correct 251 ms 75488 KB Output is correct
25 Correct 208 ms 73684 KB Output is correct
26 Correct 277 ms 79444 KB Output is correct
27 Correct 207 ms 73644 KB Output is correct
28 Correct 234 ms 74900 KB Output is correct
29 Correct 149 ms 74512 KB Output is correct
30 Correct 468 ms 77140 KB Output is correct
31 Correct 53 ms 50004 KB Output is correct
32 Correct 134 ms 64264 KB Output is correct
33 Correct 279 ms 75232 KB Output is correct
34 Correct 387 ms 75656 KB Output is correct
35 Correct 447 ms 72276 KB Output is correct
36 Correct 411 ms 72176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 39512 KB Output is correct
2 Correct 6 ms 39516 KB Output is correct
3 Correct 6 ms 39516 KB Output is correct
4 Correct 6 ms 39512 KB Output is correct
5 Correct 5 ms 39548 KB Output is correct
6 Correct 5 ms 39516 KB Output is correct
7 Correct 6 ms 39516 KB Output is correct
8 Correct 6 ms 39512 KB Output is correct
9 Correct 5 ms 39516 KB Output is correct
10 Correct 5 ms 39528 KB Output is correct
11 Correct 6 ms 39516 KB Output is correct
12 Correct 6 ms 39540 KB Output is correct
13 Correct 7 ms 39516 KB Output is correct
14 Correct 6 ms 39516 KB Output is correct
15 Correct 5 ms 39516 KB Output is correct
16 Correct 5 ms 39516 KB Output is correct
17 Correct 8 ms 39772 KB Output is correct
18 Correct 7 ms 39768 KB Output is correct
19 Correct 9 ms 39772 KB Output is correct
20 Correct 8 ms 39772 KB Output is correct
21 Correct 8 ms 39772 KB Output is correct
22 Correct 9 ms 39516 KB Output is correct
23 Correct 8 ms 39516 KB Output is correct
24 Correct 251 ms 75488 KB Output is correct
25 Correct 208 ms 73684 KB Output is correct
26 Correct 277 ms 79444 KB Output is correct
27 Correct 207 ms 73644 KB Output is correct
28 Correct 234 ms 74900 KB Output is correct
29 Correct 149 ms 74512 KB Output is correct
30 Correct 468 ms 77140 KB Output is correct
31 Correct 53 ms 50004 KB Output is correct
32 Correct 134 ms 64264 KB Output is correct
33 Correct 279 ms 75232 KB Output is correct
34 Correct 387 ms 75656 KB Output is correct
35 Correct 447 ms 72276 KB Output is correct
36 Correct 411 ms 72176 KB Output is correct
37 Correct 292 ms 81836 KB Output is correct
38 Correct 238 ms 75988 KB Output is correct
39 Correct 349 ms 79440 KB Output is correct
40 Correct 340 ms 79548 KB Output is correct
41 Correct 5 ms 39516 KB Output is correct
42 Correct 526 ms 79296 KB Output is correct
43 Correct 309 ms 77652 KB Output is correct
44 Correct 395 ms 77672 KB Output is correct
45 Correct 475 ms 74576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 39512 KB Output is correct
2 Correct 6 ms 39516 KB Output is correct
3 Correct 6 ms 39516 KB Output is correct
4 Correct 6 ms 39512 KB Output is correct
5 Correct 5 ms 39548 KB Output is correct
6 Correct 5 ms 39516 KB Output is correct
7 Correct 6 ms 39516 KB Output is correct
8 Correct 6 ms 39512 KB Output is correct
9 Correct 5 ms 39516 KB Output is correct
10 Correct 5 ms 39528 KB Output is correct
11 Correct 6 ms 39516 KB Output is correct
12 Correct 6 ms 39540 KB Output is correct
13 Correct 7 ms 39516 KB Output is correct
14 Correct 6 ms 39516 KB Output is correct
15 Correct 5 ms 39516 KB Output is correct
16 Correct 5 ms 39516 KB Output is correct
17 Correct 8 ms 39772 KB Output is correct
18 Correct 7 ms 39768 KB Output is correct
19 Correct 9 ms 39772 KB Output is correct
20 Correct 8 ms 39772 KB Output is correct
21 Correct 8 ms 39772 KB Output is correct
22 Correct 9 ms 39516 KB Output is correct
23 Correct 8 ms 39516 KB Output is correct
24 Correct 251 ms 75488 KB Output is correct
25 Correct 208 ms 73684 KB Output is correct
26 Correct 277 ms 79444 KB Output is correct
27 Correct 207 ms 73644 KB Output is correct
28 Correct 234 ms 74900 KB Output is correct
29 Correct 149 ms 74512 KB Output is correct
30 Correct 468 ms 77140 KB Output is correct
31 Correct 53 ms 50004 KB Output is correct
32 Correct 134 ms 64264 KB Output is correct
33 Correct 279 ms 75232 KB Output is correct
34 Correct 387 ms 75656 KB Output is correct
35 Correct 447 ms 72276 KB Output is correct
36 Correct 411 ms 72176 KB Output is correct
37 Correct 292 ms 81836 KB Output is correct
38 Correct 238 ms 75988 KB Output is correct
39 Correct 349 ms 79440 KB Output is correct
40 Correct 340 ms 79548 KB Output is correct
41 Correct 5 ms 39516 KB Output is correct
42 Correct 526 ms 79296 KB Output is correct
43 Correct 309 ms 77652 KB Output is correct
44 Correct 395 ms 77672 KB Output is correct
45 Correct 475 ms 74576 KB Output is correct
46 Correct 1490 ms 245152 KB Output is correct
47 Correct 1118 ms 217064 KB Output is correct
48 Correct 1814 ms 232584 KB Output is correct
49 Correct 1869 ms 232744 KB Output is correct
50 Correct 3131 ms 234644 KB Output is correct
51 Correct 1769 ms 223312 KB Output is correct
52 Correct 2198 ms 220680 KB Output is correct
53 Correct 2766 ms 203272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 351 ms 78932 KB Output is correct
2 Correct 332 ms 79188 KB Output is correct
3 Correct 173 ms 76152 KB Output is correct
4 Correct 264 ms 79140 KB Output is correct
5 Correct 6 ms 39516 KB Output is correct
6 Correct 300 ms 78500 KB Output is correct
7 Correct 61 ms 51204 KB Output is correct
8 Correct 81 ms 65076 KB Output is correct
9 Correct 169 ms 76988 KB Output is correct
10 Correct 327 ms 76888 KB Output is correct
11 Correct 134 ms 71888 KB Output is correct
12 Correct 5 ms 39512 KB Output is correct
13 Correct 6 ms 39516 KB Output is correct
14 Correct 6 ms 39516 KB Output is correct
15 Correct 6 ms 39512 KB Output is correct
16 Correct 5 ms 39548 KB Output is correct
17 Correct 5 ms 39516 KB Output is correct
18 Correct 6 ms 39516 KB Output is correct
19 Correct 6 ms 39512 KB Output is correct
20 Correct 5 ms 39516 KB Output is correct
21 Correct 5 ms 39528 KB Output is correct
22 Correct 6 ms 39516 KB Output is correct
23 Correct 6 ms 39540 KB Output is correct
24 Correct 7 ms 39516 KB Output is correct
25 Correct 6 ms 39516 KB Output is correct
26 Correct 5 ms 39516 KB Output is correct
27 Correct 5 ms 39516 KB Output is correct
28 Correct 8 ms 39772 KB Output is correct
29 Correct 7 ms 39768 KB Output is correct
30 Correct 9 ms 39772 KB Output is correct
31 Correct 8 ms 39772 KB Output is correct
32 Correct 8 ms 39772 KB Output is correct
33 Correct 9 ms 39516 KB Output is correct
34 Correct 8 ms 39516 KB Output is correct
35 Correct 251 ms 75488 KB Output is correct
36 Correct 208 ms 73684 KB Output is correct
37 Correct 277 ms 79444 KB Output is correct
38 Correct 207 ms 73644 KB Output is correct
39 Correct 234 ms 74900 KB Output is correct
40 Correct 149 ms 74512 KB Output is correct
41 Correct 468 ms 77140 KB Output is correct
42 Correct 53 ms 50004 KB Output is correct
43 Correct 134 ms 64264 KB Output is correct
44 Correct 279 ms 75232 KB Output is correct
45 Correct 387 ms 75656 KB Output is correct
46 Correct 447 ms 72276 KB Output is correct
47 Correct 411 ms 72176 KB Output is correct
48 Correct 292 ms 81836 KB Output is correct
49 Correct 238 ms 75988 KB Output is correct
50 Correct 349 ms 79440 KB Output is correct
51 Correct 340 ms 79548 KB Output is correct
52 Correct 5 ms 39516 KB Output is correct
53 Correct 526 ms 79296 KB Output is correct
54 Correct 309 ms 77652 KB Output is correct
55 Correct 395 ms 77672 KB Output is correct
56 Correct 475 ms 74576 KB Output is correct
57 Correct 278 ms 85076 KB Output is correct
58 Correct 243 ms 78888 KB Output is correct
59 Incorrect 355 ms 83044 KB Output isn't correct
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 351 ms 78932 KB Output is correct
2 Correct 332 ms 79188 KB Output is correct
3 Correct 173 ms 76152 KB Output is correct
4 Correct 264 ms 79140 KB Output is correct
5 Correct 6 ms 39516 KB Output is correct
6 Correct 300 ms 78500 KB Output is correct
7 Correct 61 ms 51204 KB Output is correct
8 Correct 81 ms 65076 KB Output is correct
9 Correct 169 ms 76988 KB Output is correct
10 Correct 327 ms 76888 KB Output is correct
11 Correct 134 ms 71888 KB Output is correct
12 Correct 5 ms 39512 KB Output is correct
13 Correct 6 ms 39516 KB Output is correct
14 Correct 6 ms 39516 KB Output is correct
15 Correct 6 ms 39512 KB Output is correct
16 Correct 5 ms 39548 KB Output is correct
17 Correct 5 ms 39516 KB Output is correct
18 Correct 6 ms 39516 KB Output is correct
19 Correct 6 ms 39512 KB Output is correct
20 Correct 5 ms 39516 KB Output is correct
21 Correct 5 ms 39528 KB Output is correct
22 Correct 6 ms 39516 KB Output is correct
23 Correct 6 ms 39540 KB Output is correct
24 Correct 7 ms 39516 KB Output is correct
25 Correct 6 ms 39516 KB Output is correct
26 Correct 5 ms 39516 KB Output is correct
27 Correct 5 ms 39516 KB Output is correct
28 Correct 8 ms 39772 KB Output is correct
29 Correct 7 ms 39768 KB Output is correct
30 Correct 9 ms 39772 KB Output is correct
31 Correct 8 ms 39772 KB Output is correct
32 Correct 8 ms 39772 KB Output is correct
33 Correct 9 ms 39516 KB Output is correct
34 Correct 8 ms 39516 KB Output is correct
35 Correct 251 ms 75488 KB Output is correct
36 Correct 208 ms 73684 KB Output is correct
37 Correct 277 ms 79444 KB Output is correct
38 Correct 207 ms 73644 KB Output is correct
39 Correct 234 ms 74900 KB Output is correct
40 Correct 149 ms 74512 KB Output is correct
41 Correct 468 ms 77140 KB Output is correct
42 Correct 53 ms 50004 KB Output is correct
43 Correct 134 ms 64264 KB Output is correct
44 Correct 279 ms 75232 KB Output is correct
45 Correct 387 ms 75656 KB Output is correct
46 Correct 447 ms 72276 KB Output is correct
47 Correct 411 ms 72176 KB Output is correct
48 Correct 292 ms 81836 KB Output is correct
49 Correct 238 ms 75988 KB Output is correct
50 Correct 349 ms 79440 KB Output is correct
51 Correct 340 ms 79548 KB Output is correct
52 Correct 5 ms 39516 KB Output is correct
53 Correct 526 ms 79296 KB Output is correct
54 Correct 309 ms 77652 KB Output is correct
55 Correct 395 ms 77672 KB Output is correct
56 Correct 475 ms 74576 KB Output is correct
57 Correct 1490 ms 245152 KB Output is correct
58 Correct 1118 ms 217064 KB Output is correct
59 Correct 1814 ms 232584 KB Output is correct
60 Correct 1869 ms 232744 KB Output is correct
61 Correct 3131 ms 234644 KB Output is correct
62 Correct 1769 ms 223312 KB Output is correct
63 Correct 2198 ms 220680 KB Output is correct
64 Correct 2766 ms 203272 KB Output is correct
65 Correct 278 ms 85076 KB Output is correct
66 Correct 243 ms 78888 KB Output is correct
67 Incorrect 355 ms 83044 KB Output isn't correct
68 Halted 0 ms 0 KB -