Submission #1079531

# Submission time Handle Problem Language Result Execution time Memory
1079531 2024-08-28T16:24:13 Z phong Two Dishes (JOI19_dishes) C++17
100 / 100
4964 ms 353108 KB
#include<bits/stdc++.h>

#define ll long long
#define int long long
const int nmax = 1e6 + 5, N = 1e5;
const ll oo = 1e18 + 1, base = 311;
const int lg = 19, M = 10;
const ll mod = 998244353, mod2 = 1e9 + 5277;
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;

int n, m;
struct node{
    ll x, y, z;
}a[nmax], b[nmax];
map<int, ll> adj[nmax];
ll tree[nmax << 2], tr[nmax << 2];
pii lz[nmax << 2];
void build(int id, int l, int r){
    lz[id] = {1, 0};
    if(l != r){
        int mid = r + l >> 1;
        build(id << 1, l, mid);
        build(id << 1 | 1, mid + 1, r);
    }
}
void fix(int id, pii tx){
//    if(val == -oo) return;
    tree[id] = tree[id] * tx.fi + tx.se;
    tr[id] = tr[id] * tx.fi + tx.se;
    lz[id].fi = lz[id].fi * tx.fi;
    lz[id].se = lz[id].se * tx.fi + tx.se;
}
void down(int id){
    fix(id << 1, lz[id]);
    fix(id << 1 | 1, lz[id]);
    lz[id] = {1, 0};
}
void update(int id, int l, int r, int u, int v, pii val, int k){
    if(l > v || r < u || tr[id] >= k) return;
    if(l >= u && r<= v && tree[id] < k){
        return fix(id, val);
    }
    down(id);
    int mid = r + l >> 1;
    update(id << 1, l, mid, u, v,val, k);
    update(id << 1 |1, mid + 1, r, u,v, val, k);
    tree[id] = max(tree[id << 1], tree[id << 1 | 1]);
    tr[id] = min(tr[id << 1], tr[id << 1 | 1]);

//    for(int i = u; i <= v; ++i){
//        if(tree[i] > k) continue;
//        tree[i] = tree[i] * val.fi + val.se;
//    }
}
int get(int id, int l, int r, int u, int v){
    if(l >= u && r <=v ) return tree[id];
    int mid = r + l >> 1;
    down(id);
    if(mid < u) return get(id << 1 | 1, mid + 1, r,u, v);
    if(mid + 1 > v) return get(id << 1, l, mid, u, v);
    return max(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v));
//    int ma = -oo;
//    for(int i = u; i <= v; ++i) ma = max(ma, tree[i]);
//    return ma;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen("code.inp", "r", stdin);
//    freopen("code.out", "w", stdout);
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) cin >> a[i].x >> a[i].y >> a[i].z, a[i].x += a[i - 1].x;
    for(int i = 1; i <= m; ++i) cin >> b[i].x >> b[i].y >> b[i].z, b[i].x += b[i - 1].x;
    ll ans  = 0;
    for(int i = 1; i <= n; ++i){
        if(a[i].x <= a[i].y){
            int l = 1, r = m, it = m + 1;
            while(l <= r){
                int mid = r + l >> 1;
                if(b[mid].x > a[i].y - a[i].x){
                    r = mid - 1;
                    it = mid;
                }
                else l = mid + 1;
            }
            ans += a[i].z;
            if(it <= m) adj[i][it] -= a[i].z;
        }
    }
    for(int i = 1; i <= m; ++i){

        if(b[i].x <= b[i].y){
            int l = 1, r = n, it = n + 1;
            while(l <= r){
                int mid = r + l >> 1;
                if(a[mid].x > b[i].y - b[i].x){
                    r = mid - 1;
                    it = mid;
                }
                else l = mid + 1;
            }
//             cout << i << ' ' << it << endl;
            if(it > n) ans += b[i].z;
            else adj[it][i] += b[i].z;
        }
    }
//    memset(dp, -63, sizeof dp);
//    dp[0][0] = 0;
    build(1, 0, m);
    vector<pii> tmp;
    for(int i = 1; i <= n; ++i){

        ll sum = 0;
        for(auto [j, val] : adj[i]){
//            sum += val;
             update(1, 0, m, j, m, {1, val}, oo);
//            if(i == 3) cout <<get(1, 0, m, 0, j) << ' ';
            tmp.push_back({get(1, 0, m, 0, j), j});
        }
        sort(tmp.begin(), tmp.end());
        for(auto [val, j] : tmp){
             update(1, 0, m, j, m, {0, val}, val);
        }
//        for(int j = 0; j <= m; ++j) cout << get(1, 0, m, j, j) << ' ';
//        cout << endl;
        tmp.clear();
    }
    cout << tree[1] + ans;

}
/*
5
10 2 4
1 1 1
2 1 3
1 1 1
100 1 1
1
1 3
*/

Compilation message

dishes.cpp: In function 'void build(long long int, long long int, long long int)':
dishes.cpp:26:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |         int mid = r + l >> 1;
      |                   ~~^~~
dishes.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int, std::pair<long long int, long long int>, long long int)':
dishes.cpp:49:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |     int mid = r + l >> 1;
      |               ~~^~~
dishes.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
dishes.cpp:62:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |     int mid = r + l >> 1;
      |               ~~^~~
dishes.cpp: At global scope:
dishes.cpp:71:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   71 | main(){
      | ^~~~
dishes.cpp: In function 'int main()':
dishes.cpp:84:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   84 |                 int mid = r + l >> 1;
      |                           ~~^~~
dishes.cpp:100:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  100 |                 int mid = r + l >> 1;
      |                           ~~^~~
dishes.cpp:118:12: warning: unused variable 'sum' [-Wunused-variable]
  118 |         ll sum = 0;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Correct 399 ms 97924 KB Output is correct
2 Correct 373 ms 97328 KB Output is correct
3 Correct 122 ms 75528 KB Output is correct
4 Correct 266 ms 88628 KB Output is correct
5 Correct 19 ms 47448 KB Output is correct
6 Correct 338 ms 93096 KB Output is correct
7 Correct 113 ms 65564 KB Output is correct
8 Correct 74 ms 57524 KB Output is correct
9 Correct 152 ms 76256 KB Output is correct
10 Correct 335 ms 91564 KB Output is correct
11 Correct 100 ms 71040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47452 KB Output is correct
2 Correct 19 ms 47268 KB Output is correct
3 Correct 19 ms 47320 KB Output is correct
4 Correct 20 ms 47452 KB Output is correct
5 Correct 26 ms 47304 KB Output is correct
6 Correct 27 ms 47448 KB Output is correct
7 Correct 24 ms 47448 KB Output is correct
8 Correct 22 ms 47452 KB Output is correct
9 Correct 21 ms 47452 KB Output is correct
10 Correct 21 ms 47452 KB Output is correct
11 Correct 20 ms 47452 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 21 ms 47448 KB Output is correct
14 Correct 21 ms 47392 KB Output is correct
15 Correct 27 ms 47232 KB Output is correct
16 Correct 22 ms 47452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47452 KB Output is correct
2 Correct 19 ms 47268 KB Output is correct
3 Correct 19 ms 47320 KB Output is correct
4 Correct 20 ms 47452 KB Output is correct
5 Correct 26 ms 47304 KB Output is correct
6 Correct 27 ms 47448 KB Output is correct
7 Correct 24 ms 47448 KB Output is correct
8 Correct 22 ms 47452 KB Output is correct
9 Correct 21 ms 47452 KB Output is correct
10 Correct 21 ms 47452 KB Output is correct
11 Correct 20 ms 47452 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 21 ms 47448 KB Output is correct
14 Correct 21 ms 47392 KB Output is correct
15 Correct 27 ms 47232 KB Output is correct
16 Correct 22 ms 47452 KB Output is correct
17 Correct 35 ms 47708 KB Output is correct
18 Correct 32 ms 47952 KB Output is correct
19 Correct 24 ms 47964 KB Output is correct
20 Correct 21 ms 47708 KB Output is correct
21 Correct 26 ms 47968 KB Output is correct
22 Correct 25 ms 47804 KB Output is correct
23 Correct 26 ms 47960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47452 KB Output is correct
2 Correct 19 ms 47268 KB Output is correct
3 Correct 19 ms 47320 KB Output is correct
4 Correct 20 ms 47452 KB Output is correct
5 Correct 26 ms 47304 KB Output is correct
6 Correct 27 ms 47448 KB Output is correct
7 Correct 24 ms 47448 KB Output is correct
8 Correct 22 ms 47452 KB Output is correct
9 Correct 21 ms 47452 KB Output is correct
10 Correct 21 ms 47452 KB Output is correct
11 Correct 20 ms 47452 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 21 ms 47448 KB Output is correct
14 Correct 21 ms 47392 KB Output is correct
15 Correct 27 ms 47232 KB Output is correct
16 Correct 22 ms 47452 KB Output is correct
17 Correct 35 ms 47708 KB Output is correct
18 Correct 32 ms 47952 KB Output is correct
19 Correct 24 ms 47964 KB Output is correct
20 Correct 21 ms 47708 KB Output is correct
21 Correct 26 ms 47968 KB Output is correct
22 Correct 25 ms 47804 KB Output is correct
23 Correct 26 ms 47960 KB Output is correct
24 Correct 333 ms 85840 KB Output is correct
25 Correct 363 ms 97372 KB Output is correct
26 Correct 323 ms 94080 KB Output is correct
27 Correct 342 ms 94004 KB Output is correct
28 Correct 298 ms 87892 KB Output is correct
29 Correct 128 ms 73812 KB Output is correct
30 Correct 800 ms 105692 KB Output is correct
31 Correct 186 ms 80760 KB Output is correct
32 Correct 82 ms 62668 KB Output is correct
33 Correct 499 ms 93312 KB Output is correct
34 Correct 631 ms 100832 KB Output is correct
35 Correct 823 ms 101400 KB Output is correct
36 Correct 801 ms 100452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47452 KB Output is correct
2 Correct 19 ms 47268 KB Output is correct
3 Correct 19 ms 47320 KB Output is correct
4 Correct 20 ms 47452 KB Output is correct
5 Correct 26 ms 47304 KB Output is correct
6 Correct 27 ms 47448 KB Output is correct
7 Correct 24 ms 47448 KB Output is correct
8 Correct 22 ms 47452 KB Output is correct
9 Correct 21 ms 47452 KB Output is correct
10 Correct 21 ms 47452 KB Output is correct
11 Correct 20 ms 47452 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 21 ms 47448 KB Output is correct
14 Correct 21 ms 47392 KB Output is correct
15 Correct 27 ms 47232 KB Output is correct
16 Correct 22 ms 47452 KB Output is correct
17 Correct 35 ms 47708 KB Output is correct
18 Correct 32 ms 47952 KB Output is correct
19 Correct 24 ms 47964 KB Output is correct
20 Correct 21 ms 47708 KB Output is correct
21 Correct 26 ms 47968 KB Output is correct
22 Correct 25 ms 47804 KB Output is correct
23 Correct 26 ms 47960 KB Output is correct
24 Correct 333 ms 85840 KB Output is correct
25 Correct 363 ms 97372 KB Output is correct
26 Correct 323 ms 94080 KB Output is correct
27 Correct 342 ms 94004 KB Output is correct
28 Correct 298 ms 87892 KB Output is correct
29 Correct 128 ms 73812 KB Output is correct
30 Correct 800 ms 105692 KB Output is correct
31 Correct 186 ms 80760 KB Output is correct
32 Correct 82 ms 62668 KB Output is correct
33 Correct 499 ms 93312 KB Output is correct
34 Correct 631 ms 100832 KB Output is correct
35 Correct 823 ms 101400 KB Output is correct
36 Correct 801 ms 100452 KB Output is correct
37 Correct 331 ms 96340 KB Output is correct
38 Correct 326 ms 96344 KB Output is correct
39 Correct 329 ms 93980 KB Output is correct
40 Correct 425 ms 94544 KB Output is correct
41 Correct 22 ms 47452 KB Output is correct
42 Correct 749 ms 108212 KB Output is correct
43 Correct 441 ms 95572 KB Output is correct
44 Correct 572 ms 102516 KB Output is correct
45 Correct 740 ms 103508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47452 KB Output is correct
2 Correct 19 ms 47268 KB Output is correct
3 Correct 19 ms 47320 KB Output is correct
4 Correct 20 ms 47452 KB Output is correct
5 Correct 26 ms 47304 KB Output is correct
6 Correct 27 ms 47448 KB Output is correct
7 Correct 24 ms 47448 KB Output is correct
8 Correct 22 ms 47452 KB Output is correct
9 Correct 21 ms 47452 KB Output is correct
10 Correct 21 ms 47452 KB Output is correct
11 Correct 20 ms 47452 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 21 ms 47448 KB Output is correct
14 Correct 21 ms 47392 KB Output is correct
15 Correct 27 ms 47232 KB Output is correct
16 Correct 22 ms 47452 KB Output is correct
17 Correct 35 ms 47708 KB Output is correct
18 Correct 32 ms 47952 KB Output is correct
19 Correct 24 ms 47964 KB Output is correct
20 Correct 21 ms 47708 KB Output is correct
21 Correct 26 ms 47968 KB Output is correct
22 Correct 25 ms 47804 KB Output is correct
23 Correct 26 ms 47960 KB Output is correct
24 Correct 333 ms 85840 KB Output is correct
25 Correct 363 ms 97372 KB Output is correct
26 Correct 323 ms 94080 KB Output is correct
27 Correct 342 ms 94004 KB Output is correct
28 Correct 298 ms 87892 KB Output is correct
29 Correct 128 ms 73812 KB Output is correct
30 Correct 800 ms 105692 KB Output is correct
31 Correct 186 ms 80760 KB Output is correct
32 Correct 82 ms 62668 KB Output is correct
33 Correct 499 ms 93312 KB Output is correct
34 Correct 631 ms 100832 KB Output is correct
35 Correct 823 ms 101400 KB Output is correct
36 Correct 801 ms 100452 KB Output is correct
37 Correct 331 ms 96340 KB Output is correct
38 Correct 326 ms 96344 KB Output is correct
39 Correct 329 ms 93980 KB Output is correct
40 Correct 425 ms 94544 KB Output is correct
41 Correct 22 ms 47452 KB Output is correct
42 Correct 749 ms 108212 KB Output is correct
43 Correct 441 ms 95572 KB Output is correct
44 Correct 572 ms 102516 KB Output is correct
45 Correct 740 ms 103508 KB Output is correct
46 Correct 1646 ms 290896 KB Output is correct
47 Correct 1661 ms 292436 KB Output is correct
48 Correct 1651 ms 278868 KB Output is correct
49 Correct 2167 ms 278740 KB Output is correct
50 Correct 4942 ms 352588 KB Output is correct
51 Correct 2764 ms 283416 KB Output is correct
52 Correct 3414 ms 309180 KB Output is correct
53 Correct 4803 ms 316868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 399 ms 97924 KB Output is correct
2 Correct 373 ms 97328 KB Output is correct
3 Correct 122 ms 75528 KB Output is correct
4 Correct 266 ms 88628 KB Output is correct
5 Correct 19 ms 47448 KB Output is correct
6 Correct 338 ms 93096 KB Output is correct
7 Correct 113 ms 65564 KB Output is correct
8 Correct 74 ms 57524 KB Output is correct
9 Correct 152 ms 76256 KB Output is correct
10 Correct 335 ms 91564 KB Output is correct
11 Correct 100 ms 71040 KB Output is correct
12 Correct 20 ms 47452 KB Output is correct
13 Correct 19 ms 47268 KB Output is correct
14 Correct 19 ms 47320 KB Output is correct
15 Correct 20 ms 47452 KB Output is correct
16 Correct 26 ms 47304 KB Output is correct
17 Correct 27 ms 47448 KB Output is correct
18 Correct 24 ms 47448 KB Output is correct
19 Correct 22 ms 47452 KB Output is correct
20 Correct 21 ms 47452 KB Output is correct
21 Correct 21 ms 47452 KB Output is correct
22 Correct 20 ms 47452 KB Output is correct
23 Correct 23 ms 47452 KB Output is correct
24 Correct 21 ms 47448 KB Output is correct
25 Correct 21 ms 47392 KB Output is correct
26 Correct 27 ms 47232 KB Output is correct
27 Correct 22 ms 47452 KB Output is correct
28 Correct 35 ms 47708 KB Output is correct
29 Correct 32 ms 47952 KB Output is correct
30 Correct 24 ms 47964 KB Output is correct
31 Correct 21 ms 47708 KB Output is correct
32 Correct 26 ms 47968 KB Output is correct
33 Correct 25 ms 47804 KB Output is correct
34 Correct 26 ms 47960 KB Output is correct
35 Correct 333 ms 85840 KB Output is correct
36 Correct 363 ms 97372 KB Output is correct
37 Correct 323 ms 94080 KB Output is correct
38 Correct 342 ms 94004 KB Output is correct
39 Correct 298 ms 87892 KB Output is correct
40 Correct 128 ms 73812 KB Output is correct
41 Correct 800 ms 105692 KB Output is correct
42 Correct 186 ms 80760 KB Output is correct
43 Correct 82 ms 62668 KB Output is correct
44 Correct 499 ms 93312 KB Output is correct
45 Correct 631 ms 100832 KB Output is correct
46 Correct 823 ms 101400 KB Output is correct
47 Correct 801 ms 100452 KB Output is correct
48 Correct 331 ms 96340 KB Output is correct
49 Correct 326 ms 96344 KB Output is correct
50 Correct 329 ms 93980 KB Output is correct
51 Correct 425 ms 94544 KB Output is correct
52 Correct 22 ms 47452 KB Output is correct
53 Correct 749 ms 108212 KB Output is correct
54 Correct 441 ms 95572 KB Output is correct
55 Correct 572 ms 102516 KB Output is correct
56 Correct 740 ms 103508 KB Output is correct
57 Correct 349 ms 96696 KB Output is correct
58 Correct 390 ms 96568 KB Output is correct
59 Correct 462 ms 94956 KB Output is correct
60 Correct 374 ms 94860 KB Output is correct
61 Correct 609 ms 106604 KB Output is correct
62 Correct 22 ms 47452 KB Output is correct
63 Correct 815 ms 108064 KB Output is correct
64 Correct 496 ms 97364 KB Output is correct
65 Correct 664 ms 104532 KB Output is correct
66 Correct 816 ms 103916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 399 ms 97924 KB Output is correct
2 Correct 373 ms 97328 KB Output is correct
3 Correct 122 ms 75528 KB Output is correct
4 Correct 266 ms 88628 KB Output is correct
5 Correct 19 ms 47448 KB Output is correct
6 Correct 338 ms 93096 KB Output is correct
7 Correct 113 ms 65564 KB Output is correct
8 Correct 74 ms 57524 KB Output is correct
9 Correct 152 ms 76256 KB Output is correct
10 Correct 335 ms 91564 KB Output is correct
11 Correct 100 ms 71040 KB Output is correct
12 Correct 20 ms 47452 KB Output is correct
13 Correct 19 ms 47268 KB Output is correct
14 Correct 19 ms 47320 KB Output is correct
15 Correct 20 ms 47452 KB Output is correct
16 Correct 26 ms 47304 KB Output is correct
17 Correct 27 ms 47448 KB Output is correct
18 Correct 24 ms 47448 KB Output is correct
19 Correct 22 ms 47452 KB Output is correct
20 Correct 21 ms 47452 KB Output is correct
21 Correct 21 ms 47452 KB Output is correct
22 Correct 20 ms 47452 KB Output is correct
23 Correct 23 ms 47452 KB Output is correct
24 Correct 21 ms 47448 KB Output is correct
25 Correct 21 ms 47392 KB Output is correct
26 Correct 27 ms 47232 KB Output is correct
27 Correct 22 ms 47452 KB Output is correct
28 Correct 35 ms 47708 KB Output is correct
29 Correct 32 ms 47952 KB Output is correct
30 Correct 24 ms 47964 KB Output is correct
31 Correct 21 ms 47708 KB Output is correct
32 Correct 26 ms 47968 KB Output is correct
33 Correct 25 ms 47804 KB Output is correct
34 Correct 26 ms 47960 KB Output is correct
35 Correct 333 ms 85840 KB Output is correct
36 Correct 363 ms 97372 KB Output is correct
37 Correct 323 ms 94080 KB Output is correct
38 Correct 342 ms 94004 KB Output is correct
39 Correct 298 ms 87892 KB Output is correct
40 Correct 128 ms 73812 KB Output is correct
41 Correct 800 ms 105692 KB Output is correct
42 Correct 186 ms 80760 KB Output is correct
43 Correct 82 ms 62668 KB Output is correct
44 Correct 499 ms 93312 KB Output is correct
45 Correct 631 ms 100832 KB Output is correct
46 Correct 823 ms 101400 KB Output is correct
47 Correct 801 ms 100452 KB Output is correct
48 Correct 331 ms 96340 KB Output is correct
49 Correct 326 ms 96344 KB Output is correct
50 Correct 329 ms 93980 KB Output is correct
51 Correct 425 ms 94544 KB Output is correct
52 Correct 22 ms 47452 KB Output is correct
53 Correct 749 ms 108212 KB Output is correct
54 Correct 441 ms 95572 KB Output is correct
55 Correct 572 ms 102516 KB Output is correct
56 Correct 740 ms 103508 KB Output is correct
57 Correct 1646 ms 290896 KB Output is correct
58 Correct 1661 ms 292436 KB Output is correct
59 Correct 1651 ms 278868 KB Output is correct
60 Correct 2167 ms 278740 KB Output is correct
61 Correct 4942 ms 352588 KB Output is correct
62 Correct 2764 ms 283416 KB Output is correct
63 Correct 3414 ms 309180 KB Output is correct
64 Correct 4803 ms 316868 KB Output is correct
65 Correct 349 ms 96696 KB Output is correct
66 Correct 390 ms 96568 KB Output is correct
67 Correct 462 ms 94956 KB Output is correct
68 Correct 374 ms 94860 KB Output is correct
69 Correct 609 ms 106604 KB Output is correct
70 Correct 22 ms 47452 KB Output is correct
71 Correct 815 ms 108064 KB Output is correct
72 Correct 496 ms 97364 KB Output is correct
73 Correct 664 ms 104532 KB Output is correct
74 Correct 816 ms 103916 KB Output is correct
75 Correct 1758 ms 294240 KB Output is correct
76 Correct 1769 ms 294204 KB Output is correct
77 Correct 2170 ms 281332 KB Output is correct
78 Correct 1699 ms 281024 KB Output is correct
79 Correct 4964 ms 353108 KB Output is correct
80 Correct 2490 ms 283968 KB Output is correct
81 Correct 3209 ms 311748 KB Output is correct
82 Correct 4563 ms 319828 KB Output is correct
83 Correct 4413 ms 332588 KB Output is correct