Submission #934519

# Submission time Handle Problem Language Result Execution time Memory
934519 2024-02-27T13:45:30 Z AdamGS Two Dishes (JOI19_dishes) C++17
100 / 100
3698 ms 210244 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);
    }
    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 && 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);
    }
    for(auto j : V[i]) upd(1, 0, N-1, 0, j, -Q[j]);
    if(po!=0) 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 356 ms 66788 KB Output is correct
2 Correct 384 ms 66892 KB Output is correct
3 Correct 152 ms 62664 KB Output is correct
4 Correct 270 ms 65860 KB Output is correct
5 Correct 9 ms 39512 KB Output is correct
6 Correct 288 ms 66012 KB Output is correct
7 Correct 63 ms 55244 KB Output is correct
8 Correct 58 ms 47880 KB Output is correct
9 Correct 151 ms 63172 KB Output is correct
10 Correct 320 ms 66508 KB Output is correct
11 Correct 141 ms 60104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39512 KB Output is correct
2 Correct 8 ms 39552 KB Output is correct
3 Correct 9 ms 39516 KB Output is correct
4 Correct 8 ms 39512 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 39580 KB Output is correct
9 Correct 8 ms 39516 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 8 ms 39516 KB Output is correct
12 Correct 9 ms 39540 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 9 ms 39560 KB Output is correct
15 Correct 8 ms 39540 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39512 KB Output is correct
2 Correct 8 ms 39552 KB Output is correct
3 Correct 9 ms 39516 KB Output is correct
4 Correct 8 ms 39512 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 39580 KB Output is correct
9 Correct 8 ms 39516 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 8 ms 39516 KB Output is correct
12 Correct 9 ms 39540 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 9 ms 39560 KB Output is correct
15 Correct 8 ms 39540 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39516 KB Output is correct
18 Correct 10 ms 39512 KB Output is correct
19 Correct 11 ms 39516 KB Output is correct
20 Correct 10 ms 39516 KB Output is correct
21 Correct 11 ms 39516 KB Output is correct
22 Correct 11 ms 39708 KB Output is correct
23 Correct 11 ms 39516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39512 KB Output is correct
2 Correct 8 ms 39552 KB Output is correct
3 Correct 9 ms 39516 KB Output is correct
4 Correct 8 ms 39512 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 39580 KB Output is correct
9 Correct 8 ms 39516 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 8 ms 39516 KB Output is correct
12 Correct 9 ms 39540 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 9 ms 39560 KB Output is correct
15 Correct 8 ms 39540 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39516 KB Output is correct
18 Correct 10 ms 39512 KB Output is correct
19 Correct 11 ms 39516 KB Output is correct
20 Correct 10 ms 39516 KB Output is correct
21 Correct 11 ms 39516 KB Output is correct
22 Correct 11 ms 39708 KB Output is correct
23 Correct 11 ms 39516 KB Output is correct
24 Correct 180 ms 64976 KB Output is correct
25 Correct 232 ms 67980 KB Output is correct
26 Correct 221 ms 67144 KB Output is correct
27 Correct 249 ms 72532 KB Output is correct
28 Correct 242 ms 68748 KB Output is correct
29 Correct 147 ms 66612 KB Output is correct
30 Correct 493 ms 70628 KB Output is correct
31 Correct 117 ms 58828 KB Output is correct
32 Correct 56 ms 48940 KB Output is correct
33 Correct 313 ms 68692 KB Output is correct
34 Correct 409 ms 69324 KB Output is correct
35 Correct 485 ms 64472 KB Output is correct
36 Correct 457 ms 64436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39512 KB Output is correct
2 Correct 8 ms 39552 KB Output is correct
3 Correct 9 ms 39516 KB Output is correct
4 Correct 8 ms 39512 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 39580 KB Output is correct
9 Correct 8 ms 39516 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 8 ms 39516 KB Output is correct
12 Correct 9 ms 39540 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 9 ms 39560 KB Output is correct
15 Correct 8 ms 39540 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39516 KB Output is correct
18 Correct 10 ms 39512 KB Output is correct
19 Correct 11 ms 39516 KB Output is correct
20 Correct 10 ms 39516 KB Output is correct
21 Correct 11 ms 39516 KB Output is correct
22 Correct 11 ms 39708 KB Output is correct
23 Correct 11 ms 39516 KB Output is correct
24 Correct 180 ms 64976 KB Output is correct
25 Correct 232 ms 67980 KB Output is correct
26 Correct 221 ms 67144 KB Output is correct
27 Correct 249 ms 72532 KB Output is correct
28 Correct 242 ms 68748 KB Output is correct
29 Correct 147 ms 66612 KB Output is correct
30 Correct 493 ms 70628 KB Output is correct
31 Correct 117 ms 58828 KB Output is correct
32 Correct 56 ms 48940 KB Output is correct
33 Correct 313 ms 68692 KB Output is correct
34 Correct 409 ms 69324 KB Output is correct
35 Correct 485 ms 64472 KB Output is correct
36 Correct 457 ms 64436 KB Output is correct
37 Correct 241 ms 69916 KB Output is correct
38 Correct 266 ms 75300 KB Output is correct
39 Correct 343 ms 72268 KB Output is correct
40 Correct 334 ms 72276 KB Output is correct
41 Correct 8 ms 39516 KB Output is correct
42 Correct 595 ms 72732 KB Output is correct
43 Correct 311 ms 70612 KB Output is correct
44 Correct 439 ms 71248 KB Output is correct
45 Correct 562 ms 67356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39512 KB Output is correct
2 Correct 8 ms 39552 KB Output is correct
3 Correct 9 ms 39516 KB Output is correct
4 Correct 8 ms 39512 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 39580 KB Output is correct
9 Correct 8 ms 39516 KB Output is correct
10 Correct 8 ms 39516 KB Output is correct
11 Correct 8 ms 39516 KB Output is correct
12 Correct 9 ms 39540 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 9 ms 39560 KB Output is correct
15 Correct 8 ms 39540 KB Output is correct
16 Correct 8 ms 39516 KB Output is correct
17 Correct 9 ms 39516 KB Output is correct
18 Correct 10 ms 39512 KB Output is correct
19 Correct 11 ms 39516 KB Output is correct
20 Correct 10 ms 39516 KB Output is correct
21 Correct 11 ms 39516 KB Output is correct
22 Correct 11 ms 39708 KB Output is correct
23 Correct 11 ms 39516 KB Output is correct
24 Correct 180 ms 64976 KB Output is correct
25 Correct 232 ms 67980 KB Output is correct
26 Correct 221 ms 67144 KB Output is correct
27 Correct 249 ms 72532 KB Output is correct
28 Correct 242 ms 68748 KB Output is correct
29 Correct 147 ms 66612 KB Output is correct
30 Correct 493 ms 70628 KB Output is correct
31 Correct 117 ms 58828 KB Output is correct
32 Correct 56 ms 48940 KB Output is correct
33 Correct 313 ms 68692 KB Output is correct
34 Correct 409 ms 69324 KB Output is correct
35 Correct 485 ms 64472 KB Output is correct
36 Correct 457 ms 64436 KB Output is correct
37 Correct 241 ms 69916 KB Output is correct
38 Correct 266 ms 75300 KB Output is correct
39 Correct 343 ms 72268 KB Output is correct
40 Correct 334 ms 72276 KB Output is correct
41 Correct 8 ms 39516 KB Output is correct
42 Correct 595 ms 72732 KB Output is correct
43 Correct 311 ms 70612 KB Output is correct
44 Correct 439 ms 71248 KB Output is correct
45 Correct 562 ms 67356 KB Output is correct
46 Correct 1272 ms 172400 KB Output is correct
47 Correct 1343 ms 199856 KB Output is correct
48 Correct 1800 ms 188564 KB Output is correct
49 Correct 1777 ms 191680 KB Output is correct
50 Correct 3698 ms 189952 KB Output is correct
51 Correct 2037 ms 177460 KB Output is correct
52 Correct 2574 ms 176368 KB Output is correct
53 Correct 3449 ms 162384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 356 ms 66788 KB Output is correct
2 Correct 384 ms 66892 KB Output is correct
3 Correct 152 ms 62664 KB Output is correct
4 Correct 270 ms 65860 KB Output is correct
5 Correct 9 ms 39512 KB Output is correct
6 Correct 288 ms 66012 KB Output is correct
7 Correct 63 ms 55244 KB Output is correct
8 Correct 58 ms 47880 KB Output is correct
9 Correct 151 ms 63172 KB Output is correct
10 Correct 320 ms 66508 KB Output is correct
11 Correct 141 ms 60104 KB Output is correct
12 Correct 8 ms 39512 KB Output is correct
13 Correct 8 ms 39552 KB Output is correct
14 Correct 9 ms 39516 KB Output is correct
15 Correct 8 ms 39512 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 39580 KB Output is correct
20 Correct 8 ms 39516 KB Output is correct
21 Correct 8 ms 39516 KB Output is correct
22 Correct 8 ms 39516 KB Output is correct
23 Correct 9 ms 39540 KB Output is correct
24 Correct 8 ms 39516 KB Output is correct
25 Correct 9 ms 39560 KB Output is correct
26 Correct 8 ms 39540 KB Output is correct
27 Correct 8 ms 39516 KB Output is correct
28 Correct 9 ms 39516 KB Output is correct
29 Correct 10 ms 39512 KB Output is correct
30 Correct 11 ms 39516 KB Output is correct
31 Correct 10 ms 39516 KB Output is correct
32 Correct 11 ms 39516 KB Output is correct
33 Correct 11 ms 39708 KB Output is correct
34 Correct 11 ms 39516 KB Output is correct
35 Correct 180 ms 64976 KB Output is correct
36 Correct 232 ms 67980 KB Output is correct
37 Correct 221 ms 67144 KB Output is correct
38 Correct 249 ms 72532 KB Output is correct
39 Correct 242 ms 68748 KB Output is correct
40 Correct 147 ms 66612 KB Output is correct
41 Correct 493 ms 70628 KB Output is correct
42 Correct 117 ms 58828 KB Output is correct
43 Correct 56 ms 48940 KB Output is correct
44 Correct 313 ms 68692 KB Output is correct
45 Correct 409 ms 69324 KB Output is correct
46 Correct 485 ms 64472 KB Output is correct
47 Correct 457 ms 64436 KB Output is correct
48 Correct 241 ms 69916 KB Output is correct
49 Correct 266 ms 75300 KB Output is correct
50 Correct 343 ms 72268 KB Output is correct
51 Correct 334 ms 72276 KB Output is correct
52 Correct 8 ms 39516 KB Output is correct
53 Correct 595 ms 72732 KB Output is correct
54 Correct 311 ms 70612 KB Output is correct
55 Correct 439 ms 71248 KB Output is correct
56 Correct 562 ms 67356 KB Output is correct
57 Correct 239 ms 70356 KB Output is correct
58 Correct 262 ms 75832 KB Output is correct
59 Correct 343 ms 73808 KB Output is correct
60 Correct 341 ms 74028 KB Output is correct
61 Correct 491 ms 70820 KB Output is correct
62 Correct 8 ms 39516 KB Output is correct
63 Correct 540 ms 74116 KB Output is correct
64 Correct 351 ms 73500 KB Output is correct
65 Correct 417 ms 72864 KB Output is correct
66 Correct 517 ms 67712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 356 ms 66788 KB Output is correct
2 Correct 384 ms 66892 KB Output is correct
3 Correct 152 ms 62664 KB Output is correct
4 Correct 270 ms 65860 KB Output is correct
5 Correct 9 ms 39512 KB Output is correct
6 Correct 288 ms 66012 KB Output is correct
7 Correct 63 ms 55244 KB Output is correct
8 Correct 58 ms 47880 KB Output is correct
9 Correct 151 ms 63172 KB Output is correct
10 Correct 320 ms 66508 KB Output is correct
11 Correct 141 ms 60104 KB Output is correct
12 Correct 8 ms 39512 KB Output is correct
13 Correct 8 ms 39552 KB Output is correct
14 Correct 9 ms 39516 KB Output is correct
15 Correct 8 ms 39512 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 39580 KB Output is correct
20 Correct 8 ms 39516 KB Output is correct
21 Correct 8 ms 39516 KB Output is correct
22 Correct 8 ms 39516 KB Output is correct
23 Correct 9 ms 39540 KB Output is correct
24 Correct 8 ms 39516 KB Output is correct
25 Correct 9 ms 39560 KB Output is correct
26 Correct 8 ms 39540 KB Output is correct
27 Correct 8 ms 39516 KB Output is correct
28 Correct 9 ms 39516 KB Output is correct
29 Correct 10 ms 39512 KB Output is correct
30 Correct 11 ms 39516 KB Output is correct
31 Correct 10 ms 39516 KB Output is correct
32 Correct 11 ms 39516 KB Output is correct
33 Correct 11 ms 39708 KB Output is correct
34 Correct 11 ms 39516 KB Output is correct
35 Correct 180 ms 64976 KB Output is correct
36 Correct 232 ms 67980 KB Output is correct
37 Correct 221 ms 67144 KB Output is correct
38 Correct 249 ms 72532 KB Output is correct
39 Correct 242 ms 68748 KB Output is correct
40 Correct 147 ms 66612 KB Output is correct
41 Correct 493 ms 70628 KB Output is correct
42 Correct 117 ms 58828 KB Output is correct
43 Correct 56 ms 48940 KB Output is correct
44 Correct 313 ms 68692 KB Output is correct
45 Correct 409 ms 69324 KB Output is correct
46 Correct 485 ms 64472 KB Output is correct
47 Correct 457 ms 64436 KB Output is correct
48 Correct 241 ms 69916 KB Output is correct
49 Correct 266 ms 75300 KB Output is correct
50 Correct 343 ms 72268 KB Output is correct
51 Correct 334 ms 72276 KB Output is correct
52 Correct 8 ms 39516 KB Output is correct
53 Correct 595 ms 72732 KB Output is correct
54 Correct 311 ms 70612 KB Output is correct
55 Correct 439 ms 71248 KB Output is correct
56 Correct 562 ms 67356 KB Output is correct
57 Correct 1272 ms 172400 KB Output is correct
58 Correct 1343 ms 199856 KB Output is correct
59 Correct 1800 ms 188564 KB Output is correct
60 Correct 1777 ms 191680 KB Output is correct
61 Correct 3698 ms 189952 KB Output is correct
62 Correct 2037 ms 177460 KB Output is correct
63 Correct 2574 ms 176368 KB Output is correct
64 Correct 3449 ms 162384 KB Output is correct
65 Correct 239 ms 70356 KB Output is correct
66 Correct 262 ms 75832 KB Output is correct
67 Correct 343 ms 73808 KB Output is correct
68 Correct 341 ms 74028 KB Output is correct
69 Correct 491 ms 70820 KB Output is correct
70 Correct 8 ms 39516 KB Output is correct
71 Correct 540 ms 74116 KB Output is correct
72 Correct 351 ms 73500 KB Output is correct
73 Correct 417 ms 72864 KB Output is correct
74 Correct 517 ms 67712 KB Output is correct
75 Correct 1220 ms 182716 KB Output is correct
76 Correct 1373 ms 210244 KB Output is correct
77 Correct 1804 ms 196792 KB Output is correct
78 Correct 1814 ms 197104 KB Output is correct
79 Correct 3605 ms 198740 KB Output is correct
80 Correct 1966 ms 185428 KB Output is correct
81 Correct 2580 ms 188616 KB Output is correct
82 Correct 3408 ms 166228 KB Output is correct
83 Correct 3352 ms 185728 KB Output is correct