Submission #1071713

# Submission time Handle Problem Language Result Execution time Memory
1071713 2024-08-23T10:22:47 Z isaachew Two Dishes (JOI19_dishes) C++17
100 / 100
5981 ms 448812 KB
#include <bits/stdc++.h>

/*
 Why is this Diamond 1?
 Shift segtree and range max
 Too slow for BOJ?
 */
std::pair<long long,long long> combine(std::pair<long long,long long> a,std::pair<long long,long long> b){
    return {a.first+b.first,std::max(a.second+b.first,b.second)};
}
struct segtree{
    int size;
    std::vector<std::pair<long long,long long>> nodes;
    segtree(){}
    void init(int n){
        size=n;
        nodes.resize(2*n-1,{0,0});
    }
    void update(int l,int r,std::pair<long long,long long> tr,int nl,int nr,int ni){
        if(r<=nl||l>=nr)return;
        if(l<=nl&&r>=nr){
            nodes[ni]=combine(nodes[ni],tr);
            return;
        }
        //pushdown
        int nm=(nl+nr)/2;
        nodes[ni+1]=combine(nodes[ni+1],nodes[ni]);
        nodes[ni+2*(nm-nl)]=combine(nodes[ni+2*(nm-nl)],nodes[ni]);
        nodes[ni]={0,-1e18};
        update(l,r,tr,nl,nm,ni+1);
        update(l,r,tr,nm,nr,ni+2*(nm-nl));
    }
    long long query(int p,int nl,int nr,int ni){
        if(nl+1>=nr){
            return nodes[ni].second;//func on 0
        }
        long long othq;
        int nm=(nl+nr)/2;
        if(p<nm){
            othq=query(p,nl,nm,ni+1);
        }else{
            othq=query(p,nm,nr,ni+2*(nm-nl));
        }
        return std::max(othq+nodes[ni].first,nodes[ni].second);
    }
};
int main(){
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    int n,m;
    std::cin>>n>>m;
    std::vector<long long> dish1,dish2;
    std::vector<long long> d1sums,d2sums;
    std::vector<std::pair<long long,long long>> d1pts,d2pts;
    std::map<int,std::vector<std::pair<int,long long>>> ndpts;//converted to (max step of dish 2, points)
    std::map<long long,long long> steps1,steps2;
    long long result=0;//constant added
    long long curt=0;
    for(int i=0;i<n;i++){
        long long x,a,b;
        std::cin>>x>>a>>b;
        dish1.push_back(x);
        d1pts.push_back({a,b});
        d1sums.push_back(curt);
        steps1[curt]=i;
        curt+=x;
    }
    d1sums.push_back(curt);
    steps1[curt]=n;
    curt=0;
    for(int i=0;i<m;i++){
        long long x,a,b;
        std::cin>>x>>a>>b;
        dish2.push_back(x);
        d2pts.push_back({a,b});
        d2sums.push_back(curt);
        steps2[curt]=i;
        curt+=x;
    }
    d2sums.push_back(curt);
    steps2[curt]=m;
    for(int i=0;i<n;i++){
        auto maxd2i=steps2.upper_bound(d1pts[i].first-d1sums[i+1]);
        int maxd2=maxd2i==steps2.end()?m:maxd2i->second-1;
        ndpts[i].push_back({maxd2,d1pts[i].second});//(index of step, last index to get affected)
        
    }
    for(int i=0;i<m;i++){
        auto maxd1i=steps1.upper_bound(d2pts[i].first-d2sums[i+1]);
        int maxd1=maxd1i==steps1.end()?n:maxd1i->second-1;
        if(maxd1>=0){
            ndpts[maxd1].push_back({i,-d2pts[i].second});
            result+=d2pts[i].second;
        }
    }
    segtree st;
    st.init(m+1);
    for(int i=0;i<n;i++){
        for(std::pair<int,long long> trans:ndpts[i]){
            st.update(0,trans.first+1,{trans.second,-1e18},0,m+1,0);
        }
        for(std::pair<int,long long> trans:ndpts[i]){
            long long qu=st.query(trans.first,0,m+1,0);
            st.update(trans.first+1,m+1,{0,qu},0,m+1,0);
        }
    }
    std::cout<<st.query(m+1,0,m+1,0)+result<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 458 ms 88232 KB Output is correct
2 Correct 459 ms 87200 KB Output is correct
3 Correct 353 ms 84576 KB Output is correct
4 Correct 397 ms 85084 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 452 ms 84360 KB Output is correct
7 Correct 100 ms 35112 KB Output is correct
8 Correct 177 ms 48924 KB Output is correct
9 Correct 340 ms 85800 KB Output is correct
10 Correct 474 ms 84652 KB Output is correct
11 Correct 316 ms 78628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 3 ms 1232 KB Output is correct
19 Correct 4 ms 1116 KB Output is correct
20 Correct 3 ms 1112 KB Output is correct
21 Correct 3 ms 1112 KB Output is correct
22 Correct 4 ms 1116 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 3 ms 1232 KB Output is correct
19 Correct 4 ms 1116 KB Output is correct
20 Correct 3 ms 1112 KB Output is correct
21 Correct 3 ms 1112 KB Output is correct
22 Correct 4 ms 1116 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
24 Correct 340 ms 80808 KB Output is correct
25 Correct 350 ms 80364 KB Output is correct
26 Correct 370 ms 81572 KB Output is correct
27 Correct 422 ms 87416 KB Output is correct
28 Correct 486 ms 81908 KB Output is correct
29 Correct 385 ms 81644 KB Output is correct
30 Correct 818 ms 85976 KB Output is correct
31 Correct 125 ms 36480 KB Output is correct
32 Correct 173 ms 46592 KB Output is correct
33 Correct 603 ms 80620 KB Output is correct
34 Correct 698 ms 83256 KB Output is correct
35 Correct 776 ms 78972 KB Output is correct
36 Correct 787 ms 78520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 3 ms 1232 KB Output is correct
19 Correct 4 ms 1116 KB Output is correct
20 Correct 3 ms 1112 KB Output is correct
21 Correct 3 ms 1112 KB Output is correct
22 Correct 4 ms 1116 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
24 Correct 340 ms 80808 KB Output is correct
25 Correct 350 ms 80364 KB Output is correct
26 Correct 370 ms 81572 KB Output is correct
27 Correct 422 ms 87416 KB Output is correct
28 Correct 486 ms 81908 KB Output is correct
29 Correct 385 ms 81644 KB Output is correct
30 Correct 818 ms 85976 KB Output is correct
31 Correct 125 ms 36480 KB Output is correct
32 Correct 173 ms 46592 KB Output is correct
33 Correct 603 ms 80620 KB Output is correct
34 Correct 698 ms 83256 KB Output is correct
35 Correct 776 ms 78972 KB Output is correct
36 Correct 787 ms 78520 KB Output is correct
37 Correct 383 ms 84228 KB Output is correct
38 Correct 450 ms 89944 KB Output is correct
39 Correct 474 ms 87708 KB Output is correct
40 Correct 458 ms 87336 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 813 ms 88840 KB Output is correct
43 Correct 551 ms 83624 KB Output is correct
44 Correct 625 ms 86056 KB Output is correct
45 Correct 773 ms 81580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 3 ms 1232 KB Output is correct
19 Correct 4 ms 1116 KB Output is correct
20 Correct 3 ms 1112 KB Output is correct
21 Correct 3 ms 1112 KB Output is correct
22 Correct 4 ms 1116 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
24 Correct 340 ms 80808 KB Output is correct
25 Correct 350 ms 80364 KB Output is correct
26 Correct 370 ms 81572 KB Output is correct
27 Correct 422 ms 87416 KB Output is correct
28 Correct 486 ms 81908 KB Output is correct
29 Correct 385 ms 81644 KB Output is correct
30 Correct 818 ms 85976 KB Output is correct
31 Correct 125 ms 36480 KB Output is correct
32 Correct 173 ms 46592 KB Output is correct
33 Correct 603 ms 80620 KB Output is correct
34 Correct 698 ms 83256 KB Output is correct
35 Correct 776 ms 78972 KB Output is correct
36 Correct 787 ms 78520 KB Output is correct
37 Correct 383 ms 84228 KB Output is correct
38 Correct 450 ms 89944 KB Output is correct
39 Correct 474 ms 87708 KB Output is correct
40 Correct 458 ms 87336 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 813 ms 88840 KB Output is correct
43 Correct 551 ms 83624 KB Output is correct
44 Correct 625 ms 86056 KB Output is correct
45 Correct 773 ms 81580 KB Output is correct
46 Correct 2012 ms 415712 KB Output is correct
47 Correct 2293 ms 447228 KB Output is correct
48 Correct 2477 ms 432680 KB Output is correct
49 Correct 2582 ms 432816 KB Output is correct
50 Correct 5981 ms 439108 KB Output is correct
51 Correct 3823 ms 404392 KB Output is correct
52 Correct 4226 ms 414400 KB Output is correct
53 Correct 5528 ms 406128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 88232 KB Output is correct
2 Correct 459 ms 87200 KB Output is correct
3 Correct 353 ms 84576 KB Output is correct
4 Correct 397 ms 85084 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 452 ms 84360 KB Output is correct
7 Correct 100 ms 35112 KB Output is correct
8 Correct 177 ms 48924 KB Output is correct
9 Correct 340 ms 85800 KB Output is correct
10 Correct 474 ms 84652 KB Output is correct
11 Correct 316 ms 78628 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 456 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 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 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 3 ms 1232 KB Output is correct
30 Correct 4 ms 1116 KB Output is correct
31 Correct 3 ms 1112 KB Output is correct
32 Correct 3 ms 1112 KB Output is correct
33 Correct 4 ms 1116 KB Output is correct
34 Correct 3 ms 1116 KB Output is correct
35 Correct 340 ms 80808 KB Output is correct
36 Correct 350 ms 80364 KB Output is correct
37 Correct 370 ms 81572 KB Output is correct
38 Correct 422 ms 87416 KB Output is correct
39 Correct 486 ms 81908 KB Output is correct
40 Correct 385 ms 81644 KB Output is correct
41 Correct 818 ms 85976 KB Output is correct
42 Correct 125 ms 36480 KB Output is correct
43 Correct 173 ms 46592 KB Output is correct
44 Correct 603 ms 80620 KB Output is correct
45 Correct 698 ms 83256 KB Output is correct
46 Correct 776 ms 78972 KB Output is correct
47 Correct 787 ms 78520 KB Output is correct
48 Correct 383 ms 84228 KB Output is correct
49 Correct 450 ms 89944 KB Output is correct
50 Correct 474 ms 87708 KB Output is correct
51 Correct 458 ms 87336 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 813 ms 88840 KB Output is correct
54 Correct 551 ms 83624 KB Output is correct
55 Correct 625 ms 86056 KB Output is correct
56 Correct 773 ms 81580 KB Output is correct
57 Correct 386 ms 84644 KB Output is correct
58 Correct 410 ms 90748 KB Output is correct
59 Correct 456 ms 88744 KB Output is correct
60 Correct 451 ms 88512 KB Output is correct
61 Correct 784 ms 86104 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 759 ms 88776 KB Output is correct
64 Correct 547 ms 84064 KB Output is correct
65 Correct 623 ms 85728 KB Output is correct
66 Correct 715 ms 82092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 88232 KB Output is correct
2 Correct 459 ms 87200 KB Output is correct
3 Correct 353 ms 84576 KB Output is correct
4 Correct 397 ms 85084 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 452 ms 84360 KB Output is correct
7 Correct 100 ms 35112 KB Output is correct
8 Correct 177 ms 48924 KB Output is correct
9 Correct 340 ms 85800 KB Output is correct
10 Correct 474 ms 84652 KB Output is correct
11 Correct 316 ms 78628 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 456 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 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 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 3 ms 1232 KB Output is correct
30 Correct 4 ms 1116 KB Output is correct
31 Correct 3 ms 1112 KB Output is correct
32 Correct 3 ms 1112 KB Output is correct
33 Correct 4 ms 1116 KB Output is correct
34 Correct 3 ms 1116 KB Output is correct
35 Correct 340 ms 80808 KB Output is correct
36 Correct 350 ms 80364 KB Output is correct
37 Correct 370 ms 81572 KB Output is correct
38 Correct 422 ms 87416 KB Output is correct
39 Correct 486 ms 81908 KB Output is correct
40 Correct 385 ms 81644 KB Output is correct
41 Correct 818 ms 85976 KB Output is correct
42 Correct 125 ms 36480 KB Output is correct
43 Correct 173 ms 46592 KB Output is correct
44 Correct 603 ms 80620 KB Output is correct
45 Correct 698 ms 83256 KB Output is correct
46 Correct 776 ms 78972 KB Output is correct
47 Correct 787 ms 78520 KB Output is correct
48 Correct 383 ms 84228 KB Output is correct
49 Correct 450 ms 89944 KB Output is correct
50 Correct 474 ms 87708 KB Output is correct
51 Correct 458 ms 87336 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 813 ms 88840 KB Output is correct
54 Correct 551 ms 83624 KB Output is correct
55 Correct 625 ms 86056 KB Output is correct
56 Correct 773 ms 81580 KB Output is correct
57 Correct 2012 ms 415712 KB Output is correct
58 Correct 2293 ms 447228 KB Output is correct
59 Correct 2477 ms 432680 KB Output is correct
60 Correct 2582 ms 432816 KB Output is correct
61 Correct 5981 ms 439108 KB Output is correct
62 Correct 3823 ms 404392 KB Output is correct
63 Correct 4226 ms 414400 KB Output is correct
64 Correct 5528 ms 406128 KB Output is correct
65 Correct 386 ms 84644 KB Output is correct
66 Correct 410 ms 90748 KB Output is correct
67 Correct 456 ms 88744 KB Output is correct
68 Correct 451 ms 88512 KB Output is correct
69 Correct 784 ms 86104 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 759 ms 88776 KB Output is correct
72 Correct 547 ms 84064 KB Output is correct
73 Correct 623 ms 85728 KB Output is correct
74 Correct 715 ms 82092 KB Output is correct
75 Correct 2121 ms 417196 KB Output is correct
76 Correct 2311 ms 448812 KB Output is correct
77 Correct 2456 ms 435352 KB Output is correct
78 Correct 2563 ms 435796 KB Output is correct
79 Correct 5874 ms 438896 KB Output is correct
80 Correct 3609 ms 411272 KB Output is correct
81 Correct 4200 ms 405184 KB Output is correct
82 Correct 5850 ms 405724 KB Output is correct
83 Correct 5605 ms 425096 KB Output is correct