Submission #103937

# Submission time Handle Problem Language Result Execution time Memory
103937 2019-04-03T10:40:32 Z mzhao Two Dishes (JOI19_dishes) C++11
74 / 100
4588 ms 221632 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];

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];
	}
	ll cnt = 0;
	for (int i = 1; i <= N; i++) {
		ma[i] = findm(sb, M+1, TA[i]-sa[i]);
		if (VA[i] < 0) {
			cnt += VA[i];
			hor[i-1].push_back({min(M, (ll) ma[i]+1), -VA[i]});
		} else {
			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 (VB[i] < 0) {
			cnt += VB[i];
			if (mb[i]+1 > 0) {
				ver[mb[i]+1].push_back({min(M, (ll) i-1), -VB[i]});
			} else cnt -= VB[i];
		} else {
			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);
		}
	}
	D("cnt = %lld\n", cnt);
	cout << query(1, 0, M+1, 0, M+1)+cnt << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 462 ms 87092 KB Output is correct
2 Correct 458 ms 86236 KB Output is correct
3 Correct 442 ms 84848 KB Output is correct
4 Correct 433 ms 81796 KB Output is correct
5 Correct 53 ms 47352 KB Output is correct
6 Correct 458 ms 85456 KB Output is correct
7 Correct 260 ms 69856 KB Output is correct
8 Correct 166 ms 65532 KB Output is correct
9 Correct 446 ms 84804 KB Output is correct
10 Correct 404 ms 87804 KB Output is correct
11 Correct 350 ms 84828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47324 KB Output is correct
2 Correct 51 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 53 ms 47352 KB Output is correct
5 Correct 46 ms 47380 KB Output is correct
6 Correct 50 ms 47480 KB Output is correct
7 Correct 52 ms 47452 KB Output is correct
8 Correct 49 ms 47352 KB Output is correct
9 Correct 47 ms 47480 KB Output is correct
10 Correct 47 ms 47352 KB Output is correct
11 Correct 48 ms 47352 KB Output is correct
12 Correct 50 ms 47360 KB Output is correct
13 Correct 45 ms 47352 KB Output is correct
14 Correct 47 ms 47352 KB Output is correct
15 Correct 46 ms 47352 KB Output is correct
16 Correct 44 ms 47352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47324 KB Output is correct
2 Correct 51 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 53 ms 47352 KB Output is correct
5 Correct 46 ms 47380 KB Output is correct
6 Correct 50 ms 47480 KB Output is correct
7 Correct 52 ms 47452 KB Output is correct
8 Correct 49 ms 47352 KB Output is correct
9 Correct 47 ms 47480 KB Output is correct
10 Correct 47 ms 47352 KB Output is correct
11 Correct 48 ms 47352 KB Output is correct
12 Correct 50 ms 47360 KB Output is correct
13 Correct 45 ms 47352 KB Output is correct
14 Correct 47 ms 47352 KB Output is correct
15 Correct 46 ms 47352 KB Output is correct
16 Correct 44 ms 47352 KB Output is correct
17 Correct 51 ms 47908 KB Output is correct
18 Correct 51 ms 47880 KB Output is correct
19 Correct 50 ms 47868 KB Output is correct
20 Correct 49 ms 47864 KB Output is correct
21 Correct 48 ms 47864 KB Output is correct
22 Correct 49 ms 47736 KB Output is correct
23 Correct 53 ms 47736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47324 KB Output is correct
2 Correct 51 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 53 ms 47352 KB Output is correct
5 Correct 46 ms 47380 KB Output is correct
6 Correct 50 ms 47480 KB Output is correct
7 Correct 52 ms 47452 KB Output is correct
8 Correct 49 ms 47352 KB Output is correct
9 Correct 47 ms 47480 KB Output is correct
10 Correct 47 ms 47352 KB Output is correct
11 Correct 48 ms 47352 KB Output is correct
12 Correct 50 ms 47360 KB Output is correct
13 Correct 45 ms 47352 KB Output is correct
14 Correct 47 ms 47352 KB Output is correct
15 Correct 46 ms 47352 KB Output is correct
16 Correct 44 ms 47352 KB Output is correct
17 Correct 51 ms 47908 KB Output is correct
18 Correct 51 ms 47880 KB Output is correct
19 Correct 50 ms 47868 KB Output is correct
20 Correct 49 ms 47864 KB Output is correct
21 Correct 48 ms 47864 KB Output is correct
22 Correct 49 ms 47736 KB Output is correct
23 Correct 53 ms 47736 KB Output is correct
24 Correct 367 ms 84080 KB Output is correct
25 Correct 447 ms 84828 KB Output is correct
26 Correct 395 ms 83416 KB Output is correct
27 Correct 415 ms 87912 KB Output is correct
28 Correct 474 ms 85132 KB Output is correct
29 Correct 396 ms 84828 KB Output is correct
30 Correct 737 ms 86884 KB Output is correct
31 Correct 288 ms 70892 KB Output is correct
32 Correct 157 ms 65656 KB Output is correct
33 Correct 493 ms 83992 KB Output is correct
34 Correct 659 ms 85888 KB Output is correct
35 Correct 624 ms 86996 KB Output is correct
36 Correct 632 ms 86852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47324 KB Output is correct
2 Correct 51 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 53 ms 47352 KB Output is correct
5 Correct 46 ms 47380 KB Output is correct
6 Correct 50 ms 47480 KB Output is correct
7 Correct 52 ms 47452 KB Output is correct
8 Correct 49 ms 47352 KB Output is correct
9 Correct 47 ms 47480 KB Output is correct
10 Correct 47 ms 47352 KB Output is correct
11 Correct 48 ms 47352 KB Output is correct
12 Correct 50 ms 47360 KB Output is correct
13 Correct 45 ms 47352 KB Output is correct
14 Correct 47 ms 47352 KB Output is correct
15 Correct 46 ms 47352 KB Output is correct
16 Correct 44 ms 47352 KB Output is correct
17 Correct 51 ms 47908 KB Output is correct
18 Correct 51 ms 47880 KB Output is correct
19 Correct 50 ms 47868 KB Output is correct
20 Correct 49 ms 47864 KB Output is correct
21 Correct 48 ms 47864 KB Output is correct
22 Correct 49 ms 47736 KB Output is correct
23 Correct 53 ms 47736 KB Output is correct
24 Correct 367 ms 84080 KB Output is correct
25 Correct 447 ms 84828 KB Output is correct
26 Correct 395 ms 83416 KB Output is correct
27 Correct 415 ms 87912 KB Output is correct
28 Correct 474 ms 85132 KB Output is correct
29 Correct 396 ms 84828 KB Output is correct
30 Correct 737 ms 86884 KB Output is correct
31 Correct 288 ms 70892 KB Output is correct
32 Correct 157 ms 65656 KB Output is correct
33 Correct 493 ms 83992 KB Output is correct
34 Correct 659 ms 85888 KB Output is correct
35 Correct 624 ms 86996 KB Output is correct
36 Correct 632 ms 86852 KB Output is correct
37 Correct 380 ms 84196 KB Output is correct
38 Correct 404 ms 87808 KB Output is correct
39 Correct 424 ms 87876 KB Output is correct
40 Correct 420 ms 87684 KB Output is correct
41 Correct 46 ms 47360 KB Output is correct
42 Correct 756 ms 86744 KB Output is correct
43 Correct 493 ms 83764 KB Output is correct
44 Correct 599 ms 85616 KB Output is correct
45 Correct 718 ms 86932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47324 KB Output is correct
2 Correct 51 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 53 ms 47352 KB Output is correct
5 Correct 46 ms 47380 KB Output is correct
6 Correct 50 ms 47480 KB Output is correct
7 Correct 52 ms 47452 KB Output is correct
8 Correct 49 ms 47352 KB Output is correct
9 Correct 47 ms 47480 KB Output is correct
10 Correct 47 ms 47352 KB Output is correct
11 Correct 48 ms 47352 KB Output is correct
12 Correct 50 ms 47360 KB Output is correct
13 Correct 45 ms 47352 KB Output is correct
14 Correct 47 ms 47352 KB Output is correct
15 Correct 46 ms 47352 KB Output is correct
16 Correct 44 ms 47352 KB Output is correct
17 Correct 51 ms 47908 KB Output is correct
18 Correct 51 ms 47880 KB Output is correct
19 Correct 50 ms 47868 KB Output is correct
20 Correct 49 ms 47864 KB Output is correct
21 Correct 48 ms 47864 KB Output is correct
22 Correct 49 ms 47736 KB Output is correct
23 Correct 53 ms 47736 KB Output is correct
24 Correct 367 ms 84080 KB Output is correct
25 Correct 447 ms 84828 KB Output is correct
26 Correct 395 ms 83416 KB Output is correct
27 Correct 415 ms 87912 KB Output is correct
28 Correct 474 ms 85132 KB Output is correct
29 Correct 396 ms 84828 KB Output is correct
30 Correct 737 ms 86884 KB Output is correct
31 Correct 288 ms 70892 KB Output is correct
32 Correct 157 ms 65656 KB Output is correct
33 Correct 493 ms 83992 KB Output is correct
34 Correct 659 ms 85888 KB Output is correct
35 Correct 624 ms 86996 KB Output is correct
36 Correct 632 ms 86852 KB Output is correct
37 Correct 380 ms 84196 KB Output is correct
38 Correct 404 ms 87808 KB Output is correct
39 Correct 424 ms 87876 KB Output is correct
40 Correct 420 ms 87684 KB Output is correct
41 Correct 46 ms 47360 KB Output is correct
42 Correct 756 ms 86744 KB Output is correct
43 Correct 493 ms 83764 KB Output is correct
44 Correct 599 ms 85616 KB Output is correct
45 Correct 718 ms 86932 KB Output is correct
46 Correct 1782 ms 198384 KB Output is correct
47 Correct 2057 ms 221632 KB Output is correct
48 Correct 2302 ms 221500 KB Output is correct
49 Correct 2294 ms 221592 KB Output is correct
50 Correct 4588 ms 216768 KB Output is correct
51 Correct 2903 ms 199464 KB Output is correct
52 Correct 3453 ms 207328 KB Output is correct
53 Correct 4230 ms 215840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 462 ms 87092 KB Output is correct
2 Correct 458 ms 86236 KB Output is correct
3 Correct 442 ms 84848 KB Output is correct
4 Correct 433 ms 81796 KB Output is correct
5 Correct 53 ms 47352 KB Output is correct
6 Correct 458 ms 85456 KB Output is correct
7 Correct 260 ms 69856 KB Output is correct
8 Correct 166 ms 65532 KB Output is correct
9 Correct 446 ms 84804 KB Output is correct
10 Correct 404 ms 87804 KB Output is correct
11 Correct 350 ms 84828 KB Output is correct
12 Correct 46 ms 47324 KB Output is correct
13 Correct 51 ms 47352 KB Output is correct
14 Correct 46 ms 47352 KB Output is correct
15 Correct 53 ms 47352 KB Output is correct
16 Correct 46 ms 47380 KB Output is correct
17 Correct 50 ms 47480 KB Output is correct
18 Correct 52 ms 47452 KB Output is correct
19 Correct 49 ms 47352 KB Output is correct
20 Correct 47 ms 47480 KB Output is correct
21 Correct 47 ms 47352 KB Output is correct
22 Correct 48 ms 47352 KB Output is correct
23 Correct 50 ms 47360 KB Output is correct
24 Correct 45 ms 47352 KB Output is correct
25 Correct 47 ms 47352 KB Output is correct
26 Correct 46 ms 47352 KB Output is correct
27 Correct 44 ms 47352 KB Output is correct
28 Correct 51 ms 47908 KB Output is correct
29 Correct 51 ms 47880 KB Output is correct
30 Correct 50 ms 47868 KB Output is correct
31 Correct 49 ms 47864 KB Output is correct
32 Correct 48 ms 47864 KB Output is correct
33 Correct 49 ms 47736 KB Output is correct
34 Correct 53 ms 47736 KB Output is correct
35 Correct 367 ms 84080 KB Output is correct
36 Correct 447 ms 84828 KB Output is correct
37 Correct 395 ms 83416 KB Output is correct
38 Correct 415 ms 87912 KB Output is correct
39 Correct 474 ms 85132 KB Output is correct
40 Correct 396 ms 84828 KB Output is correct
41 Correct 737 ms 86884 KB Output is correct
42 Correct 288 ms 70892 KB Output is correct
43 Correct 157 ms 65656 KB Output is correct
44 Correct 493 ms 83992 KB Output is correct
45 Correct 659 ms 85888 KB Output is correct
46 Correct 624 ms 86996 KB Output is correct
47 Correct 632 ms 86852 KB Output is correct
48 Correct 380 ms 84196 KB Output is correct
49 Correct 404 ms 87808 KB Output is correct
50 Correct 424 ms 87876 KB Output is correct
51 Correct 420 ms 87684 KB Output is correct
52 Correct 46 ms 47360 KB Output is correct
53 Correct 756 ms 86744 KB Output is correct
54 Correct 493 ms 83764 KB Output is correct
55 Correct 599 ms 85616 KB Output is correct
56 Correct 718 ms 86932 KB Output is correct
57 Correct 547 ms 81180 KB Output is correct
58 Correct 402 ms 98076 KB Output is correct
59 Correct 397 ms 92792 KB Output is correct
60 Correct 609 ms 92840 KB Output is correct
61 Correct 767 ms 93860 KB Output is correct
62 Correct 44 ms 47352 KB Output is correct
63 Incorrect 885 ms 96476 KB Output isn't correct
64 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 462 ms 87092 KB Output is correct
2 Correct 458 ms 86236 KB Output is correct
3 Correct 442 ms 84848 KB Output is correct
4 Correct 433 ms 81796 KB Output is correct
5 Correct 53 ms 47352 KB Output is correct
6 Correct 458 ms 85456 KB Output is correct
7 Correct 260 ms 69856 KB Output is correct
8 Correct 166 ms 65532 KB Output is correct
9 Correct 446 ms 84804 KB Output is correct
10 Correct 404 ms 87804 KB Output is correct
11 Correct 350 ms 84828 KB Output is correct
12 Correct 46 ms 47324 KB Output is correct
13 Correct 51 ms 47352 KB Output is correct
14 Correct 46 ms 47352 KB Output is correct
15 Correct 53 ms 47352 KB Output is correct
16 Correct 46 ms 47380 KB Output is correct
17 Correct 50 ms 47480 KB Output is correct
18 Correct 52 ms 47452 KB Output is correct
19 Correct 49 ms 47352 KB Output is correct
20 Correct 47 ms 47480 KB Output is correct
21 Correct 47 ms 47352 KB Output is correct
22 Correct 48 ms 47352 KB Output is correct
23 Correct 50 ms 47360 KB Output is correct
24 Correct 45 ms 47352 KB Output is correct
25 Correct 47 ms 47352 KB Output is correct
26 Correct 46 ms 47352 KB Output is correct
27 Correct 44 ms 47352 KB Output is correct
28 Correct 51 ms 47908 KB Output is correct
29 Correct 51 ms 47880 KB Output is correct
30 Correct 50 ms 47868 KB Output is correct
31 Correct 49 ms 47864 KB Output is correct
32 Correct 48 ms 47864 KB Output is correct
33 Correct 49 ms 47736 KB Output is correct
34 Correct 53 ms 47736 KB Output is correct
35 Correct 367 ms 84080 KB Output is correct
36 Correct 447 ms 84828 KB Output is correct
37 Correct 395 ms 83416 KB Output is correct
38 Correct 415 ms 87912 KB Output is correct
39 Correct 474 ms 85132 KB Output is correct
40 Correct 396 ms 84828 KB Output is correct
41 Correct 737 ms 86884 KB Output is correct
42 Correct 288 ms 70892 KB Output is correct
43 Correct 157 ms 65656 KB Output is correct
44 Correct 493 ms 83992 KB Output is correct
45 Correct 659 ms 85888 KB Output is correct
46 Correct 624 ms 86996 KB Output is correct
47 Correct 632 ms 86852 KB Output is correct
48 Correct 380 ms 84196 KB Output is correct
49 Correct 404 ms 87808 KB Output is correct
50 Correct 424 ms 87876 KB Output is correct
51 Correct 420 ms 87684 KB Output is correct
52 Correct 46 ms 47360 KB Output is correct
53 Correct 756 ms 86744 KB Output is correct
54 Correct 493 ms 83764 KB Output is correct
55 Correct 599 ms 85616 KB Output is correct
56 Correct 718 ms 86932 KB Output is correct
57 Correct 1782 ms 198384 KB Output is correct
58 Correct 2057 ms 221632 KB Output is correct
59 Correct 2302 ms 221500 KB Output is correct
60 Correct 2294 ms 221592 KB Output is correct
61 Correct 4588 ms 216768 KB Output is correct
62 Correct 2903 ms 199464 KB Output is correct
63 Correct 3453 ms 207328 KB Output is correct
64 Correct 4230 ms 215840 KB Output is correct
65 Correct 547 ms 81180 KB Output is correct
66 Correct 402 ms 98076 KB Output is correct
67 Correct 397 ms 92792 KB Output is correct
68 Correct 609 ms 92840 KB Output is correct
69 Correct 767 ms 93860 KB Output is correct
70 Correct 44 ms 47352 KB Output is correct
71 Incorrect 885 ms 96476 KB Output isn't correct
72 Halted 0 ms 0 KB -