Submission #934502

# Submission time Handle Problem Language Result Execution time Memory
934502 2024-02-27T13:20:06 Z AdamGS Two Dishes (JOI19_dishes) C++17
74 / 100
3580 ms 208232 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);
      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 333 ms 73252 KB Output is correct
2 Correct 361 ms 73508 KB Output is correct
3 Correct 145 ms 68896 KB Output is correct
4 Correct 262 ms 72532 KB Output is correct
5 Correct 9 ms 39516 KB Output is correct
6 Correct 321 ms 72236 KB Output is correct
7 Correct 67 ms 58216 KB Output is correct
8 Correct 63 ms 50696 KB Output is correct
9 Correct 161 ms 70060 KB Output is correct
10 Correct 327 ms 69508 KB Output is correct
11 Correct 121 ms 63424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 39520 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 9 ms 39512 KB Output is correct
4 Correct 8 ms 39516 KB Output is correct
5 Correct 8 ms 39516 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 8 ms 39516 KB Output is correct
8 Correct 9 ms 39628 KB Output is correct
9 Correct 8 ms 39516 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 9 ms 39556 KB Output is correct
12 Correct 9 ms 39516 KB Output is correct
13 Correct 8 ms 39632 KB Output is correct
14 Correct 9 ms 39516 KB Output is correct
15 Correct 10 ms 39516 KB Output is correct
16 Correct 9 ms 39512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 39520 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 9 ms 39512 KB Output is correct
4 Correct 8 ms 39516 KB Output is correct
5 Correct 8 ms 39516 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 8 ms 39516 KB Output is correct
8 Correct 9 ms 39628 KB Output is correct
9 Correct 8 ms 39516 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 9 ms 39556 KB Output is correct
12 Correct 9 ms 39516 KB Output is correct
13 Correct 8 ms 39632 KB Output is correct
14 Correct 9 ms 39516 KB Output is correct
15 Correct 10 ms 39516 KB Output is correct
16 Correct 9 ms 39512 KB Output is correct
17 Correct 9 ms 39516 KB Output is correct
18 Correct 10 ms 39516 KB Output is correct
19 Correct 15 ms 39620 KB Output is correct
20 Correct 10 ms 39516 KB Output is correct
21 Correct 14 ms 39516 KB Output is correct
22 Correct 12 ms 39512 KB Output is correct
23 Correct 11 ms 39512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 39520 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 9 ms 39512 KB Output is correct
4 Correct 8 ms 39516 KB Output is correct
5 Correct 8 ms 39516 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 8 ms 39516 KB Output is correct
8 Correct 9 ms 39628 KB Output is correct
9 Correct 8 ms 39516 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 9 ms 39556 KB Output is correct
12 Correct 9 ms 39516 KB Output is correct
13 Correct 8 ms 39632 KB Output is correct
14 Correct 9 ms 39516 KB Output is correct
15 Correct 10 ms 39516 KB Output is correct
16 Correct 9 ms 39512 KB Output is correct
17 Correct 9 ms 39516 KB Output is correct
18 Correct 10 ms 39516 KB Output is correct
19 Correct 15 ms 39620 KB Output is correct
20 Correct 10 ms 39516 KB Output is correct
21 Correct 14 ms 39516 KB Output is correct
22 Correct 12 ms 39512 KB Output is correct
23 Correct 11 ms 39512 KB Output is correct
24 Correct 177 ms 65328 KB Output is correct
25 Correct 221 ms 68248 KB Output is correct
26 Correct 226 ms 67532 KB Output is correct
27 Correct 251 ms 73092 KB Output is correct
28 Correct 229 ms 69140 KB Output is correct
29 Correct 135 ms 66864 KB Output is correct
30 Correct 493 ms 71072 KB Output is correct
31 Correct 109 ms 58868 KB Output is correct
32 Correct 56 ms 48944 KB Output is correct
33 Correct 295 ms 68964 KB Output is correct
34 Correct 402 ms 69584 KB Output is correct
35 Correct 463 ms 64484 KB Output is correct
36 Correct 468 ms 64592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 39520 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 9 ms 39512 KB Output is correct
4 Correct 8 ms 39516 KB Output is correct
5 Correct 8 ms 39516 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 8 ms 39516 KB Output is correct
8 Correct 9 ms 39628 KB Output is correct
9 Correct 8 ms 39516 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 9 ms 39556 KB Output is correct
12 Correct 9 ms 39516 KB Output is correct
13 Correct 8 ms 39632 KB Output is correct
14 Correct 9 ms 39516 KB Output is correct
15 Correct 10 ms 39516 KB Output is correct
16 Correct 9 ms 39512 KB Output is correct
17 Correct 9 ms 39516 KB Output is correct
18 Correct 10 ms 39516 KB Output is correct
19 Correct 15 ms 39620 KB Output is correct
20 Correct 10 ms 39516 KB Output is correct
21 Correct 14 ms 39516 KB Output is correct
22 Correct 12 ms 39512 KB Output is correct
23 Correct 11 ms 39512 KB Output is correct
24 Correct 177 ms 65328 KB Output is correct
25 Correct 221 ms 68248 KB Output is correct
26 Correct 226 ms 67532 KB Output is correct
27 Correct 251 ms 73092 KB Output is correct
28 Correct 229 ms 69140 KB Output is correct
29 Correct 135 ms 66864 KB Output is correct
30 Correct 493 ms 71072 KB Output is correct
31 Correct 109 ms 58868 KB Output is correct
32 Correct 56 ms 48944 KB Output is correct
33 Correct 295 ms 68964 KB Output is correct
34 Correct 402 ms 69584 KB Output is correct
35 Correct 463 ms 64484 KB Output is correct
36 Correct 468 ms 64592 KB Output is correct
37 Correct 247 ms 70608 KB Output is correct
38 Correct 272 ms 75976 KB Output is correct
39 Correct 345 ms 73300 KB Output is correct
40 Correct 336 ms 73264 KB Output is correct
41 Correct 8 ms 39512 KB Output is correct
42 Correct 505 ms 73928 KB Output is correct
43 Correct 324 ms 71724 KB Output is correct
44 Correct 414 ms 72400 KB Output is correct
45 Correct 484 ms 68056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 39520 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 9 ms 39512 KB Output is correct
4 Correct 8 ms 39516 KB Output is correct
5 Correct 8 ms 39516 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 8 ms 39516 KB Output is correct
8 Correct 9 ms 39628 KB Output is correct
9 Correct 8 ms 39516 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 9 ms 39556 KB Output is correct
12 Correct 9 ms 39516 KB Output is correct
13 Correct 8 ms 39632 KB Output is correct
14 Correct 9 ms 39516 KB Output is correct
15 Correct 10 ms 39516 KB Output is correct
16 Correct 9 ms 39512 KB Output is correct
17 Correct 9 ms 39516 KB Output is correct
18 Correct 10 ms 39516 KB Output is correct
19 Correct 15 ms 39620 KB Output is correct
20 Correct 10 ms 39516 KB Output is correct
21 Correct 14 ms 39516 KB Output is correct
22 Correct 12 ms 39512 KB Output is correct
23 Correct 11 ms 39512 KB Output is correct
24 Correct 177 ms 65328 KB Output is correct
25 Correct 221 ms 68248 KB Output is correct
26 Correct 226 ms 67532 KB Output is correct
27 Correct 251 ms 73092 KB Output is correct
28 Correct 229 ms 69140 KB Output is correct
29 Correct 135 ms 66864 KB Output is correct
30 Correct 493 ms 71072 KB Output is correct
31 Correct 109 ms 58868 KB Output is correct
32 Correct 56 ms 48944 KB Output is correct
33 Correct 295 ms 68964 KB Output is correct
34 Correct 402 ms 69584 KB Output is correct
35 Correct 463 ms 64484 KB Output is correct
36 Correct 468 ms 64592 KB Output is correct
37 Correct 247 ms 70608 KB Output is correct
38 Correct 272 ms 75976 KB Output is correct
39 Correct 345 ms 73300 KB Output is correct
40 Correct 336 ms 73264 KB Output is correct
41 Correct 8 ms 39512 KB Output is correct
42 Correct 505 ms 73928 KB Output is correct
43 Correct 324 ms 71724 KB Output is correct
44 Correct 414 ms 72400 KB Output is correct
45 Correct 484 ms 68056 KB Output is correct
46 Correct 1232 ms 180576 KB Output is correct
47 Correct 1356 ms 208232 KB Output is correct
48 Correct 1769 ms 194360 KB Output is correct
49 Correct 1788 ms 194296 KB Output is correct
50 Correct 3580 ms 197740 KB Output is correct
51 Correct 2057 ms 185240 KB Output is correct
52 Correct 2503 ms 184000 KB Output is correct
53 Correct 3307 ms 166352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 333 ms 73252 KB Output is correct
2 Correct 361 ms 73508 KB Output is correct
3 Correct 145 ms 68896 KB Output is correct
4 Correct 262 ms 72532 KB Output is correct
5 Correct 9 ms 39516 KB Output is correct
6 Correct 321 ms 72236 KB Output is correct
7 Correct 67 ms 58216 KB Output is correct
8 Correct 63 ms 50696 KB Output is correct
9 Correct 161 ms 70060 KB Output is correct
10 Correct 327 ms 69508 KB Output is correct
11 Correct 121 ms 63424 KB Output is correct
12 Correct 9 ms 39520 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 9 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 8 ms 39516 KB Output is correct
18 Correct 8 ms 39516 KB Output is correct
19 Correct 9 ms 39628 KB Output is correct
20 Correct 8 ms 39516 KB Output is correct
21 Correct 8 ms 39516 KB Output is correct
22 Correct 9 ms 39556 KB Output is correct
23 Correct 9 ms 39516 KB Output is correct
24 Correct 8 ms 39632 KB Output is correct
25 Correct 9 ms 39516 KB Output is correct
26 Correct 10 ms 39516 KB Output is correct
27 Correct 9 ms 39512 KB Output is correct
28 Correct 9 ms 39516 KB Output is correct
29 Correct 10 ms 39516 KB Output is correct
30 Correct 15 ms 39620 KB Output is correct
31 Correct 10 ms 39516 KB Output is correct
32 Correct 14 ms 39516 KB Output is correct
33 Correct 12 ms 39512 KB Output is correct
34 Correct 11 ms 39512 KB Output is correct
35 Correct 177 ms 65328 KB Output is correct
36 Correct 221 ms 68248 KB Output is correct
37 Correct 226 ms 67532 KB Output is correct
38 Correct 251 ms 73092 KB Output is correct
39 Correct 229 ms 69140 KB Output is correct
40 Correct 135 ms 66864 KB Output is correct
41 Correct 493 ms 71072 KB Output is correct
42 Correct 109 ms 58868 KB Output is correct
43 Correct 56 ms 48944 KB Output is correct
44 Correct 295 ms 68964 KB Output is correct
45 Correct 402 ms 69584 KB Output is correct
46 Correct 463 ms 64484 KB Output is correct
47 Correct 468 ms 64592 KB Output is correct
48 Correct 247 ms 70608 KB Output is correct
49 Correct 272 ms 75976 KB Output is correct
50 Correct 345 ms 73300 KB Output is correct
51 Correct 336 ms 73264 KB Output is correct
52 Correct 8 ms 39512 KB Output is correct
53 Correct 505 ms 73928 KB Output is correct
54 Correct 324 ms 71724 KB Output is correct
55 Correct 414 ms 72400 KB Output is correct
56 Correct 484 ms 68056 KB Output is correct
57 Correct 237 ms 71064 KB Output is correct
58 Correct 261 ms 76372 KB Output is correct
59 Incorrect 355 ms 74324 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 333 ms 73252 KB Output is correct
2 Correct 361 ms 73508 KB Output is correct
3 Correct 145 ms 68896 KB Output is correct
4 Correct 262 ms 72532 KB Output is correct
5 Correct 9 ms 39516 KB Output is correct
6 Correct 321 ms 72236 KB Output is correct
7 Correct 67 ms 58216 KB Output is correct
8 Correct 63 ms 50696 KB Output is correct
9 Correct 161 ms 70060 KB Output is correct
10 Correct 327 ms 69508 KB Output is correct
11 Correct 121 ms 63424 KB Output is correct
12 Correct 9 ms 39520 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 9 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 8 ms 39516 KB Output is correct
18 Correct 8 ms 39516 KB Output is correct
19 Correct 9 ms 39628 KB Output is correct
20 Correct 8 ms 39516 KB Output is correct
21 Correct 8 ms 39516 KB Output is correct
22 Correct 9 ms 39556 KB Output is correct
23 Correct 9 ms 39516 KB Output is correct
24 Correct 8 ms 39632 KB Output is correct
25 Correct 9 ms 39516 KB Output is correct
26 Correct 10 ms 39516 KB Output is correct
27 Correct 9 ms 39512 KB Output is correct
28 Correct 9 ms 39516 KB Output is correct
29 Correct 10 ms 39516 KB Output is correct
30 Correct 15 ms 39620 KB Output is correct
31 Correct 10 ms 39516 KB Output is correct
32 Correct 14 ms 39516 KB Output is correct
33 Correct 12 ms 39512 KB Output is correct
34 Correct 11 ms 39512 KB Output is correct
35 Correct 177 ms 65328 KB Output is correct
36 Correct 221 ms 68248 KB Output is correct
37 Correct 226 ms 67532 KB Output is correct
38 Correct 251 ms 73092 KB Output is correct
39 Correct 229 ms 69140 KB Output is correct
40 Correct 135 ms 66864 KB Output is correct
41 Correct 493 ms 71072 KB Output is correct
42 Correct 109 ms 58868 KB Output is correct
43 Correct 56 ms 48944 KB Output is correct
44 Correct 295 ms 68964 KB Output is correct
45 Correct 402 ms 69584 KB Output is correct
46 Correct 463 ms 64484 KB Output is correct
47 Correct 468 ms 64592 KB Output is correct
48 Correct 247 ms 70608 KB Output is correct
49 Correct 272 ms 75976 KB Output is correct
50 Correct 345 ms 73300 KB Output is correct
51 Correct 336 ms 73264 KB Output is correct
52 Correct 8 ms 39512 KB Output is correct
53 Correct 505 ms 73928 KB Output is correct
54 Correct 324 ms 71724 KB Output is correct
55 Correct 414 ms 72400 KB Output is correct
56 Correct 484 ms 68056 KB Output is correct
57 Correct 1232 ms 180576 KB Output is correct
58 Correct 1356 ms 208232 KB Output is correct
59 Correct 1769 ms 194360 KB Output is correct
60 Correct 1788 ms 194296 KB Output is correct
61 Correct 3580 ms 197740 KB Output is correct
62 Correct 2057 ms 185240 KB Output is correct
63 Correct 2503 ms 184000 KB Output is correct
64 Correct 3307 ms 166352 KB Output is correct
65 Correct 237 ms 71064 KB Output is correct
66 Correct 261 ms 76372 KB Output is correct
67 Incorrect 355 ms 74324 KB Output isn't correct
68 Halted 0 ms 0 KB -