Submission #934512

# Submission time Handle Problem Language Result Execution time Memory
934512 2024-02-27T13:40:08 Z AdamGS Two Dishes (JOI19_dishes) C++17
74 / 100
3687 ms 199524 KB
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e18+7;
const int LIM=1e6+7;
ll A[LIM], S[LIM], P[LIM];
ll B[LIM], T[LIM], Q[LIM];
ll tr[4*LIM], lazy[4*LIM], N=1;
vector<ll>V[LIM];
void spl(int v) {
  lazy[2*v]+=lazy[v];
  lazy[2*v+1]+=lazy[v];
  tr[2*v]+=lazy[v];
  tr[2*v+1]+=lazy[v];
  lazy[v]=0;
}
void upd(int v, int l, int r, int a, int b, ll x) {
  if(b<l || r<a) return;
  if(a<=l && r<=b) {
    tr[v]+=x;
    lazy[v]+=x;
    return;
  }
  if(lazy[v]) spl(v);
  int mid=(l+r)/2;
  upd(2*v, l, mid, a, b, x);
  upd(2*v+1, mid+1, r, a, b, x);
  tr[v]=max(tr[2*v], tr[2*v+1]);
}
ll cnt(int v, int l, int r, int a, int b) {
  if(b<l || r<a) return -INF;
  if(a<=l && r<=b) return tr[v];
  if(lazy[v]) spl(v);
  int mid=(l+r)/2;
  return max(cnt(2*v, l, mid, a, b), cnt(2*v+1, mid+1, r, a, b));
}
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n, m;
  cin >> n >> m;
  while(N<=m) N*=2;
  rep(i, n) {
    cin >> A[i+1] >> S[i] >> P[i];
    A[i+1]+=A[i];
  }
  rep(i, m) {
    cin >> B[i+1] >> T[i] >> Q[i];
    B[i+1]+=B[i];
    ll po=0, ko=n+1;
    while(po<ko) {
      ll sr=(po+ko)/2;
      if(A[sr]+B[i+1]<=T[i]) po=sr+1; else ko=sr;
    }
    if(po==0) Q[i]=0;
    else V[po-1].pb(i);
  }
  ll sum=0;
  rep(i, m) sum+=Q[i];
  rep(i, m+1) tr[N+i]=sum;
  for(int i=N-1; i; --i) tr[i]=max(tr[2*i], tr[2*i+1]);
  rep(i, n) {
    sort(all(V[i]));
    for(auto j : V[i]) {
      ll a=cnt(1, 0, N-1, j+1, j+1), b=cnt(1, 0, N-1, 0, j+1);
      upd(1, 0, N-1, j+1, j+1, b-a);
    }
    for(auto j : V[i]) upd(1, 0, N-1, 0, j, -Q[j]);
    ll po=0, ko=m+1;
    while(po<ko) {
      ll sr=(po+ko)/2;
      if(A[i+1]+B[sr]<=S[i]) po=sr+1; else ko=sr;
    }
    if(po==0) continue;
    if(po<=m) {
      ll a=cnt(1, 0, N-1, po, po), b=cnt(1, 0, N-1, 0, po);
      upd(1, 0, N-1, po, po, b-a);
    }
    upd(1, 0, N-1, 0, po-1, P[i]);
  }
  cout << cnt(1, 0, N-1, 0, m) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 344 ms 72052 KB Output is correct
2 Correct 328 ms 72312 KB Output is correct
3 Correct 148 ms 67780 KB Output is correct
4 Correct 264 ms 71248 KB Output is correct
5 Correct 9 ms 39596 KB Output is correct
6 Correct 294 ms 71180 KB Output is correct
7 Correct 68 ms 57836 KB Output is correct
8 Correct 59 ms 50260 KB Output is correct
9 Correct 146 ms 68656 KB Output is correct
10 Correct 335 ms 69116 KB Output is correct
11 Correct 116 ms 62776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39604 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 8 ms 39516 KB Output is correct
4 Correct 8 ms 39576 KB Output is correct
5 Correct 8 ms 39512 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 8 ms 39516 KB Output is correct
8 Correct 8 ms 39516 KB Output is correct
9 Correct 8 ms 39512 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 8 ms 39516 KB Output is correct
12 Correct 8 ms 39600 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 8 ms 39512 KB Output is correct
15 Correct 8 ms 39516 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39604 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 8 ms 39516 KB Output is correct
4 Correct 8 ms 39576 KB Output is correct
5 Correct 8 ms 39512 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 8 ms 39516 KB Output is correct
8 Correct 8 ms 39516 KB Output is correct
9 Correct 8 ms 39512 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 8 ms 39516 KB Output is correct
12 Correct 8 ms 39600 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 8 ms 39512 KB Output is correct
15 Correct 8 ms 39516 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39512 KB Output is correct
18 Correct 9 ms 39512 KB Output is correct
19 Correct 11 ms 39776 KB Output is correct
20 Correct 10 ms 39512 KB Output is correct
21 Correct 11 ms 39516 KB Output is correct
22 Correct 11 ms 39516 KB Output is correct
23 Correct 11 ms 39708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39604 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 8 ms 39516 KB Output is correct
4 Correct 8 ms 39576 KB Output is correct
5 Correct 8 ms 39512 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 8 ms 39516 KB Output is correct
8 Correct 8 ms 39516 KB Output is correct
9 Correct 8 ms 39512 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 8 ms 39516 KB Output is correct
12 Correct 8 ms 39600 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 8 ms 39512 KB Output is correct
15 Correct 8 ms 39516 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39512 KB Output is correct
18 Correct 9 ms 39512 KB Output is correct
19 Correct 11 ms 39776 KB Output is correct
20 Correct 10 ms 39512 KB Output is correct
21 Correct 11 ms 39516 KB Output is correct
22 Correct 11 ms 39516 KB Output is correct
23 Correct 11 ms 39708 KB Output is correct
24 Correct 180 ms 64632 KB Output is correct
25 Correct 221 ms 67488 KB Output is correct
26 Correct 247 ms 66468 KB Output is correct
27 Correct 263 ms 72092 KB Output is correct
28 Correct 257 ms 68208 KB Output is correct
29 Correct 129 ms 66060 KB Output is correct
30 Correct 520 ms 69972 KB Output is correct
31 Correct 110 ms 58760 KB Output is correct
32 Correct 55 ms 48624 KB Output is correct
33 Correct 316 ms 67740 KB Output is correct
34 Correct 415 ms 68760 KB Output is correct
35 Correct 478 ms 64336 KB Output is correct
36 Correct 509 ms 64248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39604 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 8 ms 39516 KB Output is correct
4 Correct 8 ms 39576 KB Output is correct
5 Correct 8 ms 39512 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 8 ms 39516 KB Output is correct
8 Correct 8 ms 39516 KB Output is correct
9 Correct 8 ms 39512 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 8 ms 39516 KB Output is correct
12 Correct 8 ms 39600 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 8 ms 39512 KB Output is correct
15 Correct 8 ms 39516 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39512 KB Output is correct
18 Correct 9 ms 39512 KB Output is correct
19 Correct 11 ms 39776 KB Output is correct
20 Correct 10 ms 39512 KB Output is correct
21 Correct 11 ms 39516 KB Output is correct
22 Correct 11 ms 39516 KB Output is correct
23 Correct 11 ms 39708 KB Output is correct
24 Correct 180 ms 64632 KB Output is correct
25 Correct 221 ms 67488 KB Output is correct
26 Correct 247 ms 66468 KB Output is correct
27 Correct 263 ms 72092 KB Output is correct
28 Correct 257 ms 68208 KB Output is correct
29 Correct 129 ms 66060 KB Output is correct
30 Correct 520 ms 69972 KB Output is correct
31 Correct 110 ms 58760 KB Output is correct
32 Correct 55 ms 48624 KB Output is correct
33 Correct 316 ms 67740 KB Output is correct
34 Correct 415 ms 68760 KB Output is correct
35 Correct 478 ms 64336 KB Output is correct
36 Correct 509 ms 64248 KB Output is correct
37 Correct 270 ms 69400 KB Output is correct
38 Correct 267 ms 74788 KB Output is correct
39 Correct 373 ms 73220 KB Output is correct
40 Correct 373 ms 73120 KB Output is correct
41 Correct 8 ms 39516 KB Output is correct
42 Correct 601 ms 73508 KB Output is correct
43 Correct 400 ms 71556 KB Output is correct
44 Correct 492 ms 71884 KB Output is correct
45 Correct 494 ms 67708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39604 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 8 ms 39516 KB Output is correct
4 Correct 8 ms 39576 KB Output is correct
5 Correct 8 ms 39512 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 8 ms 39516 KB Output is correct
8 Correct 8 ms 39516 KB Output is correct
9 Correct 8 ms 39512 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 8 ms 39516 KB Output is correct
12 Correct 8 ms 39600 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 8 ms 39512 KB Output is correct
15 Correct 8 ms 39516 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39512 KB Output is correct
18 Correct 9 ms 39512 KB Output is correct
19 Correct 11 ms 39776 KB Output is correct
20 Correct 10 ms 39512 KB Output is correct
21 Correct 11 ms 39516 KB Output is correct
22 Correct 11 ms 39516 KB Output is correct
23 Correct 11 ms 39708 KB Output is correct
24 Correct 180 ms 64632 KB Output is correct
25 Correct 221 ms 67488 KB Output is correct
26 Correct 247 ms 66468 KB Output is correct
27 Correct 263 ms 72092 KB Output is correct
28 Correct 257 ms 68208 KB Output is correct
29 Correct 129 ms 66060 KB Output is correct
30 Correct 520 ms 69972 KB Output is correct
31 Correct 110 ms 58760 KB Output is correct
32 Correct 55 ms 48624 KB Output is correct
33 Correct 316 ms 67740 KB Output is correct
34 Correct 415 ms 68760 KB Output is correct
35 Correct 478 ms 64336 KB Output is correct
36 Correct 509 ms 64248 KB Output is correct
37 Correct 270 ms 69400 KB Output is correct
38 Correct 267 ms 74788 KB Output is correct
39 Correct 373 ms 73220 KB Output is correct
40 Correct 373 ms 73120 KB Output is correct
41 Correct 8 ms 39516 KB Output is correct
42 Correct 601 ms 73508 KB Output is correct
43 Correct 400 ms 71556 KB Output is correct
44 Correct 492 ms 71884 KB Output is correct
45 Correct 494 ms 67708 KB Output is correct
46 Correct 1321 ms 171496 KB Output is correct
47 Correct 1361 ms 199524 KB Output is correct
48 Correct 1797 ms 186688 KB Output is correct
49 Correct 1787 ms 187852 KB Output is correct
50 Correct 3687 ms 189236 KB Output is correct
51 Correct 2067 ms 177596 KB Output is correct
52 Correct 2583 ms 175964 KB Output is correct
53 Correct 3389 ms 161744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 344 ms 72052 KB Output is correct
2 Correct 328 ms 72312 KB Output is correct
3 Correct 148 ms 67780 KB Output is correct
4 Correct 264 ms 71248 KB Output is correct
5 Correct 9 ms 39596 KB Output is correct
6 Correct 294 ms 71180 KB Output is correct
7 Correct 68 ms 57836 KB Output is correct
8 Correct 59 ms 50260 KB Output is correct
9 Correct 146 ms 68656 KB Output is correct
10 Correct 335 ms 69116 KB Output is correct
11 Correct 116 ms 62776 KB Output is correct
12 Correct 8 ms 39604 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 8 ms 39516 KB Output is correct
15 Correct 8 ms 39576 KB Output is correct
16 Correct 8 ms 39512 KB Output is correct
17 Correct 8 ms 39516 KB Output is correct
18 Correct 8 ms 39516 KB Output is correct
19 Correct 8 ms 39516 KB Output is correct
20 Correct 8 ms 39512 KB Output is correct
21 Correct 8 ms 39516 KB Output is correct
22 Correct 8 ms 39516 KB Output is correct
23 Correct 8 ms 39600 KB Output is correct
24 Correct 8 ms 39516 KB Output is correct
25 Correct 8 ms 39512 KB Output is correct
26 Correct 8 ms 39516 KB Output is correct
27 Correct 8 ms 39516 KB Output is correct
28 Correct 9 ms 39512 KB Output is correct
29 Correct 9 ms 39512 KB Output is correct
30 Correct 11 ms 39776 KB Output is correct
31 Correct 10 ms 39512 KB Output is correct
32 Correct 11 ms 39516 KB Output is correct
33 Correct 11 ms 39516 KB Output is correct
34 Correct 11 ms 39708 KB Output is correct
35 Correct 180 ms 64632 KB Output is correct
36 Correct 221 ms 67488 KB Output is correct
37 Correct 247 ms 66468 KB Output is correct
38 Correct 263 ms 72092 KB Output is correct
39 Correct 257 ms 68208 KB Output is correct
40 Correct 129 ms 66060 KB Output is correct
41 Correct 520 ms 69972 KB Output is correct
42 Correct 110 ms 58760 KB Output is correct
43 Correct 55 ms 48624 KB Output is correct
44 Correct 316 ms 67740 KB Output is correct
45 Correct 415 ms 68760 KB Output is correct
46 Correct 478 ms 64336 KB Output is correct
47 Correct 509 ms 64248 KB Output is correct
48 Correct 270 ms 69400 KB Output is correct
49 Correct 267 ms 74788 KB Output is correct
50 Correct 373 ms 73220 KB Output is correct
51 Correct 373 ms 73120 KB Output is correct
52 Correct 8 ms 39516 KB Output is correct
53 Correct 601 ms 73508 KB Output is correct
54 Correct 400 ms 71556 KB Output is correct
55 Correct 492 ms 71884 KB Output is correct
56 Correct 494 ms 67708 KB Output is correct
57 Correct 248 ms 69716 KB Output is correct
58 Correct 278 ms 75084 KB Output is correct
59 Incorrect 350 ms 73060 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 344 ms 72052 KB Output is correct
2 Correct 328 ms 72312 KB Output is correct
3 Correct 148 ms 67780 KB Output is correct
4 Correct 264 ms 71248 KB Output is correct
5 Correct 9 ms 39596 KB Output is correct
6 Correct 294 ms 71180 KB Output is correct
7 Correct 68 ms 57836 KB Output is correct
8 Correct 59 ms 50260 KB Output is correct
9 Correct 146 ms 68656 KB Output is correct
10 Correct 335 ms 69116 KB Output is correct
11 Correct 116 ms 62776 KB Output is correct
12 Correct 8 ms 39604 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 8 ms 39516 KB Output is correct
15 Correct 8 ms 39576 KB Output is correct
16 Correct 8 ms 39512 KB Output is correct
17 Correct 8 ms 39516 KB Output is correct
18 Correct 8 ms 39516 KB Output is correct
19 Correct 8 ms 39516 KB Output is correct
20 Correct 8 ms 39512 KB Output is correct
21 Correct 8 ms 39516 KB Output is correct
22 Correct 8 ms 39516 KB Output is correct
23 Correct 8 ms 39600 KB Output is correct
24 Correct 8 ms 39516 KB Output is correct
25 Correct 8 ms 39512 KB Output is correct
26 Correct 8 ms 39516 KB Output is correct
27 Correct 8 ms 39516 KB Output is correct
28 Correct 9 ms 39512 KB Output is correct
29 Correct 9 ms 39512 KB Output is correct
30 Correct 11 ms 39776 KB Output is correct
31 Correct 10 ms 39512 KB Output is correct
32 Correct 11 ms 39516 KB Output is correct
33 Correct 11 ms 39516 KB Output is correct
34 Correct 11 ms 39708 KB Output is correct
35 Correct 180 ms 64632 KB Output is correct
36 Correct 221 ms 67488 KB Output is correct
37 Correct 247 ms 66468 KB Output is correct
38 Correct 263 ms 72092 KB Output is correct
39 Correct 257 ms 68208 KB Output is correct
40 Correct 129 ms 66060 KB Output is correct
41 Correct 520 ms 69972 KB Output is correct
42 Correct 110 ms 58760 KB Output is correct
43 Correct 55 ms 48624 KB Output is correct
44 Correct 316 ms 67740 KB Output is correct
45 Correct 415 ms 68760 KB Output is correct
46 Correct 478 ms 64336 KB Output is correct
47 Correct 509 ms 64248 KB Output is correct
48 Correct 270 ms 69400 KB Output is correct
49 Correct 267 ms 74788 KB Output is correct
50 Correct 373 ms 73220 KB Output is correct
51 Correct 373 ms 73120 KB Output is correct
52 Correct 8 ms 39516 KB Output is correct
53 Correct 601 ms 73508 KB Output is correct
54 Correct 400 ms 71556 KB Output is correct
55 Correct 492 ms 71884 KB Output is correct
56 Correct 494 ms 67708 KB Output is correct
57 Correct 1321 ms 171496 KB Output is correct
58 Correct 1361 ms 199524 KB Output is correct
59 Correct 1797 ms 186688 KB Output is correct
60 Correct 1787 ms 187852 KB Output is correct
61 Correct 3687 ms 189236 KB Output is correct
62 Correct 2067 ms 177596 KB Output is correct
63 Correct 2583 ms 175964 KB Output is correct
64 Correct 3389 ms 161744 KB Output is correct
65 Correct 248 ms 69716 KB Output is correct
66 Correct 278 ms 75084 KB Output is correct
67 Incorrect 350 ms 73060 KB Output isn't correct
68 Halted 0 ms 0 KB -