답안 #1039803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039803 2024-07-31T09:27:35 Z juicy Two Dishes (JOI19_dishes) C++17
100 / 100
2267 ms 166112 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int N = 1e6 + 5;
const long long inf = 1e18;
 
int n, m;
int p[N], q[N];
long long s[N], t[N], a[N], b[N], dp[4 * N], lz[4 * N];
 
void bld(int id = 1, int l = 0, int r = m) {
  if (l == r) {
    dp[id] = 0;
    return;
  }
  int md = (l + r) / 2;
  bld(id * 2, l, md);
  bld(id * 2 + 1, md + 1, r);
  dp[id] = -inf;
}
 
void app(int id, long long x) {
  dp[id] += x;
  lz[id] += x;
}
 
void psh(int id) {
  if (lz[id]) {
    app(id * 2, lz[id]);
    app(id * 2 + 1, lz[id]);
    lz[id] = 0;
  }
  if (dp[id] != -inf) {
    dp[id * 2] = max(dp[id * 2], dp[id]);
    dp[id * 2 + 1] = max(dp[id * 2 + 1], dp[id]);
    dp[id] = -inf;
  }
}
 
void upd(int u, int v, long long x, int id = 1, int l = 0, int r = m) {
  if (u <= l && r <= v) {
    app(id, x);
    return;
  }
  psh(id);
  int md = (l + r) / 2;
  if (u <= md) {
    upd(u, v, x, id * 2, l, md);
  }
  if (md < v) {
    upd(u, v, x, id * 2 + 1, md + 1, r);
  }
}
 
void add(int u, int v, long long x, int id = 1, int l = 0, int r = m) {
  if (u <= l && r <= v) {
    dp[id] = max(dp[id], x);
    return;
  }
  psh(id);
  int md = (l + r) / 2;
  if (u <= md) {
    add(u, v, x, id * 2, l, md);
  }
  if (md < v) {
    add(u, v, x, id * 2 + 1, md + 1, r);
  }
}
 
long long qry(int i, int id = 1, int l = 0, int r = m) {
  if (l == r) {
    return dp[id];
  }
  psh(id);
  int md = (l + r) / 2;
  if (i <= md) {
    return qry(i, id * 2, l, md);
  }
  return qry(i, id * 2 + 1, md + 1, r);
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
 
  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];
  }
  vector<array<int, 3>> cands;
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    int j = upper_bound(b, b + m + 1, s[i] - a[i]) - b;
    if (j) {
      cands.push_back({i, 1 - j, p[i]});
    }
  }
  for (int j = 1; j <= m; ++j) {
    int i = upper_bound(a, a + n + 1, t[j] - b[j]) - a;
    if (i) {
      cands.push_back({i, 1 - j, -q[j]});
      sum += q[j];
    }
  }
  sort(cands.begin(), cands.end());
  bld();
  for (auto [x, y, v] : cands) {  
    if (x > n) {
      break;
    }
    y = -y;
    upd(0, y, v);
    add(y, m, qry(y));
  }
  cout << sum + qry(m);
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 27188 KB Output is correct
2 Correct 242 ms 27724 KB Output is correct
3 Correct 170 ms 24168 KB Output is correct
4 Correct 198 ms 25488 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 236 ms 26660 KB Output is correct
7 Correct 58 ms 14276 KB Output is correct
8 Correct 57 ms 11976 KB Output is correct
9 Correct 169 ms 25132 KB Output is correct
10 Correct 237 ms 25780 KB Output is correct
11 Correct 139 ms 21660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 151 ms 23756 KB Output is correct
25 Correct 178 ms 26288 KB Output is correct
26 Correct 184 ms 26240 KB Output is correct
27 Correct 189 ms 26292 KB Output is correct
28 Correct 200 ms 26776 KB Output is correct
29 Correct 162 ms 23536 KB Output is correct
30 Correct 349 ms 27280 KB Output is correct
31 Correct 97 ms 19896 KB Output is correct
32 Correct 64 ms 10756 KB Output is correct
33 Correct 224 ms 24676 KB Output is correct
34 Correct 302 ms 27064 KB Output is correct
35 Correct 340 ms 23952 KB Output is correct
36 Correct 309 ms 23988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 151 ms 23756 KB Output is correct
25 Correct 178 ms 26288 KB Output is correct
26 Correct 184 ms 26240 KB Output is correct
27 Correct 189 ms 26292 KB Output is correct
28 Correct 200 ms 26776 KB Output is correct
29 Correct 162 ms 23536 KB Output is correct
30 Correct 349 ms 27280 KB Output is correct
31 Correct 97 ms 19896 KB Output is correct
32 Correct 64 ms 10756 KB Output is correct
33 Correct 224 ms 24676 KB Output is correct
34 Correct 302 ms 27064 KB Output is correct
35 Correct 340 ms 23952 KB Output is correct
36 Correct 309 ms 23988 KB Output is correct
37 Correct 183 ms 27720 KB Output is correct
38 Correct 206 ms 27624 KB Output is correct
39 Correct 255 ms 27352 KB Output is correct
40 Correct 242 ms 27568 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 372 ms 28300 KB Output is correct
43 Correct 236 ms 25848 KB Output is correct
44 Correct 292 ms 27824 KB Output is correct
45 Correct 343 ms 25148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 151 ms 23756 KB Output is correct
25 Correct 178 ms 26288 KB Output is correct
26 Correct 184 ms 26240 KB Output is correct
27 Correct 189 ms 26292 KB Output is correct
28 Correct 200 ms 26776 KB Output is correct
29 Correct 162 ms 23536 KB Output is correct
30 Correct 349 ms 27280 KB Output is correct
31 Correct 97 ms 19896 KB Output is correct
32 Correct 64 ms 10756 KB Output is correct
33 Correct 224 ms 24676 KB Output is correct
34 Correct 302 ms 27064 KB Output is correct
35 Correct 340 ms 23952 KB Output is correct
36 Correct 309 ms 23988 KB Output is correct
37 Correct 183 ms 27720 KB Output is correct
38 Correct 206 ms 27624 KB Output is correct
39 Correct 255 ms 27352 KB Output is correct
40 Correct 242 ms 27568 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 372 ms 28300 KB Output is correct
43 Correct 236 ms 25848 KB Output is correct
44 Correct 292 ms 27824 KB Output is correct
45 Correct 343 ms 25148 KB Output is correct
46 Correct 923 ms 125104 KB Output is correct
47 Correct 1094 ms 125104 KB Output is correct
48 Correct 1299 ms 124292 KB Output is correct
49 Correct 1278 ms 124296 KB Output is correct
50 Correct 2208 ms 130692 KB Output is correct
51 Correct 1292 ms 116424 KB Output is correct
52 Correct 1717 ms 126168 KB Output is correct
53 Correct 2066 ms 114928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 27188 KB Output is correct
2 Correct 242 ms 27724 KB Output is correct
3 Correct 170 ms 24168 KB Output is correct
4 Correct 198 ms 25488 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 236 ms 26660 KB Output is correct
7 Correct 58 ms 14276 KB Output is correct
8 Correct 57 ms 11976 KB Output is correct
9 Correct 169 ms 25132 KB Output is correct
10 Correct 237 ms 25780 KB Output is correct
11 Correct 139 ms 21660 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2512 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 360 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 151 ms 23756 KB Output is correct
36 Correct 178 ms 26288 KB Output is correct
37 Correct 184 ms 26240 KB Output is correct
38 Correct 189 ms 26292 KB Output is correct
39 Correct 200 ms 26776 KB Output is correct
40 Correct 162 ms 23536 KB Output is correct
41 Correct 349 ms 27280 KB Output is correct
42 Correct 97 ms 19896 KB Output is correct
43 Correct 64 ms 10756 KB Output is correct
44 Correct 224 ms 24676 KB Output is correct
45 Correct 302 ms 27064 KB Output is correct
46 Correct 340 ms 23952 KB Output is correct
47 Correct 309 ms 23988 KB Output is correct
48 Correct 183 ms 27720 KB Output is correct
49 Correct 206 ms 27624 KB Output is correct
50 Correct 255 ms 27352 KB Output is correct
51 Correct 242 ms 27568 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 372 ms 28300 KB Output is correct
54 Correct 236 ms 25848 KB Output is correct
55 Correct 292 ms 27824 KB Output is correct
56 Correct 343 ms 25148 KB Output is correct
57 Correct 193 ms 28096 KB Output is correct
58 Correct 211 ms 34816 KB Output is correct
59 Correct 263 ms 33692 KB Output is correct
60 Correct 256 ms 33672 KB Output is correct
61 Correct 352 ms 32520 KB Output is correct
62 Correct 1 ms 2396 KB Output is correct
63 Correct 376 ms 35056 KB Output is correct
64 Correct 242 ms 32128 KB Output is correct
65 Correct 316 ms 34488 KB Output is correct
66 Correct 329 ms 28528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 27188 KB Output is correct
2 Correct 242 ms 27724 KB Output is correct
3 Correct 170 ms 24168 KB Output is correct
4 Correct 198 ms 25488 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 236 ms 26660 KB Output is correct
7 Correct 58 ms 14276 KB Output is correct
8 Correct 57 ms 11976 KB Output is correct
9 Correct 169 ms 25132 KB Output is correct
10 Correct 237 ms 25780 KB Output is correct
11 Correct 139 ms 21660 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2512 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 360 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 151 ms 23756 KB Output is correct
36 Correct 178 ms 26288 KB Output is correct
37 Correct 184 ms 26240 KB Output is correct
38 Correct 189 ms 26292 KB Output is correct
39 Correct 200 ms 26776 KB Output is correct
40 Correct 162 ms 23536 KB Output is correct
41 Correct 349 ms 27280 KB Output is correct
42 Correct 97 ms 19896 KB Output is correct
43 Correct 64 ms 10756 KB Output is correct
44 Correct 224 ms 24676 KB Output is correct
45 Correct 302 ms 27064 KB Output is correct
46 Correct 340 ms 23952 KB Output is correct
47 Correct 309 ms 23988 KB Output is correct
48 Correct 183 ms 27720 KB Output is correct
49 Correct 206 ms 27624 KB Output is correct
50 Correct 255 ms 27352 KB Output is correct
51 Correct 242 ms 27568 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 372 ms 28300 KB Output is correct
54 Correct 236 ms 25848 KB Output is correct
55 Correct 292 ms 27824 KB Output is correct
56 Correct 343 ms 25148 KB Output is correct
57 Correct 923 ms 125104 KB Output is correct
58 Correct 1094 ms 125104 KB Output is correct
59 Correct 1299 ms 124292 KB Output is correct
60 Correct 1278 ms 124296 KB Output is correct
61 Correct 2208 ms 130692 KB Output is correct
62 Correct 1292 ms 116424 KB Output is correct
63 Correct 1717 ms 126168 KB Output is correct
64 Correct 2066 ms 114928 KB Output is correct
65 Correct 193 ms 28096 KB Output is correct
66 Correct 211 ms 34816 KB Output is correct
67 Correct 263 ms 33692 KB Output is correct
68 Correct 256 ms 33672 KB Output is correct
69 Correct 352 ms 32520 KB Output is correct
70 Correct 1 ms 2396 KB Output is correct
71 Correct 376 ms 35056 KB Output is correct
72 Correct 242 ms 32128 KB Output is correct
73 Correct 316 ms 34488 KB Output is correct
74 Correct 329 ms 28528 KB Output is correct
75 Correct 981 ms 161636 KB Output is correct
76 Correct 1122 ms 161864 KB Output is correct
77 Correct 1276 ms 154692 KB Output is correct
78 Correct 1334 ms 154700 KB Output is correct
79 Correct 2267 ms 166112 KB Output is correct
80 Correct 1300 ms 150500 KB Output is correct
81 Correct 1690 ms 159160 KB Output is correct
82 Correct 2009 ms 95620 KB Output is correct
83 Correct 2005 ms 94764 KB Output is correct