Submission #621663

# Submission time Handle Problem Language Result Execution time Memory
621663 2022-08-04T01:42:41 Z czhang2718 Two Dishes (JOI19_dishes) C++17
82 / 100
10000 ms 318872 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<int> vi;
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i=a; i<=b; i++)

const int N=1e6+1;
int n, m;
ll a[N], b[N], p[N], q[N], s[N], t[N];
map<int,ll> qu[N];

bool st[4*N];
ll seg[4*N];

void push(int x, int lx, int rx){
    if(rx-lx==1) return;
    if(st[x]){
        seg[2*x+1]=seg[2*x+2]=seg[x];
        st[2*x+1]=st[2*x+2]=1;
        seg[x]=0;
        st[x]=0;
        return;
    }
    seg[2*x+1]+=seg[x];
    seg[2*x+2]+=seg[x];
    seg[x]=0;
}

void add(int l, int r, int x, int lx, int rx, ll v){
    // cout << "add " << l << r << " " << v << "\n";
    push(x, lx, rx);
    if(lx>=l && rx<=r){
        seg[x]+=v;
        return;
    }
    if(lx>=r || rx<=l) return;
    int mid=(lx+rx)/2;
    add(l, r, 2*x+1, lx, mid, v);
    add(l, r, 2*x+2, mid, rx, v);
}

void add(int l, int r, ll v){
    add(l, r, 0, 0, m+1, v);
}

void assign(int l, int r, ll v, int x, int lx, int rx){
    push(x, lx, rx);
    if(lx>=l && rx<=r){
        // cout << "seg " << lx << " " << rx << " = " << v << "\n";
        seg[x]=v;
        st[x]=1;
        return;
    }
    if(lx>=r || rx<=l) return;
    int mid=(lx+rx)/2;
    assign(l, r, v, 2*x+1, lx, mid);
    assign(l, r, v, 2*x+2, mid, rx);
}

void assign(int l, int r, ll v){
    if(r<=l) return;
    assign(l, r, v, 0, 0, m+1);
}

void assign(int i, ll v){
    assign(i, i+1, v);
}


ll qry(int i, int x, int lx, int rx){
    if(rx-lx==1) return seg[x];
    push(x, lx, rx);
    int mid=(lx+rx)/2;
    if(i<mid) return qry(i, 2*x+1, lx, mid);
    return qry(i, 2*x+2, mid, rx);
}

ll qry(int i){
    return qry(i, 0, 0, m+1);
}

int main(){
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> m;
    ll ans=0;
    vector<vi> pts;
    vector<ll> A(n+1), B(m+1);

    rep(i,1,n){
        cin >> a[i] >> s[i] >> p[i];
        A[i]=A[i-1]+a[i];
    }
    

    A.erase(A.begin());
    rep(i,1,m){
        cin >> b[i] >> t[i] >> q[i];
        B[i]=B[i-1]+b[i];
        int j=upper_bound(all(A), t[i]-B[i])-A.begin();
        if(B[i]<=t[i]) qu[j][i]+=q[i];
    }


    B.erase(B.begin());
    rep(i,1,n){
        int j=upper_bound(all(B), s[i]-A[i-1])-B.begin();
        if(A[i-1]<=s[i]){
            ans+=p[i];
            qu[i-1][j+1]-=p[i];
        }
    }

    rep(i,0,n){
        vector<pii> pts;
        for(auto p:qu[i]) pts.push_back(p);
        reverse(all(pts)); 
        // cout << "x " << i << ":\n";
        for(auto p:pts){
            int y=p.f;
            int v=p.s;
            // cout << y << " " << v << "\n";
            add(y, m+1, v);
            // rep(i,0,m) cout << qry(i) << " ";
            // cout << "\n";
            if(i!=n){
                ll prv=qry(y-1);
                int j=y-1;
                for(int k=19; k>=0; k--){
                    if(j+(1<<k)<=m && qry(j+(1<<k))<prv) j+=(1<<k);
                }
                j++;
                assign(y, j, prv);
                // rep(i,0,m) cout << qry(i) << " ";
                // cout << "\n";
            }
        }
    }
    cout << ans+qry(m);
}

// A: (x, <=y)
// B: (x, >=y)

# Verdict Execution time Memory Grader output
1 Correct 893 ms 79688 KB Output is correct
2 Correct 953 ms 82356 KB Output is correct
3 Correct 448 ms 92492 KB Output is correct
4 Correct 577 ms 72144 KB Output is correct
5 Correct 32 ms 47268 KB Output is correct
6 Correct 777 ms 82988 KB Output is correct
7 Correct 257 ms 71840 KB Output is correct
8 Correct 200 ms 66320 KB Output is correct
9 Correct 427 ms 92452 KB Output is correct
10 Correct 768 ms 77172 KB Output is correct
11 Correct 344 ms 92492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47296 KB Output is correct
2 Correct 31 ms 47256 KB Output is correct
3 Correct 26 ms 47304 KB Output is correct
4 Correct 40 ms 47332 KB Output is correct
5 Correct 34 ms 47296 KB Output is correct
6 Correct 28 ms 47284 KB Output is correct
7 Correct 29 ms 47292 KB Output is correct
8 Correct 32 ms 47272 KB Output is correct
9 Correct 38 ms 47248 KB Output is correct
10 Correct 38 ms 47308 KB Output is correct
11 Correct 36 ms 47336 KB Output is correct
12 Correct 24 ms 47344 KB Output is correct
13 Correct 29 ms 47308 KB Output is correct
14 Correct 23 ms 47308 KB Output is correct
15 Correct 27 ms 47248 KB Output is correct
16 Correct 27 ms 47244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47296 KB Output is correct
2 Correct 31 ms 47256 KB Output is correct
3 Correct 26 ms 47304 KB Output is correct
4 Correct 40 ms 47332 KB Output is correct
5 Correct 34 ms 47296 KB Output is correct
6 Correct 28 ms 47284 KB Output is correct
7 Correct 29 ms 47292 KB Output is correct
8 Correct 32 ms 47272 KB Output is correct
9 Correct 38 ms 47248 KB Output is correct
10 Correct 38 ms 47308 KB Output is correct
11 Correct 36 ms 47336 KB Output is correct
12 Correct 24 ms 47344 KB Output is correct
13 Correct 29 ms 47308 KB Output is correct
14 Correct 23 ms 47308 KB Output is correct
15 Correct 27 ms 47248 KB Output is correct
16 Correct 27 ms 47244 KB Output is correct
17 Correct 28 ms 47808 KB Output is correct
18 Correct 42 ms 47756 KB Output is correct
19 Correct 45 ms 47736 KB Output is correct
20 Correct 32 ms 47680 KB Output is correct
21 Correct 35 ms 47852 KB Output is correct
22 Correct 35 ms 47692 KB Output is correct
23 Correct 34 ms 47688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47296 KB Output is correct
2 Correct 31 ms 47256 KB Output is correct
3 Correct 26 ms 47304 KB Output is correct
4 Correct 40 ms 47332 KB Output is correct
5 Correct 34 ms 47296 KB Output is correct
6 Correct 28 ms 47284 KB Output is correct
7 Correct 29 ms 47292 KB Output is correct
8 Correct 32 ms 47272 KB Output is correct
9 Correct 38 ms 47248 KB Output is correct
10 Correct 38 ms 47308 KB Output is correct
11 Correct 36 ms 47336 KB Output is correct
12 Correct 24 ms 47344 KB Output is correct
13 Correct 29 ms 47308 KB Output is correct
14 Correct 23 ms 47308 KB Output is correct
15 Correct 27 ms 47248 KB Output is correct
16 Correct 27 ms 47244 KB Output is correct
17 Correct 28 ms 47808 KB Output is correct
18 Correct 42 ms 47756 KB Output is correct
19 Correct 45 ms 47736 KB Output is correct
20 Correct 32 ms 47680 KB Output is correct
21 Correct 35 ms 47852 KB Output is correct
22 Correct 35 ms 47692 KB Output is correct
23 Correct 34 ms 47688 KB Output is correct
24 Correct 685 ms 85204 KB Output is correct
25 Correct 843 ms 86172 KB Output is correct
26 Correct 665 ms 85632 KB Output is correct
27 Correct 809 ms 82952 KB Output is correct
28 Correct 799 ms 88824 KB Output is correct
29 Correct 371 ms 92528 KB Output is correct
30 Correct 2131 ms 89288 KB Output is correct
31 Correct 499 ms 74108 KB Output is correct
32 Correct 146 ms 66356 KB Output is correct
33 Correct 1235 ms 77020 KB Output is correct
34 Correct 1450 ms 89376 KB Output is correct
35 Correct 1934 ms 89552 KB Output is correct
36 Correct 1843 ms 89196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47296 KB Output is correct
2 Correct 31 ms 47256 KB Output is correct
3 Correct 26 ms 47304 KB Output is correct
4 Correct 40 ms 47332 KB Output is correct
5 Correct 34 ms 47296 KB Output is correct
6 Correct 28 ms 47284 KB Output is correct
7 Correct 29 ms 47292 KB Output is correct
8 Correct 32 ms 47272 KB Output is correct
9 Correct 38 ms 47248 KB Output is correct
10 Correct 38 ms 47308 KB Output is correct
11 Correct 36 ms 47336 KB Output is correct
12 Correct 24 ms 47344 KB Output is correct
13 Correct 29 ms 47308 KB Output is correct
14 Correct 23 ms 47308 KB Output is correct
15 Correct 27 ms 47248 KB Output is correct
16 Correct 27 ms 47244 KB Output is correct
17 Correct 28 ms 47808 KB Output is correct
18 Correct 42 ms 47756 KB Output is correct
19 Correct 45 ms 47736 KB Output is correct
20 Correct 32 ms 47680 KB Output is correct
21 Correct 35 ms 47852 KB Output is correct
22 Correct 35 ms 47692 KB Output is correct
23 Correct 34 ms 47688 KB Output is correct
24 Correct 685 ms 85204 KB Output is correct
25 Correct 843 ms 86172 KB Output is correct
26 Correct 665 ms 85632 KB Output is correct
27 Correct 809 ms 82952 KB Output is correct
28 Correct 799 ms 88824 KB Output is correct
29 Correct 371 ms 92528 KB Output is correct
30 Correct 2131 ms 89288 KB Output is correct
31 Correct 499 ms 74108 KB Output is correct
32 Correct 146 ms 66356 KB Output is correct
33 Correct 1235 ms 77020 KB Output is correct
34 Correct 1450 ms 89376 KB Output is correct
35 Correct 1934 ms 89552 KB Output is correct
36 Correct 1843 ms 89196 KB Output is correct
37 Correct 756 ms 85672 KB Output is correct
38 Correct 836 ms 82996 KB Output is correct
39 Correct 718 ms 76748 KB Output is correct
40 Correct 676 ms 77248 KB Output is correct
41 Correct 37 ms 47312 KB Output is correct
42 Correct 2090 ms 89432 KB Output is correct
43 Correct 1140 ms 90248 KB Output is correct
44 Correct 1632 ms 102416 KB Output is correct
45 Correct 1628 ms 96632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47296 KB Output is correct
2 Correct 31 ms 47256 KB Output is correct
3 Correct 26 ms 47304 KB Output is correct
4 Correct 40 ms 47332 KB Output is correct
5 Correct 34 ms 47296 KB Output is correct
6 Correct 28 ms 47284 KB Output is correct
7 Correct 29 ms 47292 KB Output is correct
8 Correct 32 ms 47272 KB Output is correct
9 Correct 38 ms 47248 KB Output is correct
10 Correct 38 ms 47308 KB Output is correct
11 Correct 36 ms 47336 KB Output is correct
12 Correct 24 ms 47344 KB Output is correct
13 Correct 29 ms 47308 KB Output is correct
14 Correct 23 ms 47308 KB Output is correct
15 Correct 27 ms 47248 KB Output is correct
16 Correct 27 ms 47244 KB Output is correct
17 Correct 28 ms 47808 KB Output is correct
18 Correct 42 ms 47756 KB Output is correct
19 Correct 45 ms 47736 KB Output is correct
20 Correct 32 ms 47680 KB Output is correct
21 Correct 35 ms 47852 KB Output is correct
22 Correct 35 ms 47692 KB Output is correct
23 Correct 34 ms 47688 KB Output is correct
24 Correct 685 ms 85204 KB Output is correct
25 Correct 843 ms 86172 KB Output is correct
26 Correct 665 ms 85632 KB Output is correct
27 Correct 809 ms 82952 KB Output is correct
28 Correct 799 ms 88824 KB Output is correct
29 Correct 371 ms 92528 KB Output is correct
30 Correct 2131 ms 89288 KB Output is correct
31 Correct 499 ms 74108 KB Output is correct
32 Correct 146 ms 66356 KB Output is correct
33 Correct 1235 ms 77020 KB Output is correct
34 Correct 1450 ms 89376 KB Output is correct
35 Correct 1934 ms 89552 KB Output is correct
36 Correct 1843 ms 89196 KB Output is correct
37 Correct 756 ms 85672 KB Output is correct
38 Correct 836 ms 82996 KB Output is correct
39 Correct 718 ms 76748 KB Output is correct
40 Correct 676 ms 77248 KB Output is correct
41 Correct 37 ms 47312 KB Output is correct
42 Correct 2090 ms 89432 KB Output is correct
43 Correct 1140 ms 90248 KB Output is correct
44 Correct 1632 ms 102416 KB Output is correct
45 Correct 1628 ms 96632 KB Output is correct
46 Correct 3557 ms 300500 KB Output is correct
47 Correct 4737 ms 290108 KB Output is correct
48 Correct 4508 ms 245280 KB Output is correct
49 Correct 3872 ms 247332 KB Output is correct
50 Execution timed out 10103 ms 318872 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 893 ms 79688 KB Output is correct
2 Correct 953 ms 82356 KB Output is correct
3 Correct 448 ms 92492 KB Output is correct
4 Correct 577 ms 72144 KB Output is correct
5 Correct 32 ms 47268 KB Output is correct
6 Correct 777 ms 82988 KB Output is correct
7 Correct 257 ms 71840 KB Output is correct
8 Correct 200 ms 66320 KB Output is correct
9 Correct 427 ms 92452 KB Output is correct
10 Correct 768 ms 77172 KB Output is correct
11 Correct 344 ms 92492 KB Output is correct
12 Correct 32 ms 47296 KB Output is correct
13 Correct 31 ms 47256 KB Output is correct
14 Correct 26 ms 47304 KB Output is correct
15 Correct 40 ms 47332 KB Output is correct
16 Correct 34 ms 47296 KB Output is correct
17 Correct 28 ms 47284 KB Output is correct
18 Correct 29 ms 47292 KB Output is correct
19 Correct 32 ms 47272 KB Output is correct
20 Correct 38 ms 47248 KB Output is correct
21 Correct 38 ms 47308 KB Output is correct
22 Correct 36 ms 47336 KB Output is correct
23 Correct 24 ms 47344 KB Output is correct
24 Correct 29 ms 47308 KB Output is correct
25 Correct 23 ms 47308 KB Output is correct
26 Correct 27 ms 47248 KB Output is correct
27 Correct 27 ms 47244 KB Output is correct
28 Correct 28 ms 47808 KB Output is correct
29 Correct 42 ms 47756 KB Output is correct
30 Correct 45 ms 47736 KB Output is correct
31 Correct 32 ms 47680 KB Output is correct
32 Correct 35 ms 47852 KB Output is correct
33 Correct 35 ms 47692 KB Output is correct
34 Correct 34 ms 47688 KB Output is correct
35 Correct 685 ms 85204 KB Output is correct
36 Correct 843 ms 86172 KB Output is correct
37 Correct 665 ms 85632 KB Output is correct
38 Correct 809 ms 82952 KB Output is correct
39 Correct 799 ms 88824 KB Output is correct
40 Correct 371 ms 92528 KB Output is correct
41 Correct 2131 ms 89288 KB Output is correct
42 Correct 499 ms 74108 KB Output is correct
43 Correct 146 ms 66356 KB Output is correct
44 Correct 1235 ms 77020 KB Output is correct
45 Correct 1450 ms 89376 KB Output is correct
46 Correct 1934 ms 89552 KB Output is correct
47 Correct 1843 ms 89196 KB Output is correct
48 Correct 756 ms 85672 KB Output is correct
49 Correct 836 ms 82996 KB Output is correct
50 Correct 718 ms 76748 KB Output is correct
51 Correct 676 ms 77248 KB Output is correct
52 Correct 37 ms 47312 KB Output is correct
53 Correct 2090 ms 89432 KB Output is correct
54 Correct 1140 ms 90248 KB Output is correct
55 Correct 1632 ms 102416 KB Output is correct
56 Correct 1628 ms 96632 KB Output is correct
57 Correct 871 ms 99100 KB Output is correct
58 Correct 615 ms 97420 KB Output is correct
59 Correct 622 ms 88996 KB Output is correct
60 Correct 734 ms 88452 KB Output is correct
61 Correct 1954 ms 99736 KB Output is correct
62 Correct 27 ms 47316 KB Output is correct
63 Correct 2194 ms 103104 KB Output is correct
64 Correct 1189 ms 90084 KB Output is correct
65 Correct 1512 ms 103388 KB Output is correct
66 Correct 2375 ms 96500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 893 ms 79688 KB Output is correct
2 Correct 953 ms 82356 KB Output is correct
3 Correct 448 ms 92492 KB Output is correct
4 Correct 577 ms 72144 KB Output is correct
5 Correct 32 ms 47268 KB Output is correct
6 Correct 777 ms 82988 KB Output is correct
7 Correct 257 ms 71840 KB Output is correct
8 Correct 200 ms 66320 KB Output is correct
9 Correct 427 ms 92452 KB Output is correct
10 Correct 768 ms 77172 KB Output is correct
11 Correct 344 ms 92492 KB Output is correct
12 Correct 32 ms 47296 KB Output is correct
13 Correct 31 ms 47256 KB Output is correct
14 Correct 26 ms 47304 KB Output is correct
15 Correct 40 ms 47332 KB Output is correct
16 Correct 34 ms 47296 KB Output is correct
17 Correct 28 ms 47284 KB Output is correct
18 Correct 29 ms 47292 KB Output is correct
19 Correct 32 ms 47272 KB Output is correct
20 Correct 38 ms 47248 KB Output is correct
21 Correct 38 ms 47308 KB Output is correct
22 Correct 36 ms 47336 KB Output is correct
23 Correct 24 ms 47344 KB Output is correct
24 Correct 29 ms 47308 KB Output is correct
25 Correct 23 ms 47308 KB Output is correct
26 Correct 27 ms 47248 KB Output is correct
27 Correct 27 ms 47244 KB Output is correct
28 Correct 28 ms 47808 KB Output is correct
29 Correct 42 ms 47756 KB Output is correct
30 Correct 45 ms 47736 KB Output is correct
31 Correct 32 ms 47680 KB Output is correct
32 Correct 35 ms 47852 KB Output is correct
33 Correct 35 ms 47692 KB Output is correct
34 Correct 34 ms 47688 KB Output is correct
35 Correct 685 ms 85204 KB Output is correct
36 Correct 843 ms 86172 KB Output is correct
37 Correct 665 ms 85632 KB Output is correct
38 Correct 809 ms 82952 KB Output is correct
39 Correct 799 ms 88824 KB Output is correct
40 Correct 371 ms 92528 KB Output is correct
41 Correct 2131 ms 89288 KB Output is correct
42 Correct 499 ms 74108 KB Output is correct
43 Correct 146 ms 66356 KB Output is correct
44 Correct 1235 ms 77020 KB Output is correct
45 Correct 1450 ms 89376 KB Output is correct
46 Correct 1934 ms 89552 KB Output is correct
47 Correct 1843 ms 89196 KB Output is correct
48 Correct 756 ms 85672 KB Output is correct
49 Correct 836 ms 82996 KB Output is correct
50 Correct 718 ms 76748 KB Output is correct
51 Correct 676 ms 77248 KB Output is correct
52 Correct 37 ms 47312 KB Output is correct
53 Correct 2090 ms 89432 KB Output is correct
54 Correct 1140 ms 90248 KB Output is correct
55 Correct 1632 ms 102416 KB Output is correct
56 Correct 1628 ms 96632 KB Output is correct
57 Correct 3557 ms 300500 KB Output is correct
58 Correct 4737 ms 290108 KB Output is correct
59 Correct 4508 ms 245280 KB Output is correct
60 Correct 3872 ms 247332 KB Output is correct
61 Execution timed out 10103 ms 318872 KB Time limit exceeded
62 Halted 0 ms 0 KB -