Submission #294017

# Submission time Handle Problem Language Result Execution time Memory
294017 2020-09-08T14:27:42 Z arnold518 Two Dishes (JOI19_dishes) C++14
100 / 100
4336 ms 189388 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e6;

struct Point
{
	int x, y; ll w;
};
vector<Point> V;

int N, M;
ll ans;

ll A[MAXN+10], S[MAXN+10], P[MAXN+10], B[MAXN+10], T[MAXN+10], Q[MAXN+10];

ll dp[MAXN+10];

pll lazy[MAXN*4+10];

void busy(int node, int tl, int tr)
{
	if(tl!=tr)
	{
		lazy[node*2]={lazy[node].first+lazy[node*2].first, max(lazy[node*2].second+lazy[node].first, lazy[node].second)};
		lazy[node*2+1]={lazy[node].first+lazy[node*2+1].first, max(lazy[node*2+1].second+lazy[node].first, lazy[node].second)};
	}
	else
	{
		dp[tl]=max(dp[tl]+lazy[node].first, lazy[node].second);
	}
	lazy[node]={0, 0};
}

void update(int node, int tl, int tr, int l, int r, pll k)
{
	busy(node, tl, tr);
	if(r<tl || tr<l) return;
	if(l<=tl && tr<=r)
	{
		lazy[node]=k;
		busy(node, tl, tr);
		return;
	}
	int mid=tl+tr>>1;
	update(node*2, tl, mid, l, r, k);
	update(node*2+1, mid+1, tr, l, r, k);
}

ll query(int node, int tl, int tr, int p)
{
	busy(node, tl, tr);
	if(tl==tr) return dp[tl];
	int mid=tl+tr>>1;
	if(p<=mid) return query(node*2, tl, mid, p);
	else return query(node*2+1, mid+1, tr, p);
}

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 t=upper_bound(B, B+M+1, S[i]-A[i])-B-1;
		if(t<0) continue;
		if(t==M) { ans+=P[i]; continue; }
		int x=i, y=t;
		x--; y++;
		V.push_back({x, y, -P[i]}); ans+=P[i];
	}

	for(int i=1; i<=M; i++)
	{
		int t=upper_bound(A, A+N+1, T[i]-B[i])-A-1;
		if(t<0) continue;
		if(t==N) { ans+=Q[i]; continue; }
		int y=i, x=t;
		V.push_back({x, y, Q[i]});
	}

	sort(V.begin(), V.end(), [&](const Point &p, const Point &q)
	{
		if(p.x!=q.x) return p.x<q.x;
		if(p.y!=q.y) return p.y>q.y;
		return p.w>q.w;
	});

	for(int i=0; i<V.size(); i++)
	{
		ll t=0;
		if(V[i].y!=0) t=query(1, 0, M, V[i].y-1);
		update(1, 0, M, V[i].y, M, pll(V[i].w, t));
	}
	printf("%lld\n", query(1, 0, M, M)+ans);
}

Compilation message

dishes.cpp: In function 'void update(int, int, int, int, int, pll)':
dishes.cpp:49:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |  int mid=tl+tr>>1;
      |          ~~^~~
dishes.cpp: In function 'll query(int, int, int, int)':
dishes.cpp:58:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |  int mid=tl+tr>>1;
      |          ~~^~~
dishes.cpp: In function 'int main()':
dishes.cpp:95:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |  for(int i=0; i<V.size(); i++)
      |               ~^~~~~~~~~
dishes.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
dishes.cpp:66:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |  for(int i=1; i<=N; i++) scanf("%lld%lld%lld", &A[i], &S[i], &P[i]), A[i]+=A[i-1];
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:67:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |  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 477 ms 37876 KB Output is correct
2 Correct 470 ms 37712 KB Output is correct
3 Correct 230 ms 23160 KB Output is correct
4 Correct 388 ms 33360 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 427 ms 34868 KB Output is correct
7 Correct 115 ms 11896 KB Output is correct
8 Correct 113 ms 12024 KB Output is correct
9 Correct 252 ms 24440 KB Output is correct
10 Correct 437 ms 33280 KB Output is correct
11 Correct 177 ms 17660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 416 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 416 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 4 ms 692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 416 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 4 ms 692 KB Output is correct
24 Correct 357 ms 24604 KB Output is correct
25 Correct 345 ms 33628 KB Output is correct
26 Correct 378 ms 33628 KB Output is correct
27 Correct 337 ms 33444 KB Output is correct
28 Correct 353 ms 32228 KB Output is correct
29 Correct 203 ms 21112 KB Output is correct
30 Correct 648 ms 36432 KB Output is correct
31 Correct 159 ms 21732 KB Output is correct
32 Correct 118 ms 12524 KB Output is correct
33 Correct 495 ms 33140 KB Output is correct
34 Correct 659 ms 35024 KB Output is correct
35 Correct 604 ms 30032 KB Output is correct
36 Correct 526 ms 29904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 416 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 4 ms 692 KB Output is correct
24 Correct 357 ms 24604 KB Output is correct
25 Correct 345 ms 33628 KB Output is correct
26 Correct 378 ms 33628 KB Output is correct
27 Correct 337 ms 33444 KB Output is correct
28 Correct 353 ms 32228 KB Output is correct
29 Correct 203 ms 21112 KB Output is correct
30 Correct 648 ms 36432 KB Output is correct
31 Correct 159 ms 21732 KB Output is correct
32 Correct 118 ms 12524 KB Output is correct
33 Correct 495 ms 33140 KB Output is correct
34 Correct 659 ms 35024 KB Output is correct
35 Correct 604 ms 30032 KB Output is correct
36 Correct 526 ms 29904 KB Output is correct
37 Correct 377 ms 36572 KB Output is correct
38 Correct 374 ms 36476 KB Output is correct
39 Correct 485 ms 37196 KB Output is correct
40 Correct 488 ms 36944 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 652 ms 39504 KB Output is correct
43 Correct 455 ms 36060 KB Output is correct
44 Correct 574 ms 37712 KB Output is correct
45 Correct 569 ms 33108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 416 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 4 ms 692 KB Output is correct
24 Correct 357 ms 24604 KB Output is correct
25 Correct 345 ms 33628 KB Output is correct
26 Correct 378 ms 33628 KB Output is correct
27 Correct 337 ms 33444 KB Output is correct
28 Correct 353 ms 32228 KB Output is correct
29 Correct 203 ms 21112 KB Output is correct
30 Correct 648 ms 36432 KB Output is correct
31 Correct 159 ms 21732 KB Output is correct
32 Correct 118 ms 12524 KB Output is correct
33 Correct 495 ms 33140 KB Output is correct
34 Correct 659 ms 35024 KB Output is correct
35 Correct 604 ms 30032 KB Output is correct
36 Correct 526 ms 29904 KB Output is correct
37 Correct 377 ms 36572 KB Output is correct
38 Correct 374 ms 36476 KB Output is correct
39 Correct 485 ms 37196 KB Output is correct
40 Correct 488 ms 36944 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 652 ms 39504 KB Output is correct
43 Correct 455 ms 36060 KB Output is correct
44 Correct 574 ms 37712 KB Output is correct
45 Correct 569 ms 33108 KB Output is correct
46 Correct 1963 ms 173820 KB Output is correct
47 Correct 1966 ms 173736 KB Output is correct
48 Correct 2649 ms 175844 KB Output is correct
49 Correct 2655 ms 175784 KB Output is correct
50 Correct 4225 ms 188808 KB Output is correct
51 Correct 2707 ms 168224 KB Output is correct
52 Correct 3066 ms 172132 KB Output is correct
53 Correct 3695 ms 156372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 37876 KB Output is correct
2 Correct 470 ms 37712 KB Output is correct
3 Correct 230 ms 23160 KB Output is correct
4 Correct 388 ms 33360 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 427 ms 34868 KB Output is correct
7 Correct 115 ms 11896 KB Output is correct
8 Correct 113 ms 12024 KB Output is correct
9 Correct 252 ms 24440 KB Output is correct
10 Correct 437 ms 33280 KB Output is correct
11 Correct 177 ms 17660 KB Output is correct
12 Correct 1 ms 376 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 416 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 3 ms 768 KB Output is correct
30 Correct 5 ms 768 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 4 ms 640 KB Output is correct
34 Correct 4 ms 692 KB Output is correct
35 Correct 357 ms 24604 KB Output is correct
36 Correct 345 ms 33628 KB Output is correct
37 Correct 378 ms 33628 KB Output is correct
38 Correct 337 ms 33444 KB Output is correct
39 Correct 353 ms 32228 KB Output is correct
40 Correct 203 ms 21112 KB Output is correct
41 Correct 648 ms 36432 KB Output is correct
42 Correct 159 ms 21732 KB Output is correct
43 Correct 118 ms 12524 KB Output is correct
44 Correct 495 ms 33140 KB Output is correct
45 Correct 659 ms 35024 KB Output is correct
46 Correct 604 ms 30032 KB Output is correct
47 Correct 526 ms 29904 KB Output is correct
48 Correct 377 ms 36572 KB Output is correct
49 Correct 374 ms 36476 KB Output is correct
50 Correct 485 ms 37196 KB Output is correct
51 Correct 488 ms 36944 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 652 ms 39504 KB Output is correct
54 Correct 455 ms 36060 KB Output is correct
55 Correct 574 ms 37712 KB Output is correct
56 Correct 569 ms 33108 KB Output is correct
57 Correct 383 ms 37084 KB Output is correct
58 Correct 398 ms 36956 KB Output is correct
59 Correct 492 ms 37968 KB Output is correct
60 Correct 489 ms 37968 KB Output is correct
61 Correct 665 ms 36816 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 701 ms 39632 KB Output is correct
64 Correct 485 ms 35932 KB Output is correct
65 Correct 723 ms 37968 KB Output is correct
66 Correct 603 ms 33108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 37876 KB Output is correct
2 Correct 470 ms 37712 KB Output is correct
3 Correct 230 ms 23160 KB Output is correct
4 Correct 388 ms 33360 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 427 ms 34868 KB Output is correct
7 Correct 115 ms 11896 KB Output is correct
8 Correct 113 ms 12024 KB Output is correct
9 Correct 252 ms 24440 KB Output is correct
10 Correct 437 ms 33280 KB Output is correct
11 Correct 177 ms 17660 KB Output is correct
12 Correct 1 ms 376 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 416 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 3 ms 768 KB Output is correct
30 Correct 5 ms 768 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 4 ms 640 KB Output is correct
34 Correct 4 ms 692 KB Output is correct
35 Correct 357 ms 24604 KB Output is correct
36 Correct 345 ms 33628 KB Output is correct
37 Correct 378 ms 33628 KB Output is correct
38 Correct 337 ms 33444 KB Output is correct
39 Correct 353 ms 32228 KB Output is correct
40 Correct 203 ms 21112 KB Output is correct
41 Correct 648 ms 36432 KB Output is correct
42 Correct 159 ms 21732 KB Output is correct
43 Correct 118 ms 12524 KB Output is correct
44 Correct 495 ms 33140 KB Output is correct
45 Correct 659 ms 35024 KB Output is correct
46 Correct 604 ms 30032 KB Output is correct
47 Correct 526 ms 29904 KB Output is correct
48 Correct 377 ms 36572 KB Output is correct
49 Correct 374 ms 36476 KB Output is correct
50 Correct 485 ms 37196 KB Output is correct
51 Correct 488 ms 36944 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 652 ms 39504 KB Output is correct
54 Correct 455 ms 36060 KB Output is correct
55 Correct 574 ms 37712 KB Output is correct
56 Correct 569 ms 33108 KB Output is correct
57 Correct 1963 ms 173820 KB Output is correct
58 Correct 1966 ms 173736 KB Output is correct
59 Correct 2649 ms 175844 KB Output is correct
60 Correct 2655 ms 175784 KB Output is correct
61 Correct 4225 ms 188808 KB Output is correct
62 Correct 2707 ms 168224 KB Output is correct
63 Correct 3066 ms 172132 KB Output is correct
64 Correct 3695 ms 156372 KB Output is correct
65 Correct 383 ms 37084 KB Output is correct
66 Correct 398 ms 36956 KB Output is correct
67 Correct 492 ms 37968 KB Output is correct
68 Correct 489 ms 37968 KB Output is correct
69 Correct 665 ms 36816 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 701 ms 39632 KB Output is correct
72 Correct 485 ms 35932 KB Output is correct
73 Correct 723 ms 37968 KB Output is correct
74 Correct 603 ms 33108 KB Output is correct
75 Correct 2090 ms 175472 KB Output is correct
76 Correct 2096 ms 175520 KB Output is correct
77 Correct 2738 ms 178236 KB Output is correct
78 Correct 2741 ms 178208 KB Output is correct
79 Correct 4336 ms 189388 KB Output is correct
80 Correct 2648 ms 168168 KB Output is correct
81 Correct 3061 ms 174480 KB Output is correct
82 Correct 3956 ms 156852 KB Output is correct
83 Correct 3944 ms 175464 KB Output is correct