Submission #203407

# Submission time Handle Problem Language Result Execution time Memory
203407 2020-02-20T14:07:35 Z dennisstar Two Dishes (JOI19_dishes) C++17
74 / 100
6158 ms 218368 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<60;

ll F[1<<21], lz1[1<<21], lz2[1<<21];
inline void spread(int i) {
	F[i]=max(F[i]+lz1[i], lz2[i]);
	if (i<(1<<20)) for (auto &j:{i*2, i*2+1}) lz1[j]+=lz1[i], lz2[j]+=lz1[i], lz2[j]=max(lz2[j], lz2[i]);
	lz1[i]=0, lz2[i]=-INF;
}
inline void upd1(int i, int s, int e, int ts, int te, ll v) {
	spread(i);
	if (e<ts||te<s||te<ts) return ;
	if (ts<=s&&e<=te) { lz1[i]+=v, lz2[i]+=v; spread(i); return ; }
	int md=(s+e)/2;
	upd1(i*2, s, md, ts, te, v); upd1(i*2+1, md+1, e, ts, te, v);
	F[i]=max(F[i*2], F[i*2+1]);
}
inline void upd2(int i, int s, int e, int ts, int te, ll v) {
	spread(i);
	if (e<ts||te<s||te<ts) return ;
	if (ts<=s&&e<=te) { lz2[i]=v; spread(i); return ; }
	int md=(s+e)/2;
	upd2(i*2, s, md, ts, te, v); upd2(i*2+1, md+1, e, ts, te, v);
	F[i]=max(F[i*2], F[i*2+1]);
}
inline ll get(int i, int s, int e, int t) {
	spread(i);
	if (s==e) return F[i];
	int md=(s+e)/2;
	if (t<=md) return get(i*2, s, md, t);
	else return get(i*2+1, md+1, e, t);
}

int N, M;
ll A[1<<20], B[1<<20], S[1<<20], T[1<<20], P[1<<20], Q[1<<20];
vector<pll> qu[1<<20];

int main() {
	scanf("%d %d", &N, &M);
	for (int i=1; i<=N; i++) scanf("%lld %lld %lld", &A[i], &S[i], &P[i]), A[i]+=A[i-1];
	for (int i=1; i<=M; i++) scanf("%lld %lld %lld", &B[i], &T[i], &Q[i]), B[i]+=B[i-1];
	for (int i=1; i<=N; i++) {
		int I=upper_bound(B, B+M+1, S[i]-A[i])-B-1;
		if (I>=0) qu[i].eb(I, P[i]);
	}
	ll im=0;
	for (int i=1; i<=M; i++) {
		int J=upper_bound(A, A+N+1, T[i]-B[i])-A-1;
		if (J>=0) qu[J+1].eb(i-1, -Q[i]), im+=Q[i];
	}
	for (int i=1; i<=N+1; i++) {
		sort(all(qu[i]));
		for (auto &j:qu[i]) upd1(1, 0, M, 0, j.fi, j.se);
		for (auto &j:qu[i]) upd2(1, 0, M, j.fi+1, M, get(1, 0, M, j.fi));
	}
	printf("%lld\n", get(1, 0, M, M)+im);
	return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~
dishes.cpp:49:71: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=1; i<=N; i++) scanf("%lld %lld %lld", &A[i], &S[i], &P[i]), A[i]+=A[i-1];
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
dishes.cpp:50:71: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=1; i<=M; i++) scanf("%lld %lld %lld", &B[i], &T[i], &Q[i]), B[i]+=B[i-1];
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 601 ms 63096 KB Output is correct
2 Correct 642 ms 79216 KB Output is correct
3 Correct 623 ms 77788 KB Output is correct
4 Correct 485 ms 66640 KB Output is correct
5 Correct 20 ms 24952 KB Output is correct
6 Correct 618 ms 78188 KB Output is correct
7 Correct 301 ms 58076 KB Output is correct
8 Correct 154 ms 43000 KB Output is correct
9 Correct 630 ms 78812 KB Output is correct
10 Correct 590 ms 71800 KB Output is correct
11 Correct 556 ms 72284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 24952 KB Output is correct
2 Correct 20 ms 24952 KB Output is correct
3 Correct 20 ms 24952 KB Output is correct
4 Correct 21 ms 25080 KB Output is correct
5 Correct 20 ms 25080 KB Output is correct
6 Correct 20 ms 24952 KB Output is correct
7 Correct 20 ms 24952 KB Output is correct
8 Correct 20 ms 24952 KB Output is correct
9 Correct 20 ms 25080 KB Output is correct
10 Correct 20 ms 24952 KB Output is correct
11 Correct 20 ms 24952 KB Output is correct
12 Correct 20 ms 24952 KB Output is correct
13 Correct 20 ms 24952 KB Output is correct
14 Correct 21 ms 25080 KB Output is correct
15 Correct 20 ms 24956 KB Output is correct
16 Correct 21 ms 24952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 24952 KB Output is correct
2 Correct 20 ms 24952 KB Output is correct
3 Correct 20 ms 24952 KB Output is correct
4 Correct 21 ms 25080 KB Output is correct
5 Correct 20 ms 25080 KB Output is correct
6 Correct 20 ms 24952 KB Output is correct
7 Correct 20 ms 24952 KB Output is correct
8 Correct 20 ms 24952 KB Output is correct
9 Correct 20 ms 25080 KB Output is correct
10 Correct 20 ms 24952 KB Output is correct
11 Correct 20 ms 24952 KB Output is correct
12 Correct 20 ms 24952 KB Output is correct
13 Correct 20 ms 24952 KB Output is correct
14 Correct 21 ms 25080 KB Output is correct
15 Correct 20 ms 24956 KB Output is correct
16 Correct 21 ms 24952 KB Output is correct
17 Correct 25 ms 25408 KB Output is correct
18 Correct 23 ms 25592 KB Output is correct
19 Correct 25 ms 25464 KB Output is correct
20 Correct 27 ms 25464 KB Output is correct
21 Correct 24 ms 25464 KB Output is correct
22 Correct 24 ms 25464 KB Output is correct
23 Correct 24 ms 25464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 24952 KB Output is correct
2 Correct 20 ms 24952 KB Output is correct
3 Correct 20 ms 24952 KB Output is correct
4 Correct 21 ms 25080 KB Output is correct
5 Correct 20 ms 25080 KB Output is correct
6 Correct 20 ms 24952 KB Output is correct
7 Correct 20 ms 24952 KB Output is correct
8 Correct 20 ms 24952 KB Output is correct
9 Correct 20 ms 25080 KB Output is correct
10 Correct 20 ms 24952 KB Output is correct
11 Correct 20 ms 24952 KB Output is correct
12 Correct 20 ms 24952 KB Output is correct
13 Correct 20 ms 24952 KB Output is correct
14 Correct 21 ms 25080 KB Output is correct
15 Correct 20 ms 24956 KB Output is correct
16 Correct 21 ms 24952 KB Output is correct
17 Correct 25 ms 25408 KB Output is correct
18 Correct 23 ms 25592 KB Output is correct
19 Correct 25 ms 25464 KB Output is correct
20 Correct 27 ms 25464 KB Output is correct
21 Correct 24 ms 25464 KB Output is correct
22 Correct 24 ms 25464 KB Output is correct
23 Correct 24 ms 25464 KB Output is correct
24 Correct 1016 ms 73572 KB Output is correct
25 Correct 524 ms 71904 KB Output is correct
26 Correct 538 ms 73572 KB Output is correct
27 Correct 548 ms 73588 KB Output is correct
28 Correct 669 ms 75364 KB Output is correct
29 Correct 608 ms 75804 KB Output is correct
30 Correct 934 ms 77452 KB Output is correct
31 Correct 325 ms 58840 KB Output is correct
32 Correct 140 ms 41364 KB Output is correct
33 Correct 607 ms 71032 KB Output is correct
34 Correct 822 ms 76272 KB Output is correct
35 Correct 921 ms 71032 KB Output is correct
36 Correct 881 ms 70904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 24952 KB Output is correct
2 Correct 20 ms 24952 KB Output is correct
3 Correct 20 ms 24952 KB Output is correct
4 Correct 21 ms 25080 KB Output is correct
5 Correct 20 ms 25080 KB Output is correct
6 Correct 20 ms 24952 KB Output is correct
7 Correct 20 ms 24952 KB Output is correct
8 Correct 20 ms 24952 KB Output is correct
9 Correct 20 ms 25080 KB Output is correct
10 Correct 20 ms 24952 KB Output is correct
11 Correct 20 ms 24952 KB Output is correct
12 Correct 20 ms 24952 KB Output is correct
13 Correct 20 ms 24952 KB Output is correct
14 Correct 21 ms 25080 KB Output is correct
15 Correct 20 ms 24956 KB Output is correct
16 Correct 21 ms 24952 KB Output is correct
17 Correct 25 ms 25408 KB Output is correct
18 Correct 23 ms 25592 KB Output is correct
19 Correct 25 ms 25464 KB Output is correct
20 Correct 27 ms 25464 KB Output is correct
21 Correct 24 ms 25464 KB Output is correct
22 Correct 24 ms 25464 KB Output is correct
23 Correct 24 ms 25464 KB Output is correct
24 Correct 1016 ms 73572 KB Output is correct
25 Correct 524 ms 71904 KB Output is correct
26 Correct 538 ms 73572 KB Output is correct
27 Correct 548 ms 73588 KB Output is correct
28 Correct 669 ms 75364 KB Output is correct
29 Correct 608 ms 75804 KB Output is correct
30 Correct 934 ms 77452 KB Output is correct
31 Correct 325 ms 58840 KB Output is correct
32 Correct 140 ms 41364 KB Output is correct
33 Correct 607 ms 71032 KB Output is correct
34 Correct 822 ms 76272 KB Output is correct
35 Correct 921 ms 71032 KB Output is correct
36 Correct 881 ms 70904 KB Output is correct
37 Correct 596 ms 76648 KB Output is correct
38 Correct 574 ms 76400 KB Output is correct
39 Correct 633 ms 75464 KB Output is correct
40 Correct 639 ms 75364 KB Output is correct
41 Correct 21 ms 24952 KB Output is correct
42 Correct 1020 ms 80384 KB Output is correct
43 Correct 638 ms 73940 KB Output is correct
44 Correct 877 ms 79152 KB Output is correct
45 Correct 919 ms 73976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 24952 KB Output is correct
2 Correct 20 ms 24952 KB Output is correct
3 Correct 20 ms 24952 KB Output is correct
4 Correct 21 ms 25080 KB Output is correct
5 Correct 20 ms 25080 KB Output is correct
6 Correct 20 ms 24952 KB Output is correct
7 Correct 20 ms 24952 KB Output is correct
8 Correct 20 ms 24952 KB Output is correct
9 Correct 20 ms 25080 KB Output is correct
10 Correct 20 ms 24952 KB Output is correct
11 Correct 20 ms 24952 KB Output is correct
12 Correct 20 ms 24952 KB Output is correct
13 Correct 20 ms 24952 KB Output is correct
14 Correct 21 ms 25080 KB Output is correct
15 Correct 20 ms 24956 KB Output is correct
16 Correct 21 ms 24952 KB Output is correct
17 Correct 25 ms 25408 KB Output is correct
18 Correct 23 ms 25592 KB Output is correct
19 Correct 25 ms 25464 KB Output is correct
20 Correct 27 ms 25464 KB Output is correct
21 Correct 24 ms 25464 KB Output is correct
22 Correct 24 ms 25464 KB Output is correct
23 Correct 24 ms 25464 KB Output is correct
24 Correct 1016 ms 73572 KB Output is correct
25 Correct 524 ms 71904 KB Output is correct
26 Correct 538 ms 73572 KB Output is correct
27 Correct 548 ms 73588 KB Output is correct
28 Correct 669 ms 75364 KB Output is correct
29 Correct 608 ms 75804 KB Output is correct
30 Correct 934 ms 77452 KB Output is correct
31 Correct 325 ms 58840 KB Output is correct
32 Correct 140 ms 41364 KB Output is correct
33 Correct 607 ms 71032 KB Output is correct
34 Correct 822 ms 76272 KB Output is correct
35 Correct 921 ms 71032 KB Output is correct
36 Correct 881 ms 70904 KB Output is correct
37 Correct 596 ms 76648 KB Output is correct
38 Correct 574 ms 76400 KB Output is correct
39 Correct 633 ms 75464 KB Output is correct
40 Correct 639 ms 75364 KB Output is correct
41 Correct 21 ms 24952 KB Output is correct
42 Correct 1020 ms 80384 KB Output is correct
43 Correct 638 ms 73940 KB Output is correct
44 Correct 877 ms 79152 KB Output is correct
45 Correct 919 ms 73976 KB Output is correct
46 Correct 3042 ms 199016 KB Output is correct
47 Correct 3046 ms 198908 KB Output is correct
48 Correct 3353 ms 197604 KB Output is correct
49 Correct 3321 ms 197600 KB Output is correct
50 Correct 6158 ms 218368 KB Output is correct
51 Correct 3519 ms 183440 KB Output is correct
52 Correct 4884 ms 207444 KB Output is correct
53 Correct 5487 ms 197744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 601 ms 63096 KB Output is correct
2 Correct 642 ms 79216 KB Output is correct
3 Correct 623 ms 77788 KB Output is correct
4 Correct 485 ms 66640 KB Output is correct
5 Correct 20 ms 24952 KB Output is correct
6 Correct 618 ms 78188 KB Output is correct
7 Correct 301 ms 58076 KB Output is correct
8 Correct 154 ms 43000 KB Output is correct
9 Correct 630 ms 78812 KB Output is correct
10 Correct 590 ms 71800 KB Output is correct
11 Correct 556 ms 72284 KB Output is correct
12 Correct 20 ms 24952 KB Output is correct
13 Correct 20 ms 24952 KB Output is correct
14 Correct 20 ms 24952 KB Output is correct
15 Correct 21 ms 25080 KB Output is correct
16 Correct 20 ms 25080 KB Output is correct
17 Correct 20 ms 24952 KB Output is correct
18 Correct 20 ms 24952 KB Output is correct
19 Correct 20 ms 24952 KB Output is correct
20 Correct 20 ms 25080 KB Output is correct
21 Correct 20 ms 24952 KB Output is correct
22 Correct 20 ms 24952 KB Output is correct
23 Correct 20 ms 24952 KB Output is correct
24 Correct 20 ms 24952 KB Output is correct
25 Correct 21 ms 25080 KB Output is correct
26 Correct 20 ms 24956 KB Output is correct
27 Correct 21 ms 24952 KB Output is correct
28 Correct 25 ms 25408 KB Output is correct
29 Correct 23 ms 25592 KB Output is correct
30 Correct 25 ms 25464 KB Output is correct
31 Correct 27 ms 25464 KB Output is correct
32 Correct 24 ms 25464 KB Output is correct
33 Correct 24 ms 25464 KB Output is correct
34 Correct 24 ms 25464 KB Output is correct
35 Correct 1016 ms 73572 KB Output is correct
36 Correct 524 ms 71904 KB Output is correct
37 Correct 538 ms 73572 KB Output is correct
38 Correct 548 ms 73588 KB Output is correct
39 Correct 669 ms 75364 KB Output is correct
40 Correct 608 ms 75804 KB Output is correct
41 Correct 934 ms 77452 KB Output is correct
42 Correct 325 ms 58840 KB Output is correct
43 Correct 140 ms 41364 KB Output is correct
44 Correct 607 ms 71032 KB Output is correct
45 Correct 822 ms 76272 KB Output is correct
46 Correct 921 ms 71032 KB Output is correct
47 Correct 881 ms 70904 KB Output is correct
48 Correct 596 ms 76648 KB Output is correct
49 Correct 574 ms 76400 KB Output is correct
50 Correct 633 ms 75464 KB Output is correct
51 Correct 639 ms 75364 KB Output is correct
52 Correct 21 ms 24952 KB Output is correct
53 Correct 1020 ms 80384 KB Output is correct
54 Correct 638 ms 73940 KB Output is correct
55 Correct 877 ms 79152 KB Output is correct
56 Correct 919 ms 73976 KB Output is correct
57 Incorrect 585 ms 77156 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 601 ms 63096 KB Output is correct
2 Correct 642 ms 79216 KB Output is correct
3 Correct 623 ms 77788 KB Output is correct
4 Correct 485 ms 66640 KB Output is correct
5 Correct 20 ms 24952 KB Output is correct
6 Correct 618 ms 78188 KB Output is correct
7 Correct 301 ms 58076 KB Output is correct
8 Correct 154 ms 43000 KB Output is correct
9 Correct 630 ms 78812 KB Output is correct
10 Correct 590 ms 71800 KB Output is correct
11 Correct 556 ms 72284 KB Output is correct
12 Correct 20 ms 24952 KB Output is correct
13 Correct 20 ms 24952 KB Output is correct
14 Correct 20 ms 24952 KB Output is correct
15 Correct 21 ms 25080 KB Output is correct
16 Correct 20 ms 25080 KB Output is correct
17 Correct 20 ms 24952 KB Output is correct
18 Correct 20 ms 24952 KB Output is correct
19 Correct 20 ms 24952 KB Output is correct
20 Correct 20 ms 25080 KB Output is correct
21 Correct 20 ms 24952 KB Output is correct
22 Correct 20 ms 24952 KB Output is correct
23 Correct 20 ms 24952 KB Output is correct
24 Correct 20 ms 24952 KB Output is correct
25 Correct 21 ms 25080 KB Output is correct
26 Correct 20 ms 24956 KB Output is correct
27 Correct 21 ms 24952 KB Output is correct
28 Correct 25 ms 25408 KB Output is correct
29 Correct 23 ms 25592 KB Output is correct
30 Correct 25 ms 25464 KB Output is correct
31 Correct 27 ms 25464 KB Output is correct
32 Correct 24 ms 25464 KB Output is correct
33 Correct 24 ms 25464 KB Output is correct
34 Correct 24 ms 25464 KB Output is correct
35 Correct 1016 ms 73572 KB Output is correct
36 Correct 524 ms 71904 KB Output is correct
37 Correct 538 ms 73572 KB Output is correct
38 Correct 548 ms 73588 KB Output is correct
39 Correct 669 ms 75364 KB Output is correct
40 Correct 608 ms 75804 KB Output is correct
41 Correct 934 ms 77452 KB Output is correct
42 Correct 325 ms 58840 KB Output is correct
43 Correct 140 ms 41364 KB Output is correct
44 Correct 607 ms 71032 KB Output is correct
45 Correct 822 ms 76272 KB Output is correct
46 Correct 921 ms 71032 KB Output is correct
47 Correct 881 ms 70904 KB Output is correct
48 Correct 596 ms 76648 KB Output is correct
49 Correct 574 ms 76400 KB Output is correct
50 Correct 633 ms 75464 KB Output is correct
51 Correct 639 ms 75364 KB Output is correct
52 Correct 21 ms 24952 KB Output is correct
53 Correct 1020 ms 80384 KB Output is correct
54 Correct 638 ms 73940 KB Output is correct
55 Correct 877 ms 79152 KB Output is correct
56 Correct 919 ms 73976 KB Output is correct
57 Correct 3042 ms 199016 KB Output is correct
58 Correct 3046 ms 198908 KB Output is correct
59 Correct 3353 ms 197604 KB Output is correct
60 Correct 3321 ms 197600 KB Output is correct
61 Correct 6158 ms 218368 KB Output is correct
62 Correct 3519 ms 183440 KB Output is correct
63 Correct 4884 ms 207444 KB Output is correct
64 Correct 5487 ms 197744 KB Output is correct
65 Incorrect 585 ms 77156 KB Output isn't correct
66 Halted 0 ms 0 KB -