답안 #1097775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097775 2024-10-08T09:04:59 Z thangdz2k7 Two Dishes (JOI19_dishes) C++17
100 / 100
2980 ms 165044 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 293 ms 49744 KB Output is correct
2 Correct 296 ms 49492 KB Output is correct
3 Correct 204 ms 46664 KB Output is correct
4 Correct 247 ms 49848 KB Output is correct
5 Correct 12 ms 23900 KB Output is correct
6 Correct 284 ms 47988 KB Output is correct
7 Correct 140 ms 41896 KB Output is correct
8 Correct 59 ms 28500 KB Output is correct
9 Correct 225 ms 46804 KB Output is correct
10 Correct 270 ms 52048 KB Output is correct
11 Correct 177 ms 46720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23896 KB Output is correct
2 Correct 11 ms 23896 KB Output is correct
3 Correct 11 ms 23980 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 11 ms 23960 KB Output is correct
7 Correct 11 ms 23828 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 10 ms 23896 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 12 ms 23976 KB Output is correct
13 Correct 11 ms 23900 KB Output is correct
14 Correct 11 ms 23900 KB Output is correct
15 Correct 10 ms 23972 KB Output is correct
16 Correct 10 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23896 KB Output is correct
2 Correct 11 ms 23896 KB Output is correct
3 Correct 11 ms 23980 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 11 ms 23960 KB Output is correct
7 Correct 11 ms 23828 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 10 ms 23896 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 12 ms 23976 KB Output is correct
13 Correct 11 ms 23900 KB Output is correct
14 Correct 11 ms 23900 KB Output is correct
15 Correct 10 ms 23972 KB Output is correct
16 Correct 10 ms 23900 KB Output is correct
17 Correct 15 ms 24160 KB Output is correct
18 Correct 12 ms 24240 KB Output is correct
19 Correct 14 ms 24156 KB Output is correct
20 Correct 12 ms 24156 KB Output is correct
21 Correct 13 ms 24156 KB Output is correct
22 Correct 13 ms 24156 KB Output is correct
23 Correct 14 ms 24156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23896 KB Output is correct
2 Correct 11 ms 23896 KB Output is correct
3 Correct 11 ms 23980 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 11 ms 23960 KB Output is correct
7 Correct 11 ms 23828 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 10 ms 23896 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 12 ms 23976 KB Output is correct
13 Correct 11 ms 23900 KB Output is correct
14 Correct 11 ms 23900 KB Output is correct
15 Correct 10 ms 23972 KB Output is correct
16 Correct 10 ms 23900 KB Output is correct
17 Correct 15 ms 24160 KB Output is correct
18 Correct 12 ms 24240 KB Output is correct
19 Correct 14 ms 24156 KB Output is correct
20 Correct 12 ms 24156 KB Output is correct
21 Correct 13 ms 24156 KB Output is correct
22 Correct 13 ms 24156 KB Output is correct
23 Correct 14 ms 24156 KB Output is correct
24 Correct 239 ms 46864 KB Output is correct
25 Correct 208 ms 46796 KB Output is correct
26 Correct 227 ms 46784 KB Output is correct
27 Correct 220 ms 52144 KB Output is correct
28 Correct 255 ms 47816 KB Output is correct
29 Correct 183 ms 46608 KB Output is correct
30 Correct 443 ms 49748 KB Output is correct
31 Correct 145 ms 41996 KB Output is correct
32 Correct 55 ms 28508 KB Output is correct
33 Correct 285 ms 48584 KB Output is correct
34 Correct 359 ms 47696 KB Output is correct
35 Correct 385 ms 49744 KB Output is correct
36 Correct 364 ms 49748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23896 KB Output is correct
2 Correct 11 ms 23896 KB Output is correct
3 Correct 11 ms 23980 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 11 ms 23960 KB Output is correct
7 Correct 11 ms 23828 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 10 ms 23896 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 12 ms 23976 KB Output is correct
13 Correct 11 ms 23900 KB Output is correct
14 Correct 11 ms 23900 KB Output is correct
15 Correct 10 ms 23972 KB Output is correct
16 Correct 10 ms 23900 KB Output is correct
17 Correct 15 ms 24160 KB Output is correct
18 Correct 12 ms 24240 KB Output is correct
19 Correct 14 ms 24156 KB Output is correct
20 Correct 12 ms 24156 KB Output is correct
21 Correct 13 ms 24156 KB Output is correct
22 Correct 13 ms 24156 KB Output is correct
23 Correct 14 ms 24156 KB Output is correct
24 Correct 239 ms 46864 KB Output is correct
25 Correct 208 ms 46796 KB Output is correct
26 Correct 227 ms 46784 KB Output is correct
27 Correct 220 ms 52144 KB Output is correct
28 Correct 255 ms 47816 KB Output is correct
29 Correct 183 ms 46608 KB Output is correct
30 Correct 443 ms 49748 KB Output is correct
31 Correct 145 ms 41996 KB Output is correct
32 Correct 55 ms 28508 KB Output is correct
33 Correct 285 ms 48584 KB Output is correct
34 Correct 359 ms 47696 KB Output is correct
35 Correct 385 ms 49744 KB Output is correct
36 Correct 364 ms 49748 KB Output is correct
37 Correct 247 ms 46784 KB Output is correct
38 Correct 240 ms 52052 KB Output is correct
39 Correct 278 ms 52052 KB Output is correct
40 Correct 283 ms 52048 KB Output is correct
41 Correct 11 ms 23900 KB Output is correct
42 Correct 417 ms 49724 KB Output is correct
43 Correct 279 ms 48328 KB Output is correct
44 Correct 337 ms 47528 KB Output is correct
45 Correct 380 ms 49744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23896 KB Output is correct
2 Correct 11 ms 23896 KB Output is correct
3 Correct 11 ms 23980 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 11 ms 23960 KB Output is correct
7 Correct 11 ms 23828 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 10 ms 23896 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 12 ms 23976 KB Output is correct
13 Correct 11 ms 23900 KB Output is correct
14 Correct 11 ms 23900 KB Output is correct
15 Correct 10 ms 23972 KB Output is correct
16 Correct 10 ms 23900 KB Output is correct
17 Correct 15 ms 24160 KB Output is correct
18 Correct 12 ms 24240 KB Output is correct
19 Correct 14 ms 24156 KB Output is correct
20 Correct 12 ms 24156 KB Output is correct
21 Correct 13 ms 24156 KB Output is correct
22 Correct 13 ms 24156 KB Output is correct
23 Correct 14 ms 24156 KB Output is correct
24 Correct 239 ms 46864 KB Output is correct
25 Correct 208 ms 46796 KB Output is correct
26 Correct 227 ms 46784 KB Output is correct
27 Correct 220 ms 52144 KB Output is correct
28 Correct 255 ms 47816 KB Output is correct
29 Correct 183 ms 46608 KB Output is correct
30 Correct 443 ms 49748 KB Output is correct
31 Correct 145 ms 41996 KB Output is correct
32 Correct 55 ms 28508 KB Output is correct
33 Correct 285 ms 48584 KB Output is correct
34 Correct 359 ms 47696 KB Output is correct
35 Correct 385 ms 49744 KB Output is correct
36 Correct 364 ms 49748 KB Output is correct
37 Correct 247 ms 46784 KB Output is correct
38 Correct 240 ms 52052 KB Output is correct
39 Correct 278 ms 52052 KB Output is correct
40 Correct 283 ms 52048 KB Output is correct
41 Correct 11 ms 23900 KB Output is correct
42 Correct 417 ms 49724 KB Output is correct
43 Correct 279 ms 48328 KB Output is correct
44 Correct 337 ms 47528 KB Output is correct
45 Correct 380 ms 49744 KB Output is correct
46 Correct 1290 ms 137640 KB Output is correct
47 Correct 1208 ms 164828 KB Output is correct
48 Correct 1486 ms 164688 KB Output is correct
49 Correct 1481 ms 164816 KB Output is correct
50 Correct 2979 ms 153168 KB Output is correct
51 Correct 1711 ms 145348 KB Output is correct
52 Correct 2047 ms 136136 KB Output is correct
53 Correct 2589 ms 152912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 293 ms 49744 KB Output is correct
2 Correct 296 ms 49492 KB Output is correct
3 Correct 204 ms 46664 KB Output is correct
4 Correct 247 ms 49848 KB Output is correct
5 Correct 12 ms 23900 KB Output is correct
6 Correct 284 ms 47988 KB Output is correct
7 Correct 140 ms 41896 KB Output is correct
8 Correct 59 ms 28500 KB Output is correct
9 Correct 225 ms 46804 KB Output is correct
10 Correct 270 ms 52048 KB Output is correct
11 Correct 177 ms 46720 KB Output is correct
12 Correct 12 ms 23896 KB Output is correct
13 Correct 11 ms 23896 KB Output is correct
14 Correct 11 ms 23980 KB Output is correct
15 Correct 11 ms 23900 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 11 ms 23960 KB Output is correct
18 Correct 11 ms 23828 KB Output is correct
19 Correct 11 ms 23900 KB Output is correct
20 Correct 11 ms 23896 KB Output is correct
21 Correct 10 ms 23896 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 12 ms 23976 KB Output is correct
24 Correct 11 ms 23900 KB Output is correct
25 Correct 11 ms 23900 KB Output is correct
26 Correct 10 ms 23972 KB Output is correct
27 Correct 10 ms 23900 KB Output is correct
28 Correct 15 ms 24160 KB Output is correct
29 Correct 12 ms 24240 KB Output is correct
30 Correct 14 ms 24156 KB Output is correct
31 Correct 12 ms 24156 KB Output is correct
32 Correct 13 ms 24156 KB Output is correct
33 Correct 13 ms 24156 KB Output is correct
34 Correct 14 ms 24156 KB Output is correct
35 Correct 239 ms 46864 KB Output is correct
36 Correct 208 ms 46796 KB Output is correct
37 Correct 227 ms 46784 KB Output is correct
38 Correct 220 ms 52144 KB Output is correct
39 Correct 255 ms 47816 KB Output is correct
40 Correct 183 ms 46608 KB Output is correct
41 Correct 443 ms 49748 KB Output is correct
42 Correct 145 ms 41996 KB Output is correct
43 Correct 55 ms 28508 KB Output is correct
44 Correct 285 ms 48584 KB Output is correct
45 Correct 359 ms 47696 KB Output is correct
46 Correct 385 ms 49744 KB Output is correct
47 Correct 364 ms 49748 KB Output is correct
48 Correct 247 ms 46784 KB Output is correct
49 Correct 240 ms 52052 KB Output is correct
50 Correct 278 ms 52052 KB Output is correct
51 Correct 283 ms 52048 KB Output is correct
52 Correct 11 ms 23900 KB Output is correct
53 Correct 417 ms 49724 KB Output is correct
54 Correct 279 ms 48328 KB Output is correct
55 Correct 337 ms 47528 KB Output is correct
56 Correct 380 ms 49744 KB Output is correct
57 Correct 251 ms 46792 KB Output is correct
58 Correct 230 ms 52048 KB Output is correct
59 Correct 292 ms 52048 KB Output is correct
60 Correct 277 ms 52012 KB Output is correct
61 Correct 420 ms 49996 KB Output is correct
62 Correct 12 ms 23900 KB Output is correct
63 Correct 414 ms 49788 KB Output is correct
64 Correct 284 ms 47908 KB Output is correct
65 Correct 370 ms 47928 KB Output is correct
66 Correct 385 ms 49748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 293 ms 49744 KB Output is correct
2 Correct 296 ms 49492 KB Output is correct
3 Correct 204 ms 46664 KB Output is correct
4 Correct 247 ms 49848 KB Output is correct
5 Correct 12 ms 23900 KB Output is correct
6 Correct 284 ms 47988 KB Output is correct
7 Correct 140 ms 41896 KB Output is correct
8 Correct 59 ms 28500 KB Output is correct
9 Correct 225 ms 46804 KB Output is correct
10 Correct 270 ms 52048 KB Output is correct
11 Correct 177 ms 46720 KB Output is correct
12 Correct 12 ms 23896 KB Output is correct
13 Correct 11 ms 23896 KB Output is correct
14 Correct 11 ms 23980 KB Output is correct
15 Correct 11 ms 23900 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 11 ms 23960 KB Output is correct
18 Correct 11 ms 23828 KB Output is correct
19 Correct 11 ms 23900 KB Output is correct
20 Correct 11 ms 23896 KB Output is correct
21 Correct 10 ms 23896 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 12 ms 23976 KB Output is correct
24 Correct 11 ms 23900 KB Output is correct
25 Correct 11 ms 23900 KB Output is correct
26 Correct 10 ms 23972 KB Output is correct
27 Correct 10 ms 23900 KB Output is correct
28 Correct 15 ms 24160 KB Output is correct
29 Correct 12 ms 24240 KB Output is correct
30 Correct 14 ms 24156 KB Output is correct
31 Correct 12 ms 24156 KB Output is correct
32 Correct 13 ms 24156 KB Output is correct
33 Correct 13 ms 24156 KB Output is correct
34 Correct 14 ms 24156 KB Output is correct
35 Correct 239 ms 46864 KB Output is correct
36 Correct 208 ms 46796 KB Output is correct
37 Correct 227 ms 46784 KB Output is correct
38 Correct 220 ms 52144 KB Output is correct
39 Correct 255 ms 47816 KB Output is correct
40 Correct 183 ms 46608 KB Output is correct
41 Correct 443 ms 49748 KB Output is correct
42 Correct 145 ms 41996 KB Output is correct
43 Correct 55 ms 28508 KB Output is correct
44 Correct 285 ms 48584 KB Output is correct
45 Correct 359 ms 47696 KB Output is correct
46 Correct 385 ms 49744 KB Output is correct
47 Correct 364 ms 49748 KB Output is correct
48 Correct 247 ms 46784 KB Output is correct
49 Correct 240 ms 52052 KB Output is correct
50 Correct 278 ms 52052 KB Output is correct
51 Correct 283 ms 52048 KB Output is correct
52 Correct 11 ms 23900 KB Output is correct
53 Correct 417 ms 49724 KB Output is correct
54 Correct 279 ms 48328 KB Output is correct
55 Correct 337 ms 47528 KB Output is correct
56 Correct 380 ms 49744 KB Output is correct
57 Correct 1290 ms 137640 KB Output is correct
58 Correct 1208 ms 164828 KB Output is correct
59 Correct 1486 ms 164688 KB Output is correct
60 Correct 1481 ms 164816 KB Output is correct
61 Correct 2979 ms 153168 KB Output is correct
62 Correct 1711 ms 145348 KB Output is correct
63 Correct 2047 ms 136136 KB Output is correct
64 Correct 2589 ms 152912 KB Output is correct
65 Correct 251 ms 46792 KB Output is correct
66 Correct 230 ms 52048 KB Output is correct
67 Correct 292 ms 52048 KB Output is correct
68 Correct 277 ms 52012 KB Output is correct
69 Correct 420 ms 49996 KB Output is correct
70 Correct 12 ms 23900 KB Output is correct
71 Correct 414 ms 49788 KB Output is correct
72 Correct 284 ms 47908 KB Output is correct
73 Correct 370 ms 47928 KB Output is correct
74 Correct 385 ms 49748 KB Output is correct
75 Correct 1387 ms 137468 KB Output is correct
76 Correct 1172 ms 164692 KB Output is correct
77 Correct 1460 ms 164820 KB Output is correct
78 Correct 1397 ms 165044 KB Output is correct
79 Correct 2980 ms 153324 KB Output is correct
80 Correct 1789 ms 141352 KB Output is correct
81 Correct 2189 ms 142484 KB Output is correct
82 Correct 2770 ms 153144 KB Output is correct
83 Correct 2774 ms 152396 KB Output is correct