답안 #1097769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097769 2024-10-08T08:51:20 Z thangdz2k7 Two Dishes (JOI19_dishes) C++17
100 / 100
2982 ms 236416 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 << get(m, m);
}

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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 284 ms 49676 KB Output is correct
2 Correct 282 ms 49232 KB Output is correct
3 Correct 193 ms 46800 KB Output is correct
4 Correct 231 ms 49876 KB Output is correct
5 Correct 10 ms 24152 KB Output is correct
6 Correct 253 ms 47828 KB Output is correct
7 Correct 130 ms 41932 KB Output is correct
8 Correct 61 ms 28656 KB Output is correct
9 Correct 202 ms 46796 KB Output is correct
10 Correct 270 ms 51948 KB Output is correct
11 Correct 169 ms 46624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 11 ms 24004 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 10 ms 23900 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 10 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23900 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 10 ms 23900 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 11 ms 24004 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 10 ms 23900 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 10 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23900 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 10 ms 23900 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 12 ms 24156 KB Output is correct
18 Correct 11 ms 24156 KB Output is correct
19 Correct 12 ms 24260 KB Output is correct
20 Correct 11 ms 24152 KB Output is correct
21 Correct 12 ms 24024 KB Output is correct
22 Correct 11 ms 24156 KB Output is correct
23 Correct 11 ms 24264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 11 ms 24004 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 10 ms 23900 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 10 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23900 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 10 ms 23900 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 12 ms 24156 KB Output is correct
18 Correct 11 ms 24156 KB Output is correct
19 Correct 12 ms 24260 KB Output is correct
20 Correct 11 ms 24152 KB Output is correct
21 Correct 12 ms 24024 KB Output is correct
22 Correct 11 ms 24156 KB Output is correct
23 Correct 11 ms 24264 KB Output is correct
24 Correct 220 ms 46792 KB Output is correct
25 Correct 193 ms 46700 KB Output is correct
26 Correct 224 ms 46792 KB Output is correct
27 Correct 212 ms 52048 KB Output is correct
28 Correct 245 ms 47784 KB Output is correct
29 Correct 184 ms 46772 KB Output is correct
30 Correct 415 ms 49752 KB Output is correct
31 Correct 145 ms 42000 KB Output is correct
32 Correct 54 ms 28500 KB Output is correct
33 Correct 279 ms 48372 KB Output is correct
34 Correct 340 ms 47700 KB Output is correct
35 Correct 377 ms 49764 KB Output is correct
36 Correct 368 ms 49744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 11 ms 24004 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 10 ms 23900 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 10 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23900 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 10 ms 23900 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 12 ms 24156 KB Output is correct
18 Correct 11 ms 24156 KB Output is correct
19 Correct 12 ms 24260 KB Output is correct
20 Correct 11 ms 24152 KB Output is correct
21 Correct 12 ms 24024 KB Output is correct
22 Correct 11 ms 24156 KB Output is correct
23 Correct 11 ms 24264 KB Output is correct
24 Correct 220 ms 46792 KB Output is correct
25 Correct 193 ms 46700 KB Output is correct
26 Correct 224 ms 46792 KB Output is correct
27 Correct 212 ms 52048 KB Output is correct
28 Correct 245 ms 47784 KB Output is correct
29 Correct 184 ms 46772 KB Output is correct
30 Correct 415 ms 49752 KB Output is correct
31 Correct 145 ms 42000 KB Output is correct
32 Correct 54 ms 28500 KB Output is correct
33 Correct 279 ms 48372 KB Output is correct
34 Correct 340 ms 47700 KB Output is correct
35 Correct 377 ms 49764 KB Output is correct
36 Correct 368 ms 49744 KB Output is correct
37 Correct 244 ms 46728 KB Output is correct
38 Correct 235 ms 51932 KB Output is correct
39 Correct 283 ms 52048 KB Output is correct
40 Correct 278 ms 52052 KB Output is correct
41 Correct 10 ms 23900 KB Output is correct
42 Correct 433 ms 49816 KB Output is correct
43 Correct 310 ms 48328 KB Output is correct
44 Correct 350 ms 47444 KB Output is correct
45 Correct 430 ms 49744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 11 ms 24004 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 10 ms 23900 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 10 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23900 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 10 ms 23900 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 12 ms 24156 KB Output is correct
18 Correct 11 ms 24156 KB Output is correct
19 Correct 12 ms 24260 KB Output is correct
20 Correct 11 ms 24152 KB Output is correct
21 Correct 12 ms 24024 KB Output is correct
22 Correct 11 ms 24156 KB Output is correct
23 Correct 11 ms 24264 KB Output is correct
24 Correct 220 ms 46792 KB Output is correct
25 Correct 193 ms 46700 KB Output is correct
26 Correct 224 ms 46792 KB Output is correct
27 Correct 212 ms 52048 KB Output is correct
28 Correct 245 ms 47784 KB Output is correct
29 Correct 184 ms 46772 KB Output is correct
30 Correct 415 ms 49752 KB Output is correct
31 Correct 145 ms 42000 KB Output is correct
32 Correct 54 ms 28500 KB Output is correct
33 Correct 279 ms 48372 KB Output is correct
34 Correct 340 ms 47700 KB Output is correct
35 Correct 377 ms 49764 KB Output is correct
36 Correct 368 ms 49744 KB Output is correct
37 Correct 244 ms 46728 KB Output is correct
38 Correct 235 ms 51932 KB Output is correct
39 Correct 283 ms 52048 KB Output is correct
40 Correct 278 ms 52052 KB Output is correct
41 Correct 10 ms 23900 KB Output is correct
42 Correct 433 ms 49816 KB Output is correct
43 Correct 310 ms 48328 KB Output is correct
44 Correct 350 ms 47444 KB Output is correct
45 Correct 430 ms 49744 KB Output is correct
46 Correct 1297 ms 137648 KB Output is correct
47 Correct 1222 ms 164816 KB Output is correct
48 Correct 1455 ms 164816 KB Output is correct
49 Correct 1498 ms 164736 KB Output is correct
50 Correct 2908 ms 153216 KB Output is correct
51 Correct 1769 ms 145432 KB Output is correct
52 Correct 2028 ms 136232 KB Output is correct
53 Correct 2572 ms 152880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 284 ms 49676 KB Output is correct
2 Correct 282 ms 49232 KB Output is correct
3 Correct 193 ms 46800 KB Output is correct
4 Correct 231 ms 49876 KB Output is correct
5 Correct 10 ms 24152 KB Output is correct
6 Correct 253 ms 47828 KB Output is correct
7 Correct 130 ms 41932 KB Output is correct
8 Correct 61 ms 28656 KB Output is correct
9 Correct 202 ms 46796 KB Output is correct
10 Correct 270 ms 51948 KB Output is correct
11 Correct 169 ms 46624 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 24004 KB Output is correct
14 Correct 11 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 10 ms 23900 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 10 ms 23900 KB Output is correct
19 Correct 10 ms 23900 KB Output is correct
20 Correct 10 ms 23900 KB Output is correct
21 Correct 10 ms 23900 KB Output is correct
22 Correct 10 ms 23900 KB Output is correct
23 Correct 10 ms 23900 KB Output is correct
24 Correct 10 ms 23900 KB Output is correct
25 Correct 10 ms 23900 KB Output is correct
26 Correct 10 ms 23900 KB Output is correct
27 Correct 9 ms 23900 KB Output is correct
28 Correct 12 ms 24156 KB Output is correct
29 Correct 11 ms 24156 KB Output is correct
30 Correct 12 ms 24260 KB Output is correct
31 Correct 11 ms 24152 KB Output is correct
32 Correct 12 ms 24024 KB Output is correct
33 Correct 11 ms 24156 KB Output is correct
34 Correct 11 ms 24264 KB Output is correct
35 Correct 220 ms 46792 KB Output is correct
36 Correct 193 ms 46700 KB Output is correct
37 Correct 224 ms 46792 KB Output is correct
38 Correct 212 ms 52048 KB Output is correct
39 Correct 245 ms 47784 KB Output is correct
40 Correct 184 ms 46772 KB Output is correct
41 Correct 415 ms 49752 KB Output is correct
42 Correct 145 ms 42000 KB Output is correct
43 Correct 54 ms 28500 KB Output is correct
44 Correct 279 ms 48372 KB Output is correct
45 Correct 340 ms 47700 KB Output is correct
46 Correct 377 ms 49764 KB Output is correct
47 Correct 368 ms 49744 KB Output is correct
48 Correct 244 ms 46728 KB Output is correct
49 Correct 235 ms 51932 KB Output is correct
50 Correct 283 ms 52048 KB Output is correct
51 Correct 278 ms 52052 KB Output is correct
52 Correct 10 ms 23900 KB Output is correct
53 Correct 433 ms 49816 KB Output is correct
54 Correct 310 ms 48328 KB Output is correct
55 Correct 350 ms 47444 KB Output is correct
56 Correct 430 ms 49744 KB Output is correct
57 Correct 235 ms 46736 KB Output is correct
58 Correct 226 ms 66132 KB Output is correct
59 Correct 281 ms 64380 KB Output is correct
60 Correct 284 ms 64072 KB Output is correct
61 Correct 426 ms 60748 KB Output is correct
62 Correct 10 ms 23896 KB Output is correct
63 Correct 438 ms 63660 KB Output is correct
64 Correct 297 ms 61384 KB Output is correct
65 Correct 371 ms 61644 KB Output is correct
66 Correct 400 ms 57172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 284 ms 49676 KB Output is correct
2 Correct 282 ms 49232 KB Output is correct
3 Correct 193 ms 46800 KB Output is correct
4 Correct 231 ms 49876 KB Output is correct
5 Correct 10 ms 24152 KB Output is correct
6 Correct 253 ms 47828 KB Output is correct
7 Correct 130 ms 41932 KB Output is correct
8 Correct 61 ms 28656 KB Output is correct
9 Correct 202 ms 46796 KB Output is correct
10 Correct 270 ms 51948 KB Output is correct
11 Correct 169 ms 46624 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 24004 KB Output is correct
14 Correct 11 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 10 ms 23900 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 10 ms 23900 KB Output is correct
19 Correct 10 ms 23900 KB Output is correct
20 Correct 10 ms 23900 KB Output is correct
21 Correct 10 ms 23900 KB Output is correct
22 Correct 10 ms 23900 KB Output is correct
23 Correct 10 ms 23900 KB Output is correct
24 Correct 10 ms 23900 KB Output is correct
25 Correct 10 ms 23900 KB Output is correct
26 Correct 10 ms 23900 KB Output is correct
27 Correct 9 ms 23900 KB Output is correct
28 Correct 12 ms 24156 KB Output is correct
29 Correct 11 ms 24156 KB Output is correct
30 Correct 12 ms 24260 KB Output is correct
31 Correct 11 ms 24152 KB Output is correct
32 Correct 12 ms 24024 KB Output is correct
33 Correct 11 ms 24156 KB Output is correct
34 Correct 11 ms 24264 KB Output is correct
35 Correct 220 ms 46792 KB Output is correct
36 Correct 193 ms 46700 KB Output is correct
37 Correct 224 ms 46792 KB Output is correct
38 Correct 212 ms 52048 KB Output is correct
39 Correct 245 ms 47784 KB Output is correct
40 Correct 184 ms 46772 KB Output is correct
41 Correct 415 ms 49752 KB Output is correct
42 Correct 145 ms 42000 KB Output is correct
43 Correct 54 ms 28500 KB Output is correct
44 Correct 279 ms 48372 KB Output is correct
45 Correct 340 ms 47700 KB Output is correct
46 Correct 377 ms 49764 KB Output is correct
47 Correct 368 ms 49744 KB Output is correct
48 Correct 244 ms 46728 KB Output is correct
49 Correct 235 ms 51932 KB Output is correct
50 Correct 283 ms 52048 KB Output is correct
51 Correct 278 ms 52052 KB Output is correct
52 Correct 10 ms 23900 KB Output is correct
53 Correct 433 ms 49816 KB Output is correct
54 Correct 310 ms 48328 KB Output is correct
55 Correct 350 ms 47444 KB Output is correct
56 Correct 430 ms 49744 KB Output is correct
57 Correct 1297 ms 137648 KB Output is correct
58 Correct 1222 ms 164816 KB Output is correct
59 Correct 1455 ms 164816 KB Output is correct
60 Correct 1498 ms 164736 KB Output is correct
61 Correct 2908 ms 153216 KB Output is correct
62 Correct 1769 ms 145432 KB Output is correct
63 Correct 2028 ms 136232 KB Output is correct
64 Correct 2572 ms 152880 KB Output is correct
65 Correct 235 ms 46736 KB Output is correct
66 Correct 226 ms 66132 KB Output is correct
67 Correct 281 ms 64380 KB Output is correct
68 Correct 284 ms 64072 KB Output is correct
69 Correct 426 ms 60748 KB Output is correct
70 Correct 10 ms 23896 KB Output is correct
71 Correct 438 ms 63660 KB Output is correct
72 Correct 297 ms 61384 KB Output is correct
73 Correct 371 ms 61644 KB Output is correct
74 Correct 400 ms 57172 KB Output is correct
75 Correct 1293 ms 209348 KB Output is correct
76 Correct 1209 ms 236416 KB Output is correct
77 Correct 1513 ms 223776 KB Output is correct
78 Correct 1518 ms 223676 KB Output is correct
79 Correct 2982 ms 223720 KB Output is correct
80 Correct 1743 ms 208832 KB Output is correct
81 Correct 2156 ms 209376 KB Output is correct
82 Correct 2766 ms 191344 KB Output is correct
83 Correct 2513 ms 211388 KB Output is correct