답안 #1039794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039794 2024-07-31T09:10:43 Z juicy Two Dishes (JOI19_dishes) C++17
74 / 100
2109 ms 165564 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) {  
    y = -y;
    upd(0, y, v);
    add(y, m, qry(y));
  }
  cout << sum + qry(m);
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 46624 KB Output is correct
2 Correct 238 ms 45612 KB Output is correct
3 Correct 216 ms 47280 KB Output is correct
4 Correct 202 ms 42292 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 253 ms 44968 KB Output is correct
7 Correct 109 ms 33960 KB Output is correct
8 Correct 70 ms 28608 KB Output is correct
9 Correct 221 ms 48164 KB Output is correct
10 Correct 245 ms 41388 KB Output is correct
11 Correct 206 ms 41652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 1 ms 14684 KB Output is correct
3 Correct 1 ms 14684 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 1 ms 14684 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14804 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 1 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 1 ms 14684 KB Output is correct
13 Correct 1 ms 14684 KB Output is correct
14 Correct 1 ms 14684 KB Output is correct
15 Correct 1 ms 14816 KB Output is correct
16 Correct 1 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 1 ms 14684 KB Output is correct
3 Correct 1 ms 14684 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 1 ms 14684 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14804 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 1 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 1 ms 14684 KB Output is correct
13 Correct 1 ms 14684 KB Output is correct
14 Correct 1 ms 14684 KB Output is correct
15 Correct 1 ms 14816 KB Output is correct
16 Correct 1 ms 14684 KB Output is correct
17 Correct 4 ms 15040 KB Output is correct
18 Correct 5 ms 14940 KB Output is correct
19 Correct 5 ms 14936 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 4 ms 14940 KB Output is correct
22 Correct 3 ms 14940 KB Output is correct
23 Correct 4 ms 14824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 1 ms 14684 KB Output is correct
3 Correct 1 ms 14684 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 1 ms 14684 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14804 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 1 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 1 ms 14684 KB Output is correct
13 Correct 1 ms 14684 KB Output is correct
14 Correct 1 ms 14684 KB Output is correct
15 Correct 1 ms 14816 KB Output is correct
16 Correct 1 ms 14684 KB Output is correct
17 Correct 4 ms 15040 KB Output is correct
18 Correct 5 ms 14940 KB Output is correct
19 Correct 5 ms 14936 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 4 ms 14940 KB Output is correct
22 Correct 3 ms 14940 KB Output is correct
23 Correct 4 ms 14824 KB Output is correct
24 Correct 178 ms 43188 KB Output is correct
25 Correct 184 ms 43192 KB Output is correct
26 Correct 194 ms 43444 KB Output is correct
27 Correct 188 ms 43444 KB Output is correct
28 Correct 219 ms 44188 KB Output is correct
29 Correct 183 ms 45232 KB Output is correct
30 Correct 341 ms 44584 KB Output is correct
31 Correct 122 ms 32956 KB Output is correct
32 Correct 58 ms 26560 KB Output is correct
33 Correct 207 ms 39984 KB Output is correct
34 Correct 309 ms 44288 KB Output is correct
35 Correct 342 ms 38184 KB Output is correct
36 Correct 324 ms 36120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 1 ms 14684 KB Output is correct
3 Correct 1 ms 14684 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 1 ms 14684 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14804 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 1 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 1 ms 14684 KB Output is correct
13 Correct 1 ms 14684 KB Output is correct
14 Correct 1 ms 14684 KB Output is correct
15 Correct 1 ms 14816 KB Output is correct
16 Correct 1 ms 14684 KB Output is correct
17 Correct 4 ms 15040 KB Output is correct
18 Correct 5 ms 14940 KB Output is correct
19 Correct 5 ms 14936 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 4 ms 14940 KB Output is correct
22 Correct 3 ms 14940 KB Output is correct
23 Correct 4 ms 14824 KB Output is correct
24 Correct 178 ms 43188 KB Output is correct
25 Correct 184 ms 43192 KB Output is correct
26 Correct 194 ms 43444 KB Output is correct
27 Correct 188 ms 43444 KB Output is correct
28 Correct 219 ms 44188 KB Output is correct
29 Correct 183 ms 45232 KB Output is correct
30 Correct 341 ms 44584 KB Output is correct
31 Correct 122 ms 32956 KB Output is correct
32 Correct 58 ms 26560 KB Output is correct
33 Correct 207 ms 39984 KB Output is correct
34 Correct 309 ms 44288 KB Output is correct
35 Correct 342 ms 38184 KB Output is correct
36 Correct 324 ms 36120 KB Output is correct
37 Correct 201 ms 46380 KB Output is correct
38 Correct 207 ms 46256 KB Output is correct
39 Correct 236 ms 44968 KB Output is correct
40 Correct 224 ms 44976 KB Output is correct
41 Correct 2 ms 14680 KB Output is correct
42 Correct 356 ms 47648 KB Output is correct
43 Correct 221 ms 42940 KB Output is correct
44 Correct 308 ms 47280 KB Output is correct
45 Correct 316 ms 41120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 1 ms 14684 KB Output is correct
3 Correct 1 ms 14684 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 1 ms 14684 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14804 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 1 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 1 ms 14684 KB Output is correct
13 Correct 1 ms 14684 KB Output is correct
14 Correct 1 ms 14684 KB Output is correct
15 Correct 1 ms 14816 KB Output is correct
16 Correct 1 ms 14684 KB Output is correct
17 Correct 4 ms 15040 KB Output is correct
18 Correct 5 ms 14940 KB Output is correct
19 Correct 5 ms 14936 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 4 ms 14940 KB Output is correct
22 Correct 3 ms 14940 KB Output is correct
23 Correct 4 ms 14824 KB Output is correct
24 Correct 178 ms 43188 KB Output is correct
25 Correct 184 ms 43192 KB Output is correct
26 Correct 194 ms 43444 KB Output is correct
27 Correct 188 ms 43444 KB Output is correct
28 Correct 219 ms 44188 KB Output is correct
29 Correct 183 ms 45232 KB Output is correct
30 Correct 341 ms 44584 KB Output is correct
31 Correct 122 ms 32956 KB Output is correct
32 Correct 58 ms 26560 KB Output is correct
33 Correct 207 ms 39984 KB Output is correct
34 Correct 309 ms 44288 KB Output is correct
35 Correct 342 ms 38184 KB Output is correct
36 Correct 324 ms 36120 KB Output is correct
37 Correct 201 ms 46380 KB Output is correct
38 Correct 207 ms 46256 KB Output is correct
39 Correct 236 ms 44968 KB Output is correct
40 Correct 224 ms 44976 KB Output is correct
41 Correct 2 ms 14680 KB Output is correct
42 Correct 356 ms 47648 KB Output is correct
43 Correct 221 ms 42940 KB Output is correct
44 Correct 308 ms 47280 KB Output is correct
45 Correct 316 ms 41120 KB Output is correct
46 Correct 1073 ms 159824 KB Output is correct
47 Correct 1086 ms 159740 KB Output is correct
48 Correct 1322 ms 152196 KB Output is correct
49 Correct 1261 ms 152196 KB Output is correct
50 Correct 2109 ms 165564 KB Output is correct
51 Correct 1251 ms 149600 KB Output is correct
52 Correct 1600 ms 160384 KB Output is correct
53 Correct 1948 ms 134012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 46624 KB Output is correct
2 Correct 238 ms 45612 KB Output is correct
3 Correct 216 ms 47280 KB Output is correct
4 Correct 202 ms 42292 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 253 ms 44968 KB Output is correct
7 Correct 109 ms 33960 KB Output is correct
8 Correct 70 ms 28608 KB Output is correct
9 Correct 221 ms 48164 KB Output is correct
10 Correct 245 ms 41388 KB Output is correct
11 Correct 206 ms 41652 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 1 ms 14684 KB Output is correct
14 Correct 1 ms 14684 KB Output is correct
15 Correct 1 ms 14684 KB Output is correct
16 Correct 1 ms 14684 KB Output is correct
17 Correct 2 ms 14680 KB Output is correct
18 Correct 2 ms 14804 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 1 ms 14684 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 1 ms 14684 KB Output is correct
24 Correct 1 ms 14684 KB Output is correct
25 Correct 1 ms 14684 KB Output is correct
26 Correct 1 ms 14816 KB Output is correct
27 Correct 1 ms 14684 KB Output is correct
28 Correct 4 ms 15040 KB Output is correct
29 Correct 5 ms 14940 KB Output is correct
30 Correct 5 ms 14936 KB Output is correct
31 Correct 3 ms 14940 KB Output is correct
32 Correct 4 ms 14940 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 4 ms 14824 KB Output is correct
35 Correct 178 ms 43188 KB Output is correct
36 Correct 184 ms 43192 KB Output is correct
37 Correct 194 ms 43444 KB Output is correct
38 Correct 188 ms 43444 KB Output is correct
39 Correct 219 ms 44188 KB Output is correct
40 Correct 183 ms 45232 KB Output is correct
41 Correct 341 ms 44584 KB Output is correct
42 Correct 122 ms 32956 KB Output is correct
43 Correct 58 ms 26560 KB Output is correct
44 Correct 207 ms 39984 KB Output is correct
45 Correct 309 ms 44288 KB Output is correct
46 Correct 342 ms 38184 KB Output is correct
47 Correct 324 ms 36120 KB Output is correct
48 Correct 201 ms 46380 KB Output is correct
49 Correct 207 ms 46256 KB Output is correct
50 Correct 236 ms 44968 KB Output is correct
51 Correct 224 ms 44976 KB Output is correct
52 Correct 2 ms 14680 KB Output is correct
53 Correct 356 ms 47648 KB Output is correct
54 Correct 221 ms 42940 KB Output is correct
55 Correct 308 ms 47280 KB Output is correct
56 Correct 316 ms 41120 KB Output is correct
57 Incorrect 221 ms 46768 KB Output isn't correct
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 46624 KB Output is correct
2 Correct 238 ms 45612 KB Output is correct
3 Correct 216 ms 47280 KB Output is correct
4 Correct 202 ms 42292 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 253 ms 44968 KB Output is correct
7 Correct 109 ms 33960 KB Output is correct
8 Correct 70 ms 28608 KB Output is correct
9 Correct 221 ms 48164 KB Output is correct
10 Correct 245 ms 41388 KB Output is correct
11 Correct 206 ms 41652 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 1 ms 14684 KB Output is correct
14 Correct 1 ms 14684 KB Output is correct
15 Correct 1 ms 14684 KB Output is correct
16 Correct 1 ms 14684 KB Output is correct
17 Correct 2 ms 14680 KB Output is correct
18 Correct 2 ms 14804 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 1 ms 14684 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 1 ms 14684 KB Output is correct
24 Correct 1 ms 14684 KB Output is correct
25 Correct 1 ms 14684 KB Output is correct
26 Correct 1 ms 14816 KB Output is correct
27 Correct 1 ms 14684 KB Output is correct
28 Correct 4 ms 15040 KB Output is correct
29 Correct 5 ms 14940 KB Output is correct
30 Correct 5 ms 14936 KB Output is correct
31 Correct 3 ms 14940 KB Output is correct
32 Correct 4 ms 14940 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 4 ms 14824 KB Output is correct
35 Correct 178 ms 43188 KB Output is correct
36 Correct 184 ms 43192 KB Output is correct
37 Correct 194 ms 43444 KB Output is correct
38 Correct 188 ms 43444 KB Output is correct
39 Correct 219 ms 44188 KB Output is correct
40 Correct 183 ms 45232 KB Output is correct
41 Correct 341 ms 44584 KB Output is correct
42 Correct 122 ms 32956 KB Output is correct
43 Correct 58 ms 26560 KB Output is correct
44 Correct 207 ms 39984 KB Output is correct
45 Correct 309 ms 44288 KB Output is correct
46 Correct 342 ms 38184 KB Output is correct
47 Correct 324 ms 36120 KB Output is correct
48 Correct 201 ms 46380 KB Output is correct
49 Correct 207 ms 46256 KB Output is correct
50 Correct 236 ms 44968 KB Output is correct
51 Correct 224 ms 44976 KB Output is correct
52 Correct 2 ms 14680 KB Output is correct
53 Correct 356 ms 47648 KB Output is correct
54 Correct 221 ms 42940 KB Output is correct
55 Correct 308 ms 47280 KB Output is correct
56 Correct 316 ms 41120 KB Output is correct
57 Correct 1073 ms 159824 KB Output is correct
58 Correct 1086 ms 159740 KB Output is correct
59 Correct 1322 ms 152196 KB Output is correct
60 Correct 1261 ms 152196 KB Output is correct
61 Correct 2109 ms 165564 KB Output is correct
62 Correct 1251 ms 149600 KB Output is correct
63 Correct 1600 ms 160384 KB Output is correct
64 Correct 1948 ms 134012 KB Output is correct
65 Incorrect 221 ms 46768 KB Output isn't correct
66 Halted 0 ms 0 KB -