답안 #203411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203411 2020-02-20T14:28:22 Z dennisstar Two Dishes (JOI19_dishes) C++17
100 / 100
5716 ms 144692 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<int, ll> pil;
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<pair<int, pil> > qu;

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.eb(i, pil(I, P[i]));
	}qu.eb(N+1, pil(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.eb(J+1, pil(i-1, -Q[i])), im+=Q[i];
	}
	sort(all(qu));
	for (int i=1, j=0; i<=N+1; i++) {
		for (int k=j; k<qu.size()&&qu[k].fi==i; k++) {
			auto l=qu[k].se; upd1(1, 0, M, 0, l.fi, l.se);
		}
		for (; j<qu.size()&&qu[j].fi==i; j++) {
			auto l=qu[j].se; upd2(1, 0, M, l.fi+1, M, get(1, 0, M, l.fi));
		}
	}
	printf("%lld\n", get(1, 0, M, M)+im);
	return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int k=j; k<qu.size()&&qu[k].fi==i; k++) {
                 ~^~~~~~~~~~
dishes.cpp:65:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (; j<qu.size()&&qu[j].fi==i; j++) {
          ~^~~~~~~~~~
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];
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 627 ms 37188 KB Output is correct
2 Correct 674 ms 50632 KB Output is correct
3 Correct 614 ms 50504 KB Output is correct
4 Correct 504 ms 39256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 638 ms 49864 KB Output is correct
7 Correct 292 ms 34136 KB Output is correct
8 Correct 134 ms 17376 KB Output is correct
9 Correct 628 ms 51656 KB Output is correct
10 Correct 638 ms 46024 KB Output is correct
11 Correct 563 ms 45896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 9 ms 888 KB Output is correct
18 Correct 9 ms 888 KB Output is correct
19 Correct 10 ms 888 KB Output is correct
20 Correct 8 ms 760 KB Output is correct
21 Correct 11 ms 1016 KB Output is correct
22 Correct 10 ms 888 KB Output is correct
23 Correct 9 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 9 ms 888 KB Output is correct
18 Correct 9 ms 888 KB Output is correct
19 Correct 10 ms 888 KB Output is correct
20 Correct 8 ms 760 KB Output is correct
21 Correct 11 ms 1016 KB Output is correct
22 Correct 10 ms 888 KB Output is correct
23 Correct 9 ms 888 KB Output is correct
24 Correct 995 ms 45512 KB Output is correct
25 Correct 530 ms 45384 KB Output is correct
26 Correct 569 ms 45440 KB Output is correct
27 Correct 546 ms 45512 KB Output is correct
28 Correct 680 ms 46920 KB Output is correct
29 Correct 587 ms 48716 KB Output is correct
30 Correct 847 ms 47688 KB Output is correct
31 Correct 315 ms 35668 KB Output is correct
32 Correct 138 ms 16612 KB Output is correct
33 Correct 549 ms 42836 KB Output is correct
34 Correct 823 ms 47400 KB Output is correct
35 Correct 828 ms 44108 KB Output is correct
36 Correct 793 ms 43848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 9 ms 888 KB Output is correct
18 Correct 9 ms 888 KB Output is correct
19 Correct 10 ms 888 KB Output is correct
20 Correct 8 ms 760 KB Output is correct
21 Correct 11 ms 1016 KB Output is correct
22 Correct 10 ms 888 KB Output is correct
23 Correct 9 ms 888 KB Output is correct
24 Correct 995 ms 45512 KB Output is correct
25 Correct 530 ms 45384 KB Output is correct
26 Correct 569 ms 45440 KB Output is correct
27 Correct 546 ms 45512 KB Output is correct
28 Correct 680 ms 46920 KB Output is correct
29 Correct 587 ms 48716 KB Output is correct
30 Correct 847 ms 47688 KB Output is correct
31 Correct 315 ms 35668 KB Output is correct
32 Correct 138 ms 16612 KB Output is correct
33 Correct 549 ms 42836 KB Output is correct
34 Correct 823 ms 47400 KB Output is correct
35 Correct 828 ms 44108 KB Output is correct
36 Correct 793 ms 43848 KB Output is correct
37 Correct 561 ms 48840 KB Output is correct
38 Correct 599 ms 48968 KB Output is correct
39 Correct 706 ms 48768 KB Output is correct
40 Correct 705 ms 49096 KB Output is correct
41 Correct 5 ms 376 KB Output is correct
42 Correct 944 ms 51828 KB Output is correct
43 Correct 604 ms 47064 KB Output is correct
44 Correct 833 ms 51656 KB Output is correct
45 Correct 860 ms 46280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 9 ms 888 KB Output is correct
18 Correct 9 ms 888 KB Output is correct
19 Correct 10 ms 888 KB Output is correct
20 Correct 8 ms 760 KB Output is correct
21 Correct 11 ms 1016 KB Output is correct
22 Correct 10 ms 888 KB Output is correct
23 Correct 9 ms 888 KB Output is correct
24 Correct 995 ms 45512 KB Output is correct
25 Correct 530 ms 45384 KB Output is correct
26 Correct 569 ms 45440 KB Output is correct
27 Correct 546 ms 45512 KB Output is correct
28 Correct 680 ms 46920 KB Output is correct
29 Correct 587 ms 48716 KB Output is correct
30 Correct 847 ms 47688 KB Output is correct
31 Correct 315 ms 35668 KB Output is correct
32 Correct 138 ms 16612 KB Output is correct
33 Correct 549 ms 42836 KB Output is correct
34 Correct 823 ms 47400 KB Output is correct
35 Correct 828 ms 44108 KB Output is correct
36 Correct 793 ms 43848 KB Output is correct
37 Correct 561 ms 48840 KB Output is correct
38 Correct 599 ms 48968 KB Output is correct
39 Correct 706 ms 48768 KB Output is correct
40 Correct 705 ms 49096 KB Output is correct
41 Correct 5 ms 376 KB Output is correct
42 Correct 944 ms 51828 KB Output is correct
43 Correct 604 ms 47064 KB Output is correct
44 Correct 833 ms 51656 KB Output is correct
45 Correct 860 ms 46280 KB Output is correct
46 Correct 2926 ms 133240 KB Output is correct
47 Correct 3099 ms 133404 KB Output is correct
48 Correct 3579 ms 144380 KB Output is correct
49 Correct 3623 ms 144692 KB Output is correct
50 Correct 5572 ms 144508 KB Output is correct
51 Correct 3276 ms 118956 KB Output is correct
52 Correct 4506 ms 139292 KB Output is correct
53 Correct 5107 ms 143008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 627 ms 37188 KB Output is correct
2 Correct 674 ms 50632 KB Output is correct
3 Correct 614 ms 50504 KB Output is correct
4 Correct 504 ms 39256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 638 ms 49864 KB Output is correct
7 Correct 292 ms 34136 KB Output is correct
8 Correct 134 ms 17376 KB Output is correct
9 Correct 628 ms 51656 KB Output is correct
10 Correct 638 ms 46024 KB Output is correct
11 Correct 563 ms 45896 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 380 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 9 ms 888 KB Output is correct
29 Correct 9 ms 888 KB Output is correct
30 Correct 10 ms 888 KB Output is correct
31 Correct 8 ms 760 KB Output is correct
32 Correct 11 ms 1016 KB Output is correct
33 Correct 10 ms 888 KB Output is correct
34 Correct 9 ms 888 KB Output is correct
35 Correct 995 ms 45512 KB Output is correct
36 Correct 530 ms 45384 KB Output is correct
37 Correct 569 ms 45440 KB Output is correct
38 Correct 546 ms 45512 KB Output is correct
39 Correct 680 ms 46920 KB Output is correct
40 Correct 587 ms 48716 KB Output is correct
41 Correct 847 ms 47688 KB Output is correct
42 Correct 315 ms 35668 KB Output is correct
43 Correct 138 ms 16612 KB Output is correct
44 Correct 549 ms 42836 KB Output is correct
45 Correct 823 ms 47400 KB Output is correct
46 Correct 828 ms 44108 KB Output is correct
47 Correct 793 ms 43848 KB Output is correct
48 Correct 561 ms 48840 KB Output is correct
49 Correct 599 ms 48968 KB Output is correct
50 Correct 706 ms 48768 KB Output is correct
51 Correct 705 ms 49096 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Correct 944 ms 51828 KB Output is correct
54 Correct 604 ms 47064 KB Output is correct
55 Correct 833 ms 51656 KB Output is correct
56 Correct 860 ms 46280 KB Output is correct
57 Correct 569 ms 45312 KB Output is correct
58 Correct 588 ms 44744 KB Output is correct
59 Correct 674 ms 47276 KB Output is correct
60 Correct 669 ms 47176 KB Output is correct
61 Correct 894 ms 47172 KB Output is correct
62 Correct 5 ms 376 KB Output is correct
63 Correct 875 ms 47232 KB Output is correct
64 Correct 584 ms 42328 KB Output is correct
65 Correct 816 ms 46668 KB Output is correct
66 Correct 840 ms 46924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 627 ms 37188 KB Output is correct
2 Correct 674 ms 50632 KB Output is correct
3 Correct 614 ms 50504 KB Output is correct
4 Correct 504 ms 39256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 638 ms 49864 KB Output is correct
7 Correct 292 ms 34136 KB Output is correct
8 Correct 134 ms 17376 KB Output is correct
9 Correct 628 ms 51656 KB Output is correct
10 Correct 638 ms 46024 KB Output is correct
11 Correct 563 ms 45896 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 380 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 9 ms 888 KB Output is correct
29 Correct 9 ms 888 KB Output is correct
30 Correct 10 ms 888 KB Output is correct
31 Correct 8 ms 760 KB Output is correct
32 Correct 11 ms 1016 KB Output is correct
33 Correct 10 ms 888 KB Output is correct
34 Correct 9 ms 888 KB Output is correct
35 Correct 995 ms 45512 KB Output is correct
36 Correct 530 ms 45384 KB Output is correct
37 Correct 569 ms 45440 KB Output is correct
38 Correct 546 ms 45512 KB Output is correct
39 Correct 680 ms 46920 KB Output is correct
40 Correct 587 ms 48716 KB Output is correct
41 Correct 847 ms 47688 KB Output is correct
42 Correct 315 ms 35668 KB Output is correct
43 Correct 138 ms 16612 KB Output is correct
44 Correct 549 ms 42836 KB Output is correct
45 Correct 823 ms 47400 KB Output is correct
46 Correct 828 ms 44108 KB Output is correct
47 Correct 793 ms 43848 KB Output is correct
48 Correct 561 ms 48840 KB Output is correct
49 Correct 599 ms 48968 KB Output is correct
50 Correct 706 ms 48768 KB Output is correct
51 Correct 705 ms 49096 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Correct 944 ms 51828 KB Output is correct
54 Correct 604 ms 47064 KB Output is correct
55 Correct 833 ms 51656 KB Output is correct
56 Correct 860 ms 46280 KB Output is correct
57 Correct 2926 ms 133240 KB Output is correct
58 Correct 3099 ms 133404 KB Output is correct
59 Correct 3579 ms 144380 KB Output is correct
60 Correct 3623 ms 144692 KB Output is correct
61 Correct 5572 ms 144508 KB Output is correct
62 Correct 3276 ms 118956 KB Output is correct
63 Correct 4506 ms 139292 KB Output is correct
64 Correct 5107 ms 143008 KB Output is correct
65 Correct 569 ms 45312 KB Output is correct
66 Correct 588 ms 44744 KB Output is correct
67 Correct 674 ms 47276 KB Output is correct
68 Correct 669 ms 47176 KB Output is correct
69 Correct 894 ms 47172 KB Output is correct
70 Correct 5 ms 376 KB Output is correct
71 Correct 875 ms 47232 KB Output is correct
72 Correct 584 ms 42328 KB Output is correct
73 Correct 816 ms 46668 KB Output is correct
74 Correct 840 ms 46924 KB Output is correct
75 Correct 2973 ms 135032 KB Output is correct
76 Correct 3083 ms 133848 KB Output is correct
77 Correct 3648 ms 144436 KB Output is correct
78 Correct 3746 ms 144504 KB Output is correct
79 Correct 5716 ms 144224 KB Output is correct
80 Correct 3351 ms 118828 KB Output is correct
81 Correct 4656 ms 139440 KB Output is correct
82 Correct 5254 ms 143356 KB Output is correct
83 Correct 5238 ms 142096 KB Output is correct