Submission #1097770

# Submission time Handle Problem Language Result Execution time Memory
1097770 2024-10-08T08:52:48 Z thangdz2k7 Two Dishes (JOI19_dishes) C++17
74 / 100
3065 ms 164688 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int N = 1e6 + 5;
const int mod = 1e9 + 7;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

int n, m;
ll a[N], b[N], s[N], t[N], p[N], q[N];
vi event[N];

const ll inf = 1e18;
ll Max[4 * N], lz[4 * N];

void update(int u, int v, ll val, bool op, int s = 1, int l = 0, int r = m){
    if (v < l || u > r) return;
    if (u <= l && r <= v){
        if (op) Max[s] += val, lz[s] += val;
        else maxl(Max[s], val);
        return;
    }

    int mid = l + r >> 1; if (!op) val -= lz[s];
    update(u, v, val, op, s << 1, l, mid);
    update(u, v, val, op, s << 1 | 1, mid + 1, r);
    Max[s] = max(Max[s << 1], Max[s << 1 | 1]) + lz[s];
}

ll get(int u, int v, int s = 1, int l = 0, int r = m){
    if (v < l || u > r) return -inf;
    if (u <= l && r <= v) return Max[s];

    int mid = l + r >> 1;
    return max(get(u, v, s << 1, l, mid), get(u, v, s << 1 | 1, mid + 1, r)) + lz[s];
}

void solve(){
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i) cin >> a[i] >> s[i] >> p[i], a[i] += a[i - 1];
    for (int i = 1; i <= m; ++ i) cin >> b[i] >> t[i] >> q[i], b[i] += b[i - 1];

    for (int i = 1; i <= n; ++ i) s[i] = upper_bound(b, b + m + 1, s[i] - a[i]) - b - 1;
    for (int i = 1; i <= m; ++ i){
        t[i] = upper_bound(a, a + n + 1, t[i] - b[i]) - a;
        event[t[i]].pb(i);
    }

    for (int i = 1; i <= 4 * m + 4; ++ i) Max[i] = -inf, lz[i] = 0;
    update(0, 0, 0, 0);

    for (int i = 1; i <= n + 1; ++ i){
        for (int j : event[i]){
            ll f = get(0, j - 1);
            update(j, j, f, 0);
        }
        if (i > n) update(m, m, get(0, m - 1), 0);
        ll f = get(0, s[i]);
        update(s[i] + 1, s[i] + 1, f, 0);
        update(0, s[i], p[i], 1);
        for (int j : event[i]) update(j, m, q[j], 1);
    }
    cout << Max[1];
}

int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message

dishes.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
dishes.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
dishes.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
dishes.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
dishes.cpp: In function 'void update(int, int, ll, bool, int, int, int)':
dishes.cpp:36:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |     int mid = l + r >> 1; if (!op) val -= lz[s];
      |               ~~^~~
dishes.cpp: In function 'll get(int, int, int, int, int)':
dishes.cpp:46:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |     int mid = l + r >> 1;
      |               ~~^~~
dishes.cpp: In function 'int main()':
dishes.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 277 ms 49744 KB Output is correct
2 Correct 284 ms 49236 KB Output is correct
3 Correct 195 ms 46796 KB Output is correct
4 Correct 241 ms 49876 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 252 ms 47836 KB Output is correct
7 Correct 131 ms 41952 KB Output is correct
8 Correct 56 ms 28496 KB Output is correct
9 Correct 196 ms 46796 KB Output is correct
10 Correct 262 ms 52040 KB Output is correct
11 Correct 171 ms 46652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 11 ms 23884 KB Output is correct
3 Correct 13 ms 23848 KB Output is correct
4 Correct 11 ms 24012 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 10 ms 23812 KB Output is correct
7 Correct 11 ms 23896 KB Output is correct
8 Correct 10 ms 23776 KB Output is correct
9 Correct 10 ms 23968 KB Output is correct
10 Correct 11 ms 23900 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23808 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23916 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 11 ms 23884 KB Output is correct
3 Correct 13 ms 23848 KB Output is correct
4 Correct 11 ms 24012 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 10 ms 23812 KB Output is correct
7 Correct 11 ms 23896 KB Output is correct
8 Correct 10 ms 23776 KB Output is correct
9 Correct 10 ms 23968 KB Output is correct
10 Correct 11 ms 23900 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23808 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23916 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 14 ms 24152 KB Output is correct
18 Correct 13 ms 24244 KB Output is correct
19 Correct 15 ms 24152 KB Output is correct
20 Correct 12 ms 24156 KB Output is correct
21 Correct 12 ms 24156 KB Output is correct
22 Correct 12 ms 24080 KB Output is correct
23 Correct 12 ms 24252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 11 ms 23884 KB Output is correct
3 Correct 13 ms 23848 KB Output is correct
4 Correct 11 ms 24012 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 10 ms 23812 KB Output is correct
7 Correct 11 ms 23896 KB Output is correct
8 Correct 10 ms 23776 KB Output is correct
9 Correct 10 ms 23968 KB Output is correct
10 Correct 11 ms 23900 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23808 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23916 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 14 ms 24152 KB Output is correct
18 Correct 13 ms 24244 KB Output is correct
19 Correct 15 ms 24152 KB Output is correct
20 Correct 12 ms 24156 KB Output is correct
21 Correct 12 ms 24156 KB Output is correct
22 Correct 12 ms 24080 KB Output is correct
23 Correct 12 ms 24252 KB Output is correct
24 Correct 231 ms 46752 KB Output is correct
25 Correct 205 ms 46800 KB Output is correct
26 Correct 227 ms 46892 KB Output is correct
27 Correct 206 ms 51920 KB Output is correct
28 Correct 243 ms 47820 KB Output is correct
29 Correct 183 ms 46796 KB Output is correct
30 Correct 408 ms 49736 KB Output is correct
31 Correct 145 ms 42000 KB Output is correct
32 Correct 56 ms 28684 KB Output is correct
33 Correct 272 ms 48436 KB Output is correct
34 Correct 354 ms 47700 KB Output is correct
35 Correct 375 ms 49748 KB Output is correct
36 Correct 375 ms 49752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 11 ms 23884 KB Output is correct
3 Correct 13 ms 23848 KB Output is correct
4 Correct 11 ms 24012 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 10 ms 23812 KB Output is correct
7 Correct 11 ms 23896 KB Output is correct
8 Correct 10 ms 23776 KB Output is correct
9 Correct 10 ms 23968 KB Output is correct
10 Correct 11 ms 23900 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23808 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23916 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 14 ms 24152 KB Output is correct
18 Correct 13 ms 24244 KB Output is correct
19 Correct 15 ms 24152 KB Output is correct
20 Correct 12 ms 24156 KB Output is correct
21 Correct 12 ms 24156 KB Output is correct
22 Correct 12 ms 24080 KB Output is correct
23 Correct 12 ms 24252 KB Output is correct
24 Correct 231 ms 46752 KB Output is correct
25 Correct 205 ms 46800 KB Output is correct
26 Correct 227 ms 46892 KB Output is correct
27 Correct 206 ms 51920 KB Output is correct
28 Correct 243 ms 47820 KB Output is correct
29 Correct 183 ms 46796 KB Output is correct
30 Correct 408 ms 49736 KB Output is correct
31 Correct 145 ms 42000 KB Output is correct
32 Correct 56 ms 28684 KB Output is correct
33 Correct 272 ms 48436 KB Output is correct
34 Correct 354 ms 47700 KB Output is correct
35 Correct 375 ms 49748 KB Output is correct
36 Correct 375 ms 49752 KB Output is correct
37 Correct 232 ms 46772 KB Output is correct
38 Correct 219 ms 52048 KB Output is correct
39 Correct 278 ms 52052 KB Output is correct
40 Correct 274 ms 52052 KB Output is correct
41 Correct 9 ms 23900 KB Output is correct
42 Correct 403 ms 49592 KB Output is correct
43 Correct 285 ms 48332 KB Output is correct
44 Correct 353 ms 47440 KB Output is correct
45 Correct 381 ms 49848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 11 ms 23884 KB Output is correct
3 Correct 13 ms 23848 KB Output is correct
4 Correct 11 ms 24012 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 10 ms 23812 KB Output is correct
7 Correct 11 ms 23896 KB Output is correct
8 Correct 10 ms 23776 KB Output is correct
9 Correct 10 ms 23968 KB Output is correct
10 Correct 11 ms 23900 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23808 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23916 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 14 ms 24152 KB Output is correct
18 Correct 13 ms 24244 KB Output is correct
19 Correct 15 ms 24152 KB Output is correct
20 Correct 12 ms 24156 KB Output is correct
21 Correct 12 ms 24156 KB Output is correct
22 Correct 12 ms 24080 KB Output is correct
23 Correct 12 ms 24252 KB Output is correct
24 Correct 231 ms 46752 KB Output is correct
25 Correct 205 ms 46800 KB Output is correct
26 Correct 227 ms 46892 KB Output is correct
27 Correct 206 ms 51920 KB Output is correct
28 Correct 243 ms 47820 KB Output is correct
29 Correct 183 ms 46796 KB Output is correct
30 Correct 408 ms 49736 KB Output is correct
31 Correct 145 ms 42000 KB Output is correct
32 Correct 56 ms 28684 KB Output is correct
33 Correct 272 ms 48436 KB Output is correct
34 Correct 354 ms 47700 KB Output is correct
35 Correct 375 ms 49748 KB Output is correct
36 Correct 375 ms 49752 KB Output is correct
37 Correct 232 ms 46772 KB Output is correct
38 Correct 219 ms 52048 KB Output is correct
39 Correct 278 ms 52052 KB Output is correct
40 Correct 274 ms 52052 KB Output is correct
41 Correct 9 ms 23900 KB Output is correct
42 Correct 403 ms 49592 KB Output is correct
43 Correct 285 ms 48332 KB Output is correct
44 Correct 353 ms 47440 KB Output is correct
45 Correct 381 ms 49848 KB Output is correct
46 Correct 1237 ms 137648 KB Output is correct
47 Correct 1154 ms 164688 KB Output is correct
48 Correct 1435 ms 164688 KB Output is correct
49 Correct 1448 ms 164688 KB Output is correct
50 Correct 3065 ms 153220 KB Output is correct
51 Correct 1729 ms 145344 KB Output is correct
52 Correct 2009 ms 136208 KB Output is correct
53 Correct 2519 ms 152916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 277 ms 49744 KB Output is correct
2 Correct 284 ms 49236 KB Output is correct
3 Correct 195 ms 46796 KB Output is correct
4 Correct 241 ms 49876 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 252 ms 47836 KB Output is correct
7 Correct 131 ms 41952 KB Output is correct
8 Correct 56 ms 28496 KB Output is correct
9 Correct 196 ms 46796 KB Output is correct
10 Correct 262 ms 52040 KB Output is correct
11 Correct 171 ms 46652 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23884 KB Output is correct
14 Correct 13 ms 23848 KB Output is correct
15 Correct 11 ms 24012 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 10 ms 23812 KB Output is correct
18 Correct 11 ms 23896 KB Output is correct
19 Correct 10 ms 23776 KB Output is correct
20 Correct 10 ms 23968 KB Output is correct
21 Correct 11 ms 23900 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 11 ms 23900 KB Output is correct
24 Correct 11 ms 23808 KB Output is correct
25 Correct 10 ms 23900 KB Output is correct
26 Correct 10 ms 23916 KB Output is correct
27 Correct 11 ms 23900 KB Output is correct
28 Correct 14 ms 24152 KB Output is correct
29 Correct 13 ms 24244 KB Output is correct
30 Correct 15 ms 24152 KB Output is correct
31 Correct 12 ms 24156 KB Output is correct
32 Correct 12 ms 24156 KB Output is correct
33 Correct 12 ms 24080 KB Output is correct
34 Correct 12 ms 24252 KB Output is correct
35 Correct 231 ms 46752 KB Output is correct
36 Correct 205 ms 46800 KB Output is correct
37 Correct 227 ms 46892 KB Output is correct
38 Correct 206 ms 51920 KB Output is correct
39 Correct 243 ms 47820 KB Output is correct
40 Correct 183 ms 46796 KB Output is correct
41 Correct 408 ms 49736 KB Output is correct
42 Correct 145 ms 42000 KB Output is correct
43 Correct 56 ms 28684 KB Output is correct
44 Correct 272 ms 48436 KB Output is correct
45 Correct 354 ms 47700 KB Output is correct
46 Correct 375 ms 49748 KB Output is correct
47 Correct 375 ms 49752 KB Output is correct
48 Correct 232 ms 46772 KB Output is correct
49 Correct 219 ms 52048 KB Output is correct
50 Correct 278 ms 52052 KB Output is correct
51 Correct 274 ms 52052 KB Output is correct
52 Correct 9 ms 23900 KB Output is correct
53 Correct 403 ms 49592 KB Output is correct
54 Correct 285 ms 48332 KB Output is correct
55 Correct 353 ms 47440 KB Output is correct
56 Correct 381 ms 49848 KB Output is correct
57 Incorrect 240 ms 46804 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 277 ms 49744 KB Output is correct
2 Correct 284 ms 49236 KB Output is correct
3 Correct 195 ms 46796 KB Output is correct
4 Correct 241 ms 49876 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 252 ms 47836 KB Output is correct
7 Correct 131 ms 41952 KB Output is correct
8 Correct 56 ms 28496 KB Output is correct
9 Correct 196 ms 46796 KB Output is correct
10 Correct 262 ms 52040 KB Output is correct
11 Correct 171 ms 46652 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23884 KB Output is correct
14 Correct 13 ms 23848 KB Output is correct
15 Correct 11 ms 24012 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 10 ms 23812 KB Output is correct
18 Correct 11 ms 23896 KB Output is correct
19 Correct 10 ms 23776 KB Output is correct
20 Correct 10 ms 23968 KB Output is correct
21 Correct 11 ms 23900 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 11 ms 23900 KB Output is correct
24 Correct 11 ms 23808 KB Output is correct
25 Correct 10 ms 23900 KB Output is correct
26 Correct 10 ms 23916 KB Output is correct
27 Correct 11 ms 23900 KB Output is correct
28 Correct 14 ms 24152 KB Output is correct
29 Correct 13 ms 24244 KB Output is correct
30 Correct 15 ms 24152 KB Output is correct
31 Correct 12 ms 24156 KB Output is correct
32 Correct 12 ms 24156 KB Output is correct
33 Correct 12 ms 24080 KB Output is correct
34 Correct 12 ms 24252 KB Output is correct
35 Correct 231 ms 46752 KB Output is correct
36 Correct 205 ms 46800 KB Output is correct
37 Correct 227 ms 46892 KB Output is correct
38 Correct 206 ms 51920 KB Output is correct
39 Correct 243 ms 47820 KB Output is correct
40 Correct 183 ms 46796 KB Output is correct
41 Correct 408 ms 49736 KB Output is correct
42 Correct 145 ms 42000 KB Output is correct
43 Correct 56 ms 28684 KB Output is correct
44 Correct 272 ms 48436 KB Output is correct
45 Correct 354 ms 47700 KB Output is correct
46 Correct 375 ms 49748 KB Output is correct
47 Correct 375 ms 49752 KB Output is correct
48 Correct 232 ms 46772 KB Output is correct
49 Correct 219 ms 52048 KB Output is correct
50 Correct 278 ms 52052 KB Output is correct
51 Correct 274 ms 52052 KB Output is correct
52 Correct 9 ms 23900 KB Output is correct
53 Correct 403 ms 49592 KB Output is correct
54 Correct 285 ms 48332 KB Output is correct
55 Correct 353 ms 47440 KB Output is correct
56 Correct 381 ms 49848 KB Output is correct
57 Correct 1237 ms 137648 KB Output is correct
58 Correct 1154 ms 164688 KB Output is correct
59 Correct 1435 ms 164688 KB Output is correct
60 Correct 1448 ms 164688 KB Output is correct
61 Correct 3065 ms 153220 KB Output is correct
62 Correct 1729 ms 145344 KB Output is correct
63 Correct 2009 ms 136208 KB Output is correct
64 Correct 2519 ms 152916 KB Output is correct
65 Incorrect 240 ms 46804 KB Output isn't correct
66 Halted 0 ms 0 KB -