답안 #203408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203408 2020-02-20T14:09:35 Z dennisstar Two Dishes (JOI19_dishes) C++17
100 / 100
7065 ms 236196 KB
#include <bits/stdc++.h>
#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];
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;
}
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]);
}
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]);
}
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<pair<int, ll> > 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]);
	}qu[N+1].eb(M-1, -INF);
	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:46: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:47: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:48: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];
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 707 ms 63204 KB Output is correct
2 Correct 742 ms 74264 KB Output is correct
3 Correct 675 ms 73180 KB Output is correct
4 Correct 564 ms 61564 KB Output is correct
5 Correct 20 ms 24952 KB Output is correct
6 Correct 714 ms 73584 KB Output is correct
7 Correct 359 ms 58076 KB Output is correct
8 Correct 153 ms 43000 KB Output is correct
9 Correct 674 ms 73180 KB Output is correct
10 Correct 707 ms 71948 KB Output is correct
11 Correct 613 ms 72412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24952 KB Output is correct
2 Correct 20 ms 24952 KB Output is correct
3 Correct 21 ms 24952 KB Output is correct
4 Correct 22 ms 25128 KB Output is correct
5 Correct 20 ms 24952 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 24952 KB Output is correct
10 Correct 20 ms 24952 KB Output is correct
11 Correct 20 ms 24952 KB Output is correct
12 Correct 21 ms 24952 KB Output is correct
13 Correct 22 ms 24952 KB Output is correct
14 Correct 21 ms 24956 KB Output is correct
15 Correct 20 ms 24952 KB Output is correct
16 Correct 21 ms 24952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24952 KB Output is correct
2 Correct 20 ms 24952 KB Output is correct
3 Correct 21 ms 24952 KB Output is correct
4 Correct 22 ms 25128 KB Output is correct
5 Correct 20 ms 24952 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 24952 KB Output is correct
10 Correct 20 ms 24952 KB Output is correct
11 Correct 20 ms 24952 KB Output is correct
12 Correct 21 ms 24952 KB Output is correct
13 Correct 22 ms 24952 KB Output is correct
14 Correct 21 ms 24956 KB Output is correct
15 Correct 20 ms 24952 KB Output is correct
16 Correct 21 ms 24952 KB Output is correct
17 Correct 25 ms 25468 KB Output is correct
18 Correct 24 ms 25464 KB Output is correct
19 Correct 26 ms 25464 KB Output is correct
20 Correct 25 ms 25464 KB Output is correct
21 Correct 26 ms 25464 KB Output is correct
22 Correct 26 ms 25464 KB Output is correct
23 Correct 27 ms 25464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24952 KB Output is correct
2 Correct 20 ms 24952 KB Output is correct
3 Correct 21 ms 24952 KB Output is correct
4 Correct 22 ms 25128 KB Output is correct
5 Correct 20 ms 24952 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 24952 KB Output is correct
10 Correct 20 ms 24952 KB Output is correct
11 Correct 20 ms 24952 KB Output is correct
12 Correct 21 ms 24952 KB Output is correct
13 Correct 22 ms 24952 KB Output is correct
14 Correct 21 ms 24956 KB Output is correct
15 Correct 20 ms 24952 KB Output is correct
16 Correct 21 ms 24952 KB Output is correct
17 Correct 25 ms 25468 KB Output is correct
18 Correct 24 ms 25464 KB Output is correct
19 Correct 26 ms 25464 KB Output is correct
20 Correct 25 ms 25464 KB Output is correct
21 Correct 26 ms 25464 KB Output is correct
22 Correct 26 ms 25464 KB Output is correct
23 Correct 27 ms 25464 KB Output is correct
24 Correct 1072 ms 71780 KB Output is correct
25 Correct 571 ms 70100 KB Output is correct
26 Correct 633 ms 71652 KB Output is correct
27 Correct 608 ms 71544 KB Output is correct
28 Correct 731 ms 72660 KB Output is correct
29 Correct 647 ms 73052 KB Output is correct
30 Correct 1095 ms 75260 KB Output is correct
31 Correct 383 ms 58784 KB Output is correct
32 Correct 153 ms 41208 KB Output is correct
33 Correct 661 ms 68988 KB Output is correct
34 Correct 949 ms 74636 KB Output is correct
35 Correct 1024 ms 71160 KB Output is correct
36 Correct 977 ms 70904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24952 KB Output is correct
2 Correct 20 ms 24952 KB Output is correct
3 Correct 21 ms 24952 KB Output is correct
4 Correct 22 ms 25128 KB Output is correct
5 Correct 20 ms 24952 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 24952 KB Output is correct
10 Correct 20 ms 24952 KB Output is correct
11 Correct 20 ms 24952 KB Output is correct
12 Correct 21 ms 24952 KB Output is correct
13 Correct 22 ms 24952 KB Output is correct
14 Correct 21 ms 24956 KB Output is correct
15 Correct 20 ms 24952 KB Output is correct
16 Correct 21 ms 24952 KB Output is correct
17 Correct 25 ms 25468 KB Output is correct
18 Correct 24 ms 25464 KB Output is correct
19 Correct 26 ms 25464 KB Output is correct
20 Correct 25 ms 25464 KB Output is correct
21 Correct 26 ms 25464 KB Output is correct
22 Correct 26 ms 25464 KB Output is correct
23 Correct 27 ms 25464 KB Output is correct
24 Correct 1072 ms 71780 KB Output is correct
25 Correct 571 ms 70100 KB Output is correct
26 Correct 633 ms 71652 KB Output is correct
27 Correct 608 ms 71544 KB Output is correct
28 Correct 731 ms 72660 KB Output is correct
29 Correct 647 ms 73052 KB Output is correct
30 Correct 1095 ms 75260 KB Output is correct
31 Correct 383 ms 58784 KB Output is correct
32 Correct 153 ms 41208 KB Output is correct
33 Correct 661 ms 68988 KB Output is correct
34 Correct 949 ms 74636 KB Output is correct
35 Correct 1024 ms 71160 KB Output is correct
36 Correct 977 ms 70904 KB Output is correct
37 Correct 663 ms 71524 KB Output is correct
38 Correct 641 ms 71240 KB Output is correct
39 Correct 759 ms 72696 KB Output is correct
40 Correct 767 ms 72572 KB Output is correct
41 Correct 21 ms 24952 KB Output is correct
42 Correct 1102 ms 74748 KB Output is correct
43 Correct 664 ms 68344 KB Output is correct
44 Correct 954 ms 73460 KB Output is correct
45 Correct 1048 ms 74080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24952 KB Output is correct
2 Correct 20 ms 24952 KB Output is correct
3 Correct 21 ms 24952 KB Output is correct
4 Correct 22 ms 25128 KB Output is correct
5 Correct 20 ms 24952 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 24952 KB Output is correct
10 Correct 20 ms 24952 KB Output is correct
11 Correct 20 ms 24952 KB Output is correct
12 Correct 21 ms 24952 KB Output is correct
13 Correct 22 ms 24952 KB Output is correct
14 Correct 21 ms 24956 KB Output is correct
15 Correct 20 ms 24952 KB Output is correct
16 Correct 21 ms 24952 KB Output is correct
17 Correct 25 ms 25468 KB Output is correct
18 Correct 24 ms 25464 KB Output is correct
19 Correct 26 ms 25464 KB Output is correct
20 Correct 25 ms 25464 KB Output is correct
21 Correct 26 ms 25464 KB Output is correct
22 Correct 26 ms 25464 KB Output is correct
23 Correct 27 ms 25464 KB Output is correct
24 Correct 1072 ms 71780 KB Output is correct
25 Correct 571 ms 70100 KB Output is correct
26 Correct 633 ms 71652 KB Output is correct
27 Correct 608 ms 71544 KB Output is correct
28 Correct 731 ms 72660 KB Output is correct
29 Correct 647 ms 73052 KB Output is correct
30 Correct 1095 ms 75260 KB Output is correct
31 Correct 383 ms 58784 KB Output is correct
32 Correct 153 ms 41208 KB Output is correct
33 Correct 661 ms 68988 KB Output is correct
34 Correct 949 ms 74636 KB Output is correct
35 Correct 1024 ms 71160 KB Output is correct
36 Correct 977 ms 70904 KB Output is correct
37 Correct 663 ms 71524 KB Output is correct
38 Correct 641 ms 71240 KB Output is correct
39 Correct 759 ms 72696 KB Output is correct
40 Correct 767 ms 72572 KB Output is correct
41 Correct 21 ms 24952 KB Output is correct
42 Correct 1102 ms 74748 KB Output is correct
43 Correct 664 ms 68344 KB Output is correct
44 Correct 954 ms 73460 KB Output is correct
45 Correct 1048 ms 74080 KB Output is correct
46 Correct 3429 ms 161108 KB Output is correct
47 Correct 3257 ms 160888 KB Output is correct
48 Correct 3956 ms 168784 KB Output is correct
49 Correct 3931 ms 168708 KB Output is correct
50 Correct 6844 ms 180212 KB Output is correct
51 Correct 3875 ms 147436 KB Output is correct
52 Correct 5355 ms 171960 KB Output is correct
53 Correct 6266 ms 178752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 707 ms 63204 KB Output is correct
2 Correct 742 ms 74264 KB Output is correct
3 Correct 675 ms 73180 KB Output is correct
4 Correct 564 ms 61564 KB Output is correct
5 Correct 20 ms 24952 KB Output is correct
6 Correct 714 ms 73584 KB Output is correct
7 Correct 359 ms 58076 KB Output is correct
8 Correct 153 ms 43000 KB Output is correct
9 Correct 674 ms 73180 KB Output is correct
10 Correct 707 ms 71948 KB Output is correct
11 Correct 613 ms 72412 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 24952 KB Output is correct
15 Correct 22 ms 25128 KB Output is correct
16 Correct 20 ms 24952 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 24952 KB Output is correct
21 Correct 20 ms 24952 KB Output is correct
22 Correct 20 ms 24952 KB Output is correct
23 Correct 21 ms 24952 KB Output is correct
24 Correct 22 ms 24952 KB Output is correct
25 Correct 21 ms 24956 KB Output is correct
26 Correct 20 ms 24952 KB Output is correct
27 Correct 21 ms 24952 KB Output is correct
28 Correct 25 ms 25468 KB Output is correct
29 Correct 24 ms 25464 KB Output is correct
30 Correct 26 ms 25464 KB Output is correct
31 Correct 25 ms 25464 KB Output is correct
32 Correct 26 ms 25464 KB Output is correct
33 Correct 26 ms 25464 KB Output is correct
34 Correct 27 ms 25464 KB Output is correct
35 Correct 1072 ms 71780 KB Output is correct
36 Correct 571 ms 70100 KB Output is correct
37 Correct 633 ms 71652 KB Output is correct
38 Correct 608 ms 71544 KB Output is correct
39 Correct 731 ms 72660 KB Output is correct
40 Correct 647 ms 73052 KB Output is correct
41 Correct 1095 ms 75260 KB Output is correct
42 Correct 383 ms 58784 KB Output is correct
43 Correct 153 ms 41208 KB Output is correct
44 Correct 661 ms 68988 KB Output is correct
45 Correct 949 ms 74636 KB Output is correct
46 Correct 1024 ms 71160 KB Output is correct
47 Correct 977 ms 70904 KB Output is correct
48 Correct 663 ms 71524 KB Output is correct
49 Correct 641 ms 71240 KB Output is correct
50 Correct 759 ms 72696 KB Output is correct
51 Correct 767 ms 72572 KB Output is correct
52 Correct 21 ms 24952 KB Output is correct
53 Correct 1102 ms 74748 KB Output is correct
54 Correct 664 ms 68344 KB Output is correct
55 Correct 954 ms 73460 KB Output is correct
56 Correct 1048 ms 74080 KB Output is correct
57 Correct 660 ms 63972 KB Output is correct
58 Correct 645 ms 76920 KB Output is correct
59 Correct 760 ms 76536 KB Output is correct
60 Correct 773 ms 76540 KB Output is correct
61 Correct 1125 ms 77572 KB Output is correct
62 Correct 20 ms 24952 KB Output is correct
63 Correct 1134 ms 80632 KB Output is correct
64 Correct 683 ms 73976 KB Output is correct
65 Correct 953 ms 79080 KB Output is correct
66 Correct 1014 ms 74104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 707 ms 63204 KB Output is correct
2 Correct 742 ms 74264 KB Output is correct
3 Correct 675 ms 73180 KB Output is correct
4 Correct 564 ms 61564 KB Output is correct
5 Correct 20 ms 24952 KB Output is correct
6 Correct 714 ms 73584 KB Output is correct
7 Correct 359 ms 58076 KB Output is correct
8 Correct 153 ms 43000 KB Output is correct
9 Correct 674 ms 73180 KB Output is correct
10 Correct 707 ms 71948 KB Output is correct
11 Correct 613 ms 72412 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 24952 KB Output is correct
15 Correct 22 ms 25128 KB Output is correct
16 Correct 20 ms 24952 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 24952 KB Output is correct
21 Correct 20 ms 24952 KB Output is correct
22 Correct 20 ms 24952 KB Output is correct
23 Correct 21 ms 24952 KB Output is correct
24 Correct 22 ms 24952 KB Output is correct
25 Correct 21 ms 24956 KB Output is correct
26 Correct 20 ms 24952 KB Output is correct
27 Correct 21 ms 24952 KB Output is correct
28 Correct 25 ms 25468 KB Output is correct
29 Correct 24 ms 25464 KB Output is correct
30 Correct 26 ms 25464 KB Output is correct
31 Correct 25 ms 25464 KB Output is correct
32 Correct 26 ms 25464 KB Output is correct
33 Correct 26 ms 25464 KB Output is correct
34 Correct 27 ms 25464 KB Output is correct
35 Correct 1072 ms 71780 KB Output is correct
36 Correct 571 ms 70100 KB Output is correct
37 Correct 633 ms 71652 KB Output is correct
38 Correct 608 ms 71544 KB Output is correct
39 Correct 731 ms 72660 KB Output is correct
40 Correct 647 ms 73052 KB Output is correct
41 Correct 1095 ms 75260 KB Output is correct
42 Correct 383 ms 58784 KB Output is correct
43 Correct 153 ms 41208 KB Output is correct
44 Correct 661 ms 68988 KB Output is correct
45 Correct 949 ms 74636 KB Output is correct
46 Correct 1024 ms 71160 KB Output is correct
47 Correct 977 ms 70904 KB Output is correct
48 Correct 663 ms 71524 KB Output is correct
49 Correct 641 ms 71240 KB Output is correct
50 Correct 759 ms 72696 KB Output is correct
51 Correct 767 ms 72572 KB Output is correct
52 Correct 21 ms 24952 KB Output is correct
53 Correct 1102 ms 74748 KB Output is correct
54 Correct 664 ms 68344 KB Output is correct
55 Correct 954 ms 73460 KB Output is correct
56 Correct 1048 ms 74080 KB Output is correct
57 Correct 3429 ms 161108 KB Output is correct
58 Correct 3257 ms 160888 KB Output is correct
59 Correct 3956 ms 168784 KB Output is correct
60 Correct 3931 ms 168708 KB Output is correct
61 Correct 6844 ms 180212 KB Output is correct
62 Correct 3875 ms 147436 KB Output is correct
63 Correct 5355 ms 171960 KB Output is correct
64 Correct 6266 ms 178752 KB Output is correct
65 Correct 660 ms 63972 KB Output is correct
66 Correct 645 ms 76920 KB Output is correct
67 Correct 760 ms 76536 KB Output is correct
68 Correct 773 ms 76540 KB Output is correct
69 Correct 1125 ms 77572 KB Output is correct
70 Correct 20 ms 24952 KB Output is correct
71 Correct 1134 ms 80632 KB Output is correct
72 Correct 683 ms 73976 KB Output is correct
73 Correct 953 ms 79080 KB Output is correct
74 Correct 1014 ms 74104 KB Output is correct
75 Correct 3541 ms 215628 KB Output is correct
76 Correct 3320 ms 215736 KB Output is correct
77 Correct 4058 ms 227244 KB Output is correct
78 Correct 4070 ms 226888 KB Output is correct
79 Correct 7065 ms 232948 KB Output is correct
80 Correct 3906 ms 198240 KB Output is correct
81 Correct 5509 ms 218768 KB Output is correct
82 Correct 6627 ms 218028 KB Output is correct
83 Correct 6574 ms 236196 KB Output is correct