Submission #103902

# Submission time Handle Problem Language Result Execution time Memory
103902 2019-04-03T06:23:11 Z mzhao Two Dishes (JOI19_dishes) C++11
74 / 100
5234 ms 314560 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define D(x...) printf(x)
#else
#define D(x...)
#endif

#define MN 1000009
#define ll long long
#define x first
#define y second

ll N, M, A[MN], TA[MN], VA[MN], SA[MN], B[MN], TB[MN], VB[MN], SB[MN];
ll sa[MN], sb[MN], ma[MN], mb[MN];
vector<pair<ll, ll>> ver[MN], hor[MN];
vector<pair<ll, bool>> p[MN]; // (y value, is dish A?)

ll findm(ll a[], ll len, ll x) { // index of last element <= x
	ll l = -1, h = len;
	while (l < h-1) {
		ll m = (l+h)/2;
		if (a[m] > x) h = m;
		else l = m;
	}
	return l;
}

ll t[4*MN], l[4*MN];

void push(ll n, ll a, ll b) {
	t[n] += l[n];
	if (a < b-1) {
		l[2*n] += l[n];
		l[2*n+1] += l[n];
	}
	l[n] = 0;
}

ll query(ll n, ll a, ll b, ll x, ll y) {
	if (l[n]) push(n, a, b);
	if (b <= x || y <= a) return -1e16;
	if (x <= a && b <= y) return t[n];
	return max(query(2*n, a, (a+b)/2, x, y), query(2*n+1, (a+b)/2, b, x, y));
}

ll update(ll n, ll a, ll b, ll x, ll y, ll v) {
	if (l[n]) push(n, a, b);
	if (b <= x || y <= a) return t[n];
	if (x <= a && b <= y) {
		l[n] += v;
		push(n, a, b);
	} else {
		t[n] = max(update(2*n, a, (a+b)/2, x, y, v), update(2*n+1, (a+b)/2, b, x, y, v));
	}
	return t[n];
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> TA[i] >> VA[i];
		sa[i] = sa[i-1]+A[i];
	}
	for (int i = 1; i <= M; i++) {
		cin >> B[i] >> TB[i] >> VB[i];
		sb[i] = sb[i-1]+B[i];
	}
	for (int i = 1; i <= N; i++) {
		ma[i] = findm(sb, M+1, TA[i]-sa[i]);
		ver[i].push_back({ma[i], VA[i]});
	}
	for (int i = 1; i <= M; i++) {
		mb[i] = findm(sa, N+1, TB[i]-sb[i]);
		if (mb[i] >= 0) {
			hor[mb[i]].push_back({i, VB[i]});
		}
	}
	for (int i = 1; i <= N; i++) D("%lld ", ma[i]);
	D("\n");
	for (int i = 1; i <= M; i++) D("%lld ", mb[i]);
	D("\n");
	for (int i = 0; i <= N; i++) {
		for (pair<ll, ll> j : ver[i]) {
			update(1, 0, M+1, 0, j.x+1, j.y);
		}
		for (pair<ll, ll> j : hor[i]) {
			ll best = query(1, 0, M+1, 0, j.x+1);
			ll cur = query(1, 0, M+1, j.x, j.x+1);
			update(1, 0, M+1, j.x, j.x+1, best-cur);
			update(1, 0, M+1, j.x, M+1, j.y);
		}
	}
	cout << query(1, 0, M+1, 0, M+1) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 507 ms 118776 KB Output is correct
2 Correct 470 ms 119384 KB Output is correct
3 Correct 411 ms 117652 KB Output is correct
4 Correct 389 ms 114936 KB Output is correct
5 Correct 65 ms 71032 KB Output is correct
6 Correct 500 ms 118172 KB Output is correct
7 Correct 269 ms 95984 KB Output is correct
8 Correct 163 ms 91988 KB Output is correct
9 Correct 392 ms 118744 KB Output is correct
10 Correct 386 ms 115020 KB Output is correct
11 Correct 338 ms 112200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 70904 KB Output is correct
2 Correct 65 ms 70904 KB Output is correct
3 Correct 77 ms 70904 KB Output is correct
4 Correct 65 ms 70904 KB Output is correct
5 Correct 76 ms 70904 KB Output is correct
6 Correct 69 ms 70904 KB Output is correct
7 Correct 72 ms 71032 KB Output is correct
8 Correct 67 ms 70904 KB Output is correct
9 Correct 69 ms 70904 KB Output is correct
10 Correct 68 ms 70892 KB Output is correct
11 Correct 65 ms 70904 KB Output is correct
12 Correct 64 ms 70904 KB Output is correct
13 Correct 65 ms 71032 KB Output is correct
14 Correct 63 ms 70904 KB Output is correct
15 Correct 65 ms 70904 KB Output is correct
16 Correct 64 ms 70904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 70904 KB Output is correct
2 Correct 65 ms 70904 KB Output is correct
3 Correct 77 ms 70904 KB Output is correct
4 Correct 65 ms 70904 KB Output is correct
5 Correct 76 ms 70904 KB Output is correct
6 Correct 69 ms 70904 KB Output is correct
7 Correct 72 ms 71032 KB Output is correct
8 Correct 67 ms 70904 KB Output is correct
9 Correct 69 ms 70904 KB Output is correct
10 Correct 68 ms 70892 KB Output is correct
11 Correct 65 ms 70904 KB Output is correct
12 Correct 64 ms 70904 KB Output is correct
13 Correct 65 ms 71032 KB Output is correct
14 Correct 63 ms 70904 KB Output is correct
15 Correct 65 ms 70904 KB Output is correct
16 Correct 64 ms 70904 KB Output is correct
17 Correct 74 ms 71332 KB Output is correct
18 Correct 70 ms 71356 KB Output is correct
19 Correct 70 ms 71416 KB Output is correct
20 Correct 69 ms 71288 KB Output is correct
21 Correct 89 ms 71288 KB Output is correct
22 Correct 72 ms 71288 KB Output is correct
23 Correct 82 ms 71288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 70904 KB Output is correct
2 Correct 65 ms 70904 KB Output is correct
3 Correct 77 ms 70904 KB Output is correct
4 Correct 65 ms 70904 KB Output is correct
5 Correct 76 ms 70904 KB Output is correct
6 Correct 69 ms 70904 KB Output is correct
7 Correct 72 ms 71032 KB Output is correct
8 Correct 67 ms 70904 KB Output is correct
9 Correct 69 ms 70904 KB Output is correct
10 Correct 68 ms 70892 KB Output is correct
11 Correct 65 ms 70904 KB Output is correct
12 Correct 64 ms 70904 KB Output is correct
13 Correct 65 ms 71032 KB Output is correct
14 Correct 63 ms 70904 KB Output is correct
15 Correct 65 ms 70904 KB Output is correct
16 Correct 64 ms 70904 KB Output is correct
17 Correct 74 ms 71332 KB Output is correct
18 Correct 70 ms 71356 KB Output is correct
19 Correct 70 ms 71416 KB Output is correct
20 Correct 69 ms 71288 KB Output is correct
21 Correct 89 ms 71288 KB Output is correct
22 Correct 72 ms 71288 KB Output is correct
23 Correct 82 ms 71288 KB Output is correct
24 Correct 406 ms 103324 KB Output is correct
25 Correct 420 ms 104924 KB Output is correct
26 Correct 408 ms 103368 KB Output is correct
27 Correct 395 ms 107932 KB Output is correct
28 Correct 463 ms 105048 KB Output is correct
29 Correct 463 ms 104868 KB Output is correct
30 Correct 772 ms 106932 KB Output is correct
31 Correct 309 ms 90692 KB Output is correct
32 Correct 198 ms 85496 KB Output is correct
33 Correct 466 ms 104208 KB Output is correct
34 Correct 596 ms 105836 KB Output is correct
35 Correct 658 ms 106872 KB Output is correct
36 Correct 691 ms 106772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 70904 KB Output is correct
2 Correct 65 ms 70904 KB Output is correct
3 Correct 77 ms 70904 KB Output is correct
4 Correct 65 ms 70904 KB Output is correct
5 Correct 76 ms 70904 KB Output is correct
6 Correct 69 ms 70904 KB Output is correct
7 Correct 72 ms 71032 KB Output is correct
8 Correct 67 ms 70904 KB Output is correct
9 Correct 69 ms 70904 KB Output is correct
10 Correct 68 ms 70892 KB Output is correct
11 Correct 65 ms 70904 KB Output is correct
12 Correct 64 ms 70904 KB Output is correct
13 Correct 65 ms 71032 KB Output is correct
14 Correct 63 ms 70904 KB Output is correct
15 Correct 65 ms 70904 KB Output is correct
16 Correct 64 ms 70904 KB Output is correct
17 Correct 74 ms 71332 KB Output is correct
18 Correct 70 ms 71356 KB Output is correct
19 Correct 70 ms 71416 KB Output is correct
20 Correct 69 ms 71288 KB Output is correct
21 Correct 89 ms 71288 KB Output is correct
22 Correct 72 ms 71288 KB Output is correct
23 Correct 82 ms 71288 KB Output is correct
24 Correct 406 ms 103324 KB Output is correct
25 Correct 420 ms 104924 KB Output is correct
26 Correct 408 ms 103368 KB Output is correct
27 Correct 395 ms 107932 KB Output is correct
28 Correct 463 ms 105048 KB Output is correct
29 Correct 463 ms 104868 KB Output is correct
30 Correct 772 ms 106932 KB Output is correct
31 Correct 309 ms 90692 KB Output is correct
32 Correct 198 ms 85496 KB Output is correct
33 Correct 466 ms 104208 KB Output is correct
34 Correct 596 ms 105836 KB Output is correct
35 Correct 658 ms 106872 KB Output is correct
36 Correct 691 ms 106772 KB Output is correct
37 Correct 423 ms 116452 KB Output is correct
38 Correct 501 ms 121208 KB Output is correct
39 Correct 448 ms 118340 KB Output is correct
40 Correct 517 ms 118596 KB Output is correct
41 Correct 76 ms 70904 KB Output is correct
42 Correct 880 ms 120184 KB Output is correct
43 Correct 591 ms 116968 KB Output is correct
44 Correct 660 ms 118768 KB Output is correct
45 Correct 760 ms 113784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 70904 KB Output is correct
2 Correct 65 ms 70904 KB Output is correct
3 Correct 77 ms 70904 KB Output is correct
4 Correct 65 ms 70904 KB Output is correct
5 Correct 76 ms 70904 KB Output is correct
6 Correct 69 ms 70904 KB Output is correct
7 Correct 72 ms 71032 KB Output is correct
8 Correct 67 ms 70904 KB Output is correct
9 Correct 69 ms 70904 KB Output is correct
10 Correct 68 ms 70892 KB Output is correct
11 Correct 65 ms 70904 KB Output is correct
12 Correct 64 ms 70904 KB Output is correct
13 Correct 65 ms 71032 KB Output is correct
14 Correct 63 ms 70904 KB Output is correct
15 Correct 65 ms 70904 KB Output is correct
16 Correct 64 ms 70904 KB Output is correct
17 Correct 74 ms 71332 KB Output is correct
18 Correct 70 ms 71356 KB Output is correct
19 Correct 70 ms 71416 KB Output is correct
20 Correct 69 ms 71288 KB Output is correct
21 Correct 89 ms 71288 KB Output is correct
22 Correct 72 ms 71288 KB Output is correct
23 Correct 82 ms 71288 KB Output is correct
24 Correct 406 ms 103324 KB Output is correct
25 Correct 420 ms 104924 KB Output is correct
26 Correct 408 ms 103368 KB Output is correct
27 Correct 395 ms 107932 KB Output is correct
28 Correct 463 ms 105048 KB Output is correct
29 Correct 463 ms 104868 KB Output is correct
30 Correct 772 ms 106932 KB Output is correct
31 Correct 309 ms 90692 KB Output is correct
32 Correct 198 ms 85496 KB Output is correct
33 Correct 466 ms 104208 KB Output is correct
34 Correct 596 ms 105836 KB Output is correct
35 Correct 658 ms 106872 KB Output is correct
36 Correct 691 ms 106772 KB Output is correct
37 Correct 423 ms 116452 KB Output is correct
38 Correct 501 ms 121208 KB Output is correct
39 Correct 448 ms 118340 KB Output is correct
40 Correct 517 ms 118596 KB Output is correct
41 Correct 76 ms 70904 KB Output is correct
42 Correct 880 ms 120184 KB Output is correct
43 Correct 591 ms 116968 KB Output is correct
44 Correct 660 ms 118768 KB Output is correct
45 Correct 760 ms 113784 KB Output is correct
46 Correct 2053 ms 291424 KB Output is correct
47 Correct 2441 ms 314560 KB Output is correct
48 Correct 2241 ms 301164 KB Output is correct
49 Correct 2116 ms 301168 KB Output is correct
50 Correct 5234 ms 309800 KB Output is correct
51 Correct 3087 ms 289728 KB Output is correct
52 Correct 3908 ms 296660 KB Output is correct
53 Correct 4486 ms 277900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 507 ms 118776 KB Output is correct
2 Correct 470 ms 119384 KB Output is correct
3 Correct 411 ms 117652 KB Output is correct
4 Correct 389 ms 114936 KB Output is correct
5 Correct 65 ms 71032 KB Output is correct
6 Correct 500 ms 118172 KB Output is correct
7 Correct 269 ms 95984 KB Output is correct
8 Correct 163 ms 91988 KB Output is correct
9 Correct 392 ms 118744 KB Output is correct
10 Correct 386 ms 115020 KB Output is correct
11 Correct 338 ms 112200 KB Output is correct
12 Correct 68 ms 70904 KB Output is correct
13 Correct 65 ms 70904 KB Output is correct
14 Correct 77 ms 70904 KB Output is correct
15 Correct 65 ms 70904 KB Output is correct
16 Correct 76 ms 70904 KB Output is correct
17 Correct 69 ms 70904 KB Output is correct
18 Correct 72 ms 71032 KB Output is correct
19 Correct 67 ms 70904 KB Output is correct
20 Correct 69 ms 70904 KB Output is correct
21 Correct 68 ms 70892 KB Output is correct
22 Correct 65 ms 70904 KB Output is correct
23 Correct 64 ms 70904 KB Output is correct
24 Correct 65 ms 71032 KB Output is correct
25 Correct 63 ms 70904 KB Output is correct
26 Correct 65 ms 70904 KB Output is correct
27 Correct 64 ms 70904 KB Output is correct
28 Correct 74 ms 71332 KB Output is correct
29 Correct 70 ms 71356 KB Output is correct
30 Correct 70 ms 71416 KB Output is correct
31 Correct 69 ms 71288 KB Output is correct
32 Correct 89 ms 71288 KB Output is correct
33 Correct 72 ms 71288 KB Output is correct
34 Correct 82 ms 71288 KB Output is correct
35 Correct 406 ms 103324 KB Output is correct
36 Correct 420 ms 104924 KB Output is correct
37 Correct 408 ms 103368 KB Output is correct
38 Correct 395 ms 107932 KB Output is correct
39 Correct 463 ms 105048 KB Output is correct
40 Correct 463 ms 104868 KB Output is correct
41 Correct 772 ms 106932 KB Output is correct
42 Correct 309 ms 90692 KB Output is correct
43 Correct 198 ms 85496 KB Output is correct
44 Correct 466 ms 104208 KB Output is correct
45 Correct 596 ms 105836 KB Output is correct
46 Correct 658 ms 106872 KB Output is correct
47 Correct 691 ms 106772 KB Output is correct
48 Correct 423 ms 116452 KB Output is correct
49 Correct 501 ms 121208 KB Output is correct
50 Correct 448 ms 118340 KB Output is correct
51 Correct 517 ms 118596 KB Output is correct
52 Correct 76 ms 70904 KB Output is correct
53 Correct 880 ms 120184 KB Output is correct
54 Correct 591 ms 116968 KB Output is correct
55 Correct 660 ms 118768 KB Output is correct
56 Correct 760 ms 113784 KB Output is correct
57 Incorrect 464 ms 117064 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 507 ms 118776 KB Output is correct
2 Correct 470 ms 119384 KB Output is correct
3 Correct 411 ms 117652 KB Output is correct
4 Correct 389 ms 114936 KB Output is correct
5 Correct 65 ms 71032 KB Output is correct
6 Correct 500 ms 118172 KB Output is correct
7 Correct 269 ms 95984 KB Output is correct
8 Correct 163 ms 91988 KB Output is correct
9 Correct 392 ms 118744 KB Output is correct
10 Correct 386 ms 115020 KB Output is correct
11 Correct 338 ms 112200 KB Output is correct
12 Correct 68 ms 70904 KB Output is correct
13 Correct 65 ms 70904 KB Output is correct
14 Correct 77 ms 70904 KB Output is correct
15 Correct 65 ms 70904 KB Output is correct
16 Correct 76 ms 70904 KB Output is correct
17 Correct 69 ms 70904 KB Output is correct
18 Correct 72 ms 71032 KB Output is correct
19 Correct 67 ms 70904 KB Output is correct
20 Correct 69 ms 70904 KB Output is correct
21 Correct 68 ms 70892 KB Output is correct
22 Correct 65 ms 70904 KB Output is correct
23 Correct 64 ms 70904 KB Output is correct
24 Correct 65 ms 71032 KB Output is correct
25 Correct 63 ms 70904 KB Output is correct
26 Correct 65 ms 70904 KB Output is correct
27 Correct 64 ms 70904 KB Output is correct
28 Correct 74 ms 71332 KB Output is correct
29 Correct 70 ms 71356 KB Output is correct
30 Correct 70 ms 71416 KB Output is correct
31 Correct 69 ms 71288 KB Output is correct
32 Correct 89 ms 71288 KB Output is correct
33 Correct 72 ms 71288 KB Output is correct
34 Correct 82 ms 71288 KB Output is correct
35 Correct 406 ms 103324 KB Output is correct
36 Correct 420 ms 104924 KB Output is correct
37 Correct 408 ms 103368 KB Output is correct
38 Correct 395 ms 107932 KB Output is correct
39 Correct 463 ms 105048 KB Output is correct
40 Correct 463 ms 104868 KB Output is correct
41 Correct 772 ms 106932 KB Output is correct
42 Correct 309 ms 90692 KB Output is correct
43 Correct 198 ms 85496 KB Output is correct
44 Correct 466 ms 104208 KB Output is correct
45 Correct 596 ms 105836 KB Output is correct
46 Correct 658 ms 106872 KB Output is correct
47 Correct 691 ms 106772 KB Output is correct
48 Correct 423 ms 116452 KB Output is correct
49 Correct 501 ms 121208 KB Output is correct
50 Correct 448 ms 118340 KB Output is correct
51 Correct 517 ms 118596 KB Output is correct
52 Correct 76 ms 70904 KB Output is correct
53 Correct 880 ms 120184 KB Output is correct
54 Correct 591 ms 116968 KB Output is correct
55 Correct 660 ms 118768 KB Output is correct
56 Correct 760 ms 113784 KB Output is correct
57 Correct 2053 ms 291424 KB Output is correct
58 Correct 2441 ms 314560 KB Output is correct
59 Correct 2241 ms 301164 KB Output is correct
60 Correct 2116 ms 301168 KB Output is correct
61 Correct 5234 ms 309800 KB Output is correct
62 Correct 3087 ms 289728 KB Output is correct
63 Correct 3908 ms 296660 KB Output is correct
64 Correct 4486 ms 277900 KB Output is correct
65 Incorrect 464 ms 117064 KB Output isn't correct
66 Halted 0 ms 0 KB -