Submission #365855

# Submission time Handle Problem Language Result Execution time Memory
365855 2021-02-12T13:00:28 Z Kazalika Two Dishes (JOI19_dishes) C++14
100 / 100
7155 ms 273368 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 1e6 + 5;
const ll inf = 1e18;

ll sgt[N << 2], add[N << 2];

void push(int t, int l, int r) {
  if (add[t]) {
    sgt[t] += add[t];
    if (l < r) {
      add[t << 1] += add[t];
      add[t << 1 | 1] += add[t];
    }
    add[t] = 0;
  }
}

void upd(int t, int l, int r, int x, ll val) {
  push(t, l, r);
  if (x < l || x > r)
    return;
  if (l == r) {
    sgt[t] = max(sgt[t], val);
    return;
  }
  int md = (l + r) >> 1;
  upd(t << 1, l, md, x, val);
  upd(t << 1 | 1, md + 1, r, x, val);
  sgt[t] = max(sgt[t << 1], sgt[t << 1 | 1]);
}

void add_range(int t, int l, int r, int x, int y, ll val) {
  push(t, l, r);
  if (l > y || r < x || l > r)
    return;
  if (l >= x && r <= y) {
    add[t] = val;
    push(t, l, r);
    return;
  }
  int md = (l + r) >> 1;
  add_range(t << 1, l, md, x, y, val);
  add_range(t << 1 | 1, md + 1, r, x, y, val);
  sgt[t] = max(sgt[t << 1], sgt[t << 1 | 1]);
}

ll get_max(int t, int l, int r, int x, int y) {
  push(t, l, r);
  if (l > y || r < x || l > r)
    return -inf;
  if (l >= x && r <= y)
    return sgt[t];
  int md = (l + r) >> 1;
  return max(get_max(t << 1, l, md, x, y), get_max(t << 1 | 1, md + 1, r, x, y));
}

int a[N], b[N];
ll s[N], t[N];
int p[N], q[N];
ll sa[N], sb[N];
map<pair<int, int>, ll> qq;



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> s[i] >> p[i];
    sa[i] = (i ? sa[i - 1] : 0) + a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i] >> t[i] >> q[i];
    sb[i] = (i ? sb[i - 1] : 0) + b[i];
  }
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    if (sa[i] > s[i])
      continue;
    if (sa[i] + sb[m - 1] <= s[i])
      sum += p[i];
    else {
      int nw = upper_bound(sb, sb + m, s[i] - sa[i]) - sb;
      qq[{(i + 1) - 1, -nw - 1}] += p[i];
    }
  }
  for (int i = 0; i < m; ++i) {
    if (sb[i] > t[i])
      continue;
    if (sb[i] + sa[n - 1] <= t[i])
      sum += q[i];
    else {
      int nw = upper_bound(sa, sa + n, t[i] - sb[i]) - sa;
      sum += q[i];
      qq[{nw, -(i + 1)}] -= q[i];
    }
  }
  for (auto &pt : qq) {
    int y = -pt.first.second;
    ll val = pt.second;
    ll nw = get_max(1, 0, N - 1, 0, y - 1);
    upd(1, 0, N - 1, y, nw);
    add_range(1, 0, N - 1, 0, y - 1, val);
  }
  push(0, 0, N - 1);
  ll ans = sgt[1] + sum;
  cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 473 ms 30828 KB Output is correct
2 Correct 458 ms 30024 KB Output is correct
3 Correct 157 ms 9824 KB Output is correct
4 Correct 352 ms 21740 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 403 ms 26104 KB Output is correct
7 Correct 81 ms 5228 KB Output is correct
8 Correct 82 ms 5136 KB Output is correct
9 Correct 161 ms 9836 KB Output is correct
10 Correct 408 ms 29088 KB Output is correct
11 Correct 114 ms 9836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 6 ms 796 KB Output is correct
18 Correct 6 ms 876 KB Output is correct
19 Correct 9 ms 1052 KB Output is correct
20 Correct 6 ms 1012 KB Output is correct
21 Correct 6 ms 1004 KB Output is correct
22 Correct 7 ms 1004 KB Output is correct
23 Correct 9 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 6 ms 796 KB Output is correct
18 Correct 6 ms 876 KB Output is correct
19 Correct 9 ms 1052 KB Output is correct
20 Correct 6 ms 1012 KB Output is correct
21 Correct 6 ms 1004 KB Output is correct
22 Correct 7 ms 1004 KB Output is correct
23 Correct 9 ms 1004 KB Output is correct
24 Correct 391 ms 33004 KB Output is correct
25 Correct 434 ms 39608 KB Output is correct
26 Correct 390 ms 39752 KB Output is correct
27 Correct 400 ms 39788 KB Output is correct
28 Correct 379 ms 33644 KB Output is correct
29 Correct 202 ms 21228 KB Output is correct
30 Correct 1123 ms 51364 KB Output is correct
31 Correct 188 ms 23276 KB Output is correct
32 Correct 167 ms 16876 KB Output is correct
33 Correct 621 ms 39148 KB Output is correct
34 Correct 823 ms 46180 KB Output is correct
35 Correct 1036 ms 45452 KB Output is correct
36 Correct 1004 ms 44524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 6 ms 796 KB Output is correct
18 Correct 6 ms 876 KB Output is correct
19 Correct 9 ms 1052 KB Output is correct
20 Correct 6 ms 1012 KB Output is correct
21 Correct 6 ms 1004 KB Output is correct
22 Correct 7 ms 1004 KB Output is correct
23 Correct 9 ms 1004 KB Output is correct
24 Correct 391 ms 33004 KB Output is correct
25 Correct 434 ms 39608 KB Output is correct
26 Correct 390 ms 39752 KB Output is correct
27 Correct 400 ms 39788 KB Output is correct
28 Correct 379 ms 33644 KB Output is correct
29 Correct 202 ms 21228 KB Output is correct
30 Correct 1123 ms 51364 KB Output is correct
31 Correct 188 ms 23276 KB Output is correct
32 Correct 167 ms 16876 KB Output is correct
33 Correct 621 ms 39148 KB Output is correct
34 Correct 823 ms 46180 KB Output is correct
35 Correct 1036 ms 45452 KB Output is correct
36 Correct 1004 ms 44524 KB Output is correct
37 Correct 404 ms 42732 KB Output is correct
38 Correct 405 ms 42732 KB Output is correct
39 Correct 424 ms 40172 KB Output is correct
40 Correct 425 ms 40044 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1100 ms 54476 KB Output is correct
43 Correct 604 ms 41836 KB Output is correct
44 Correct 822 ms 48620 KB Output is correct
45 Correct 1016 ms 48748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 6 ms 796 KB Output is correct
18 Correct 6 ms 876 KB Output is correct
19 Correct 9 ms 1052 KB Output is correct
20 Correct 6 ms 1012 KB Output is correct
21 Correct 6 ms 1004 KB Output is correct
22 Correct 7 ms 1004 KB Output is correct
23 Correct 9 ms 1004 KB Output is correct
24 Correct 391 ms 33004 KB Output is correct
25 Correct 434 ms 39608 KB Output is correct
26 Correct 390 ms 39752 KB Output is correct
27 Correct 400 ms 39788 KB Output is correct
28 Correct 379 ms 33644 KB Output is correct
29 Correct 202 ms 21228 KB Output is correct
30 Correct 1123 ms 51364 KB Output is correct
31 Correct 188 ms 23276 KB Output is correct
32 Correct 167 ms 16876 KB Output is correct
33 Correct 621 ms 39148 KB Output is correct
34 Correct 823 ms 46180 KB Output is correct
35 Correct 1036 ms 45452 KB Output is correct
36 Correct 1004 ms 44524 KB Output is correct
37 Correct 404 ms 42732 KB Output is correct
38 Correct 405 ms 42732 KB Output is correct
39 Correct 424 ms 40172 KB Output is correct
40 Correct 425 ms 40044 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1100 ms 54476 KB Output is correct
43 Correct 604 ms 41836 KB Output is correct
44 Correct 822 ms 48620 KB Output is correct
45 Correct 1016 ms 48748 KB Output is correct
46 Correct 2084 ms 195248 KB Output is correct
47 Correct 2045 ms 194028 KB Output is correct
48 Correct 2163 ms 199204 KB Output is correct
49 Correct 2183 ms 192900 KB Output is correct
50 Correct 7025 ms 253792 KB Output is correct
51 Correct 3627 ms 185136 KB Output is correct
52 Correct 4764 ms 207460 KB Output is correct
53 Correct 6517 ms 237308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 473 ms 30828 KB Output is correct
2 Correct 458 ms 30024 KB Output is correct
3 Correct 157 ms 9824 KB Output is correct
4 Correct 352 ms 21740 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 403 ms 26104 KB Output is correct
7 Correct 81 ms 5228 KB Output is correct
8 Correct 82 ms 5136 KB Output is correct
9 Correct 161 ms 9836 KB Output is correct
10 Correct 408 ms 29088 KB Output is correct
11 Correct 114 ms 9836 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 6 ms 796 KB Output is correct
29 Correct 6 ms 876 KB Output is correct
30 Correct 9 ms 1052 KB Output is correct
31 Correct 6 ms 1012 KB Output is correct
32 Correct 6 ms 1004 KB Output is correct
33 Correct 7 ms 1004 KB Output is correct
34 Correct 9 ms 1004 KB Output is correct
35 Correct 391 ms 33004 KB Output is correct
36 Correct 434 ms 39608 KB Output is correct
37 Correct 390 ms 39752 KB Output is correct
38 Correct 400 ms 39788 KB Output is correct
39 Correct 379 ms 33644 KB Output is correct
40 Correct 202 ms 21228 KB Output is correct
41 Correct 1123 ms 51364 KB Output is correct
42 Correct 188 ms 23276 KB Output is correct
43 Correct 167 ms 16876 KB Output is correct
44 Correct 621 ms 39148 KB Output is correct
45 Correct 823 ms 46180 KB Output is correct
46 Correct 1036 ms 45452 KB Output is correct
47 Correct 1004 ms 44524 KB Output is correct
48 Correct 404 ms 42732 KB Output is correct
49 Correct 405 ms 42732 KB Output is correct
50 Correct 424 ms 40172 KB Output is correct
51 Correct 425 ms 40044 KB Output is correct
52 Correct 1 ms 492 KB Output is correct
53 Correct 1100 ms 54476 KB Output is correct
54 Correct 604 ms 41836 KB Output is correct
55 Correct 822 ms 48620 KB Output is correct
56 Correct 1016 ms 48748 KB Output is correct
57 Correct 438 ms 43244 KB Output is correct
58 Correct 446 ms 43164 KB Output is correct
59 Correct 441 ms 41196 KB Output is correct
60 Correct 437 ms 41068 KB Output is correct
61 Correct 1032 ms 52460 KB Output is correct
62 Correct 1 ms 492 KB Output is correct
63 Correct 1058 ms 54716 KB Output is correct
64 Correct 632 ms 41648 KB Output is correct
65 Correct 804 ms 49236 KB Output is correct
66 Correct 983 ms 47840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 473 ms 30828 KB Output is correct
2 Correct 458 ms 30024 KB Output is correct
3 Correct 157 ms 9824 KB Output is correct
4 Correct 352 ms 21740 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 403 ms 26104 KB Output is correct
7 Correct 81 ms 5228 KB Output is correct
8 Correct 82 ms 5136 KB Output is correct
9 Correct 161 ms 9836 KB Output is correct
10 Correct 408 ms 29088 KB Output is correct
11 Correct 114 ms 9836 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 6 ms 796 KB Output is correct
29 Correct 6 ms 876 KB Output is correct
30 Correct 9 ms 1052 KB Output is correct
31 Correct 6 ms 1012 KB Output is correct
32 Correct 6 ms 1004 KB Output is correct
33 Correct 7 ms 1004 KB Output is correct
34 Correct 9 ms 1004 KB Output is correct
35 Correct 391 ms 33004 KB Output is correct
36 Correct 434 ms 39608 KB Output is correct
37 Correct 390 ms 39752 KB Output is correct
38 Correct 400 ms 39788 KB Output is correct
39 Correct 379 ms 33644 KB Output is correct
40 Correct 202 ms 21228 KB Output is correct
41 Correct 1123 ms 51364 KB Output is correct
42 Correct 188 ms 23276 KB Output is correct
43 Correct 167 ms 16876 KB Output is correct
44 Correct 621 ms 39148 KB Output is correct
45 Correct 823 ms 46180 KB Output is correct
46 Correct 1036 ms 45452 KB Output is correct
47 Correct 1004 ms 44524 KB Output is correct
48 Correct 404 ms 42732 KB Output is correct
49 Correct 405 ms 42732 KB Output is correct
50 Correct 424 ms 40172 KB Output is correct
51 Correct 425 ms 40044 KB Output is correct
52 Correct 1 ms 492 KB Output is correct
53 Correct 1100 ms 54476 KB Output is correct
54 Correct 604 ms 41836 KB Output is correct
55 Correct 822 ms 48620 KB Output is correct
56 Correct 1016 ms 48748 KB Output is correct
57 Correct 2084 ms 195248 KB Output is correct
58 Correct 2045 ms 194028 KB Output is correct
59 Correct 2163 ms 199204 KB Output is correct
60 Correct 2183 ms 192900 KB Output is correct
61 Correct 7025 ms 253792 KB Output is correct
62 Correct 3627 ms 185136 KB Output is correct
63 Correct 4764 ms 207460 KB Output is correct
64 Correct 6517 ms 237308 KB Output is correct
65 Correct 438 ms 43244 KB Output is correct
66 Correct 446 ms 43164 KB Output is correct
67 Correct 441 ms 41196 KB Output is correct
68 Correct 437 ms 41068 KB Output is correct
69 Correct 1032 ms 52460 KB Output is correct
70 Correct 1 ms 492 KB Output is correct
71 Correct 1058 ms 54716 KB Output is correct
72 Correct 632 ms 41648 KB Output is correct
73 Correct 804 ms 49236 KB Output is correct
74 Correct 983 ms 47840 KB Output is correct
75 Correct 2062 ms 214568 KB Output is correct
76 Correct 2091 ms 214800 KB Output is correct
77 Correct 2259 ms 201732 KB Output is correct
78 Correct 2220 ms 201812 KB Output is correct
79 Correct 7155 ms 273368 KB Output is correct
80 Correct 3675 ms 202604 KB Output is correct
81 Correct 4835 ms 231940 KB Output is correct
82 Correct 7012 ms 240040 KB Output is correct
83 Correct 6613 ms 251684 KB Output is correct