Submission #157673

# Submission time Handle Problem Language Result Execution time Memory
157673 2019-10-12T17:10:29 Z HungAnhGoldIBO2020 Two Dishes (JOI19_dishes) C++14
100 / 100
6559 ms 189996 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 3;
const int inf = 1e18 + 2;
int it[N << 2], lazy[N << 2], sA[N], sB[N] ,s[N], t[N], p[N], q[N], ass[N << 2];
vector<pair<int, int> >  pts[N];
void init(int idx, int l, int r){
	it[idx] = -inf;
	ass[idx] = -inf;
	if(l == r){
		return;
	}
	int mid = (l + r) >> 1;
	init(idx << 1, l, mid);
	init(idx << 1 | 1, mid + 1, r);
}
void push(int idx, int l, int r){
	if(l == r){
		ass[idx] = -inf;
		lazy[idx] = 0;
		return;
	}
	ass[idx << 1] = max(ass[idx << 1] + lazy[idx], ass[idx]);
	ass[idx << 1 | 1] = max(ass[idx << 1 | 1] + lazy[idx], ass[idx]);
	it[idx << 1] = max(it[idx << 1] + lazy[idx], ass[idx]);
	it[idx << 1 | 1] = max(it[idx << 1 | 1] + lazy[idx], ass[idx]);
	lazy[idx << 1] += lazy[idx];
	lazy[idx << 1 | 1] += lazy[idx];
	lazy[idx] = 0;
	ass[idx] = -inf;
}
void add(int idx, int l, int r, int lef, int rig, int val){
	if(l > rig || r < lef){
		return;
	}
	push(idx, l, r);
	if(l >= lef && r <= rig){
		it[idx] += val;
		lazy[idx] += val;
		ass[idx] += val;
		return;
	}
	//cout << idx << ' ' << l << ' ' << r << ' ' << lef << ' ' << rig << ' ' << val <<endl;
	int mid = (l + r) >> 1;
	add(idx << 1, l, mid, lef, rig, val);
	add(idx << 1 | 1, mid + 1, r, lef, rig, val);
	it[idx] = max(ass[idx], max(it[idx << 1], it[idx << 1 | 1]));
}
void upd(int idx, int l, int r, int lef, int rig, int val){
	if(l > rig || r < lef){
		return;
	}
	push(idx, l, r);
	if(l >= lef && r <= rig){
		ass[idx] = val;
		it[idx] = max(it[idx], val);
		return;
	}
	int mid = (l + r) >> 1;
	upd(idx << 1, l, mid, lef, rig, val);
	upd(idx << 1 | 1, mid + 1, r, lef, rig, val);
	it[idx] = max(ass[idx], max(it[idx << 1], it[idx << 1 | 1]));
}
int getmax(int idx, int l, int r, int lef, int rig){
	if(l > rig || r < lef){
		return -inf;
	}
	push(idx, l, r);
	if(l >= lef && r <= rig){
		return it[idx];
	}
	int mid = (l + r) >> 1;
	return max(getmax(idx << 1, l, mid, lef, rig), getmax(idx << 1 | 1, mid + 1, r, lef, rig));
}
signed main(){
	ios :: sync_with_stdio(0);
	cin. tie(0);
	int n, m, i, j, k, l, sum_val = 0;
	cin >> n >> m;
	for(i = 1; i <= n; i++){
		cin >> j >> s[i] >> p[i];
		sA[i] = sA[i - 1] + j;
	}
	for(i = 1; i <= m; i++){
		cin >> j >> t[i] >> q[i];
		sB[i] = sB[i - 1] + j;
		sum_val += q[i];
	}
	for(i = 1; i <= n; i++){
		j = upper_bound(sB, sB + 1 + m, s[i] - sA[i]) - sB - 1;
		if(j >= 0){
			pts[i].push_back({j, p[i]});
		}
	}		//true
	for(i = 1; i <= m; i++){
		j = upper_bound(sA, sA + 1 + n, t[i] - sB[i]) - sA - 1;
		if(j < n){
			pts[j + 1].push_back({i - 1, -q[i]}); 
		}
	}	//true, why? consider the point moving which don't really affect the answer.
	init(1, 0, m);
	upd(1, 0, m, 0, 0, 0);
	pts[0].push_back({0, 0});
	for(i = 0; i <= n; i++){
		for(j = 0; j < pts[i].size() ; j++){
			add(1, 0, m, 0, pts[i][j].first, pts[i][j].second);
		}
		for(j = 0; j < pts[i].size() ; j++){
			k = getmax(1, 0, m, 0, pts[i][j].first);
			upd(1, 0, m, pts[i][j].first, m, k);
		}
	}
	cout << getmax(1, 0, m, 0, m) + sum_val;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:106:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j = 0; j < pts[i].size() ; j++){
              ~~^~~~~~~~~~~~~~~
dishes.cpp:109:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j = 0; j < pts[i].size() ; j++){
              ~~^~~~~~~~~~~~~~~
dishes.cpp:79:21: warning: unused variable 'l' [-Wunused-variable]
  int n, m, i, j, k, l, sum_val = 0;
                     ^
# Verdict Execution time Memory Grader output
1 Correct 710 ms 56252 KB Output is correct
2 Correct 680 ms 55168 KB Output is correct
3 Correct 343 ms 47956 KB Output is correct
4 Correct 634 ms 52812 KB Output is correct
5 Correct 31 ms 23928 KB Output is correct
6 Correct 653 ms 53940 KB Output is correct
7 Correct 159 ms 37620 KB Output is correct
8 Correct 166 ms 34872 KB Output is correct
9 Correct 351 ms 47840 KB Output is correct
10 Correct 646 ms 55104 KB Output is correct
11 Correct 263 ms 47848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 23 ms 23932 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23840 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 23 ms 23928 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 24 ms 23928 KB Output is correct
14 Correct 24 ms 23844 KB Output is correct
15 Correct 24 ms 23928 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 23 ms 23932 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23840 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 23 ms 23928 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 24 ms 23928 KB Output is correct
14 Correct 24 ms 23844 KB Output is correct
15 Correct 24 ms 23928 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 27 ms 24312 KB Output is correct
18 Correct 28 ms 24324 KB Output is correct
19 Correct 29 ms 24312 KB Output is correct
20 Correct 28 ms 24312 KB Output is correct
21 Correct 29 ms 24312 KB Output is correct
22 Correct 28 ms 24312 KB Output is correct
23 Correct 29 ms 24184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 23 ms 23932 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23840 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 23 ms 23928 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 24 ms 23928 KB Output is correct
14 Correct 24 ms 23844 KB Output is correct
15 Correct 24 ms 23928 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 27 ms 24312 KB Output is correct
18 Correct 28 ms 24324 KB Output is correct
19 Correct 29 ms 24312 KB Output is correct
20 Correct 28 ms 24312 KB Output is correct
21 Correct 29 ms 24312 KB Output is correct
22 Correct 28 ms 24312 KB Output is correct
23 Correct 29 ms 24184 KB Output is correct
24 Correct 497 ms 56680 KB Output is correct
25 Correct 493 ms 58332 KB Output is correct
26 Correct 577 ms 59752 KB Output is correct
27 Correct 528 ms 59712 KB Output is correct
28 Correct 519 ms 59476 KB Output is correct
29 Correct 316 ms 53972 KB Output is correct
30 Correct 1025 ms 63516 KB Output is correct
31 Correct 255 ms 47828 KB Output is correct
32 Correct 141 ms 40056 KB Output is correct
33 Correct 733 ms 58764 KB Output is correct
34 Correct 818 ms 62012 KB Output is correct
35 Correct 935 ms 61648 KB Output is correct
36 Correct 902 ms 61392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 23 ms 23932 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23840 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 23 ms 23928 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 24 ms 23928 KB Output is correct
14 Correct 24 ms 23844 KB Output is correct
15 Correct 24 ms 23928 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 27 ms 24312 KB Output is correct
18 Correct 28 ms 24324 KB Output is correct
19 Correct 29 ms 24312 KB Output is correct
20 Correct 28 ms 24312 KB Output is correct
21 Correct 29 ms 24312 KB Output is correct
22 Correct 28 ms 24312 KB Output is correct
23 Correct 29 ms 24184 KB Output is correct
24 Correct 497 ms 56680 KB Output is correct
25 Correct 493 ms 58332 KB Output is correct
26 Correct 577 ms 59752 KB Output is correct
27 Correct 528 ms 59712 KB Output is correct
28 Correct 519 ms 59476 KB Output is correct
29 Correct 316 ms 53972 KB Output is correct
30 Correct 1025 ms 63516 KB Output is correct
31 Correct 255 ms 47828 KB Output is correct
32 Correct 141 ms 40056 KB Output is correct
33 Correct 733 ms 58764 KB Output is correct
34 Correct 818 ms 62012 KB Output is correct
35 Correct 935 ms 61648 KB Output is correct
36 Correct 902 ms 61392 KB Output is correct
37 Correct 604 ms 58952 KB Output is correct
38 Correct 541 ms 58864 KB Output is correct
39 Correct 715 ms 61304 KB Output is correct
40 Correct 731 ms 61440 KB Output is correct
41 Correct 24 ms 23928 KB Output is correct
42 Correct 1041 ms 62692 KB Output is correct
43 Correct 738 ms 58256 KB Output is correct
44 Correct 876 ms 61424 KB Output is correct
45 Correct 981 ms 64340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 23 ms 23932 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23840 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 23 ms 23928 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 24 ms 23928 KB Output is correct
14 Correct 24 ms 23844 KB Output is correct
15 Correct 24 ms 23928 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 27 ms 24312 KB Output is correct
18 Correct 28 ms 24324 KB Output is correct
19 Correct 29 ms 24312 KB Output is correct
20 Correct 28 ms 24312 KB Output is correct
21 Correct 29 ms 24312 KB Output is correct
22 Correct 28 ms 24312 KB Output is correct
23 Correct 29 ms 24184 KB Output is correct
24 Correct 497 ms 56680 KB Output is correct
25 Correct 493 ms 58332 KB Output is correct
26 Correct 577 ms 59752 KB Output is correct
27 Correct 528 ms 59712 KB Output is correct
28 Correct 519 ms 59476 KB Output is correct
29 Correct 316 ms 53972 KB Output is correct
30 Correct 1025 ms 63516 KB Output is correct
31 Correct 255 ms 47828 KB Output is correct
32 Correct 141 ms 40056 KB Output is correct
33 Correct 733 ms 58764 KB Output is correct
34 Correct 818 ms 62012 KB Output is correct
35 Correct 935 ms 61648 KB Output is correct
36 Correct 902 ms 61392 KB Output is correct
37 Correct 604 ms 58952 KB Output is correct
38 Correct 541 ms 58864 KB Output is correct
39 Correct 715 ms 61304 KB Output is correct
40 Correct 731 ms 61440 KB Output is correct
41 Correct 24 ms 23928 KB Output is correct
42 Correct 1041 ms 62692 KB Output is correct
43 Correct 738 ms 58256 KB Output is correct
44 Correct 876 ms 61424 KB Output is correct
45 Correct 981 ms 64340 KB Output is correct
46 Correct 3211 ms 168140 KB Output is correct
47 Correct 2839 ms 172312 KB Output is correct
48 Correct 3793 ms 173980 KB Output is correct
49 Correct 3829 ms 174080 KB Output is correct
50 Correct 6559 ms 187140 KB Output is correct
51 Correct 4227 ms 161236 KB Output is correct
52 Correct 4754 ms 176376 KB Output is correct
53 Correct 5888 ms 183196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 710 ms 56252 KB Output is correct
2 Correct 680 ms 55168 KB Output is correct
3 Correct 343 ms 47956 KB Output is correct
4 Correct 634 ms 52812 KB Output is correct
5 Correct 31 ms 23928 KB Output is correct
6 Correct 653 ms 53940 KB Output is correct
7 Correct 159 ms 37620 KB Output is correct
8 Correct 166 ms 34872 KB Output is correct
9 Correct 351 ms 47840 KB Output is correct
10 Correct 646 ms 55104 KB Output is correct
11 Correct 263 ms 47848 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 23 ms 23932 KB Output is correct
14 Correct 24 ms 23928 KB Output is correct
15 Correct 23 ms 23840 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 24 ms 23928 KB Output is correct
18 Correct 23 ms 23928 KB Output is correct
19 Correct 23 ms 23928 KB Output is correct
20 Correct 24 ms 23928 KB Output is correct
21 Correct 23 ms 23928 KB Output is correct
22 Correct 23 ms 23928 KB Output is correct
23 Correct 23 ms 23928 KB Output is correct
24 Correct 24 ms 23928 KB Output is correct
25 Correct 24 ms 23844 KB Output is correct
26 Correct 24 ms 23928 KB Output is correct
27 Correct 24 ms 23928 KB Output is correct
28 Correct 27 ms 24312 KB Output is correct
29 Correct 28 ms 24324 KB Output is correct
30 Correct 29 ms 24312 KB Output is correct
31 Correct 28 ms 24312 KB Output is correct
32 Correct 29 ms 24312 KB Output is correct
33 Correct 28 ms 24312 KB Output is correct
34 Correct 29 ms 24184 KB Output is correct
35 Correct 497 ms 56680 KB Output is correct
36 Correct 493 ms 58332 KB Output is correct
37 Correct 577 ms 59752 KB Output is correct
38 Correct 528 ms 59712 KB Output is correct
39 Correct 519 ms 59476 KB Output is correct
40 Correct 316 ms 53972 KB Output is correct
41 Correct 1025 ms 63516 KB Output is correct
42 Correct 255 ms 47828 KB Output is correct
43 Correct 141 ms 40056 KB Output is correct
44 Correct 733 ms 58764 KB Output is correct
45 Correct 818 ms 62012 KB Output is correct
46 Correct 935 ms 61648 KB Output is correct
47 Correct 902 ms 61392 KB Output is correct
48 Correct 604 ms 58952 KB Output is correct
49 Correct 541 ms 58864 KB Output is correct
50 Correct 715 ms 61304 KB Output is correct
51 Correct 731 ms 61440 KB Output is correct
52 Correct 24 ms 23928 KB Output is correct
53 Correct 1041 ms 62692 KB Output is correct
54 Correct 738 ms 58256 KB Output is correct
55 Correct 876 ms 61424 KB Output is correct
56 Correct 981 ms 64340 KB Output is correct
57 Correct 611 ms 59012 KB Output is correct
58 Correct 545 ms 58980 KB Output is correct
59 Correct 724 ms 61176 KB Output is correct
60 Correct 729 ms 61052 KB Output is correct
61 Correct 1018 ms 63864 KB Output is correct
62 Correct 24 ms 23932 KB Output is correct
63 Correct 1033 ms 62868 KB Output is correct
64 Correct 728 ms 58212 KB Output is correct
65 Correct 820 ms 60792 KB Output is correct
66 Correct 942 ms 63912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 710 ms 56252 KB Output is correct
2 Correct 680 ms 55168 KB Output is correct
3 Correct 343 ms 47956 KB Output is correct
4 Correct 634 ms 52812 KB Output is correct
5 Correct 31 ms 23928 KB Output is correct
6 Correct 653 ms 53940 KB Output is correct
7 Correct 159 ms 37620 KB Output is correct
8 Correct 166 ms 34872 KB Output is correct
9 Correct 351 ms 47840 KB Output is correct
10 Correct 646 ms 55104 KB Output is correct
11 Correct 263 ms 47848 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 23 ms 23932 KB Output is correct
14 Correct 24 ms 23928 KB Output is correct
15 Correct 23 ms 23840 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 24 ms 23928 KB Output is correct
18 Correct 23 ms 23928 KB Output is correct
19 Correct 23 ms 23928 KB Output is correct
20 Correct 24 ms 23928 KB Output is correct
21 Correct 23 ms 23928 KB Output is correct
22 Correct 23 ms 23928 KB Output is correct
23 Correct 23 ms 23928 KB Output is correct
24 Correct 24 ms 23928 KB Output is correct
25 Correct 24 ms 23844 KB Output is correct
26 Correct 24 ms 23928 KB Output is correct
27 Correct 24 ms 23928 KB Output is correct
28 Correct 27 ms 24312 KB Output is correct
29 Correct 28 ms 24324 KB Output is correct
30 Correct 29 ms 24312 KB Output is correct
31 Correct 28 ms 24312 KB Output is correct
32 Correct 29 ms 24312 KB Output is correct
33 Correct 28 ms 24312 KB Output is correct
34 Correct 29 ms 24184 KB Output is correct
35 Correct 497 ms 56680 KB Output is correct
36 Correct 493 ms 58332 KB Output is correct
37 Correct 577 ms 59752 KB Output is correct
38 Correct 528 ms 59712 KB Output is correct
39 Correct 519 ms 59476 KB Output is correct
40 Correct 316 ms 53972 KB Output is correct
41 Correct 1025 ms 63516 KB Output is correct
42 Correct 255 ms 47828 KB Output is correct
43 Correct 141 ms 40056 KB Output is correct
44 Correct 733 ms 58764 KB Output is correct
45 Correct 818 ms 62012 KB Output is correct
46 Correct 935 ms 61648 KB Output is correct
47 Correct 902 ms 61392 KB Output is correct
48 Correct 604 ms 58952 KB Output is correct
49 Correct 541 ms 58864 KB Output is correct
50 Correct 715 ms 61304 KB Output is correct
51 Correct 731 ms 61440 KB Output is correct
52 Correct 24 ms 23928 KB Output is correct
53 Correct 1041 ms 62692 KB Output is correct
54 Correct 738 ms 58256 KB Output is correct
55 Correct 876 ms 61424 KB Output is correct
56 Correct 981 ms 64340 KB Output is correct
57 Correct 3211 ms 168140 KB Output is correct
58 Correct 2839 ms 172312 KB Output is correct
59 Correct 3793 ms 173980 KB Output is correct
60 Correct 3829 ms 174080 KB Output is correct
61 Correct 6559 ms 187140 KB Output is correct
62 Correct 4227 ms 161236 KB Output is correct
63 Correct 4754 ms 176376 KB Output is correct
64 Correct 5888 ms 183196 KB Output is correct
65 Correct 611 ms 59012 KB Output is correct
66 Correct 545 ms 58980 KB Output is correct
67 Correct 724 ms 61176 KB Output is correct
68 Correct 729 ms 61052 KB Output is correct
69 Correct 1018 ms 63864 KB Output is correct
70 Correct 24 ms 23932 KB Output is correct
71 Correct 1033 ms 62868 KB Output is correct
72 Correct 728 ms 58212 KB Output is correct
73 Correct 820 ms 60792 KB Output is correct
74 Correct 942 ms 63912 KB Output is correct
75 Correct 3257 ms 170256 KB Output is correct
76 Correct 2847 ms 174252 KB Output is correct
77 Correct 3831 ms 179680 KB Output is correct
78 Correct 3819 ms 179668 KB Output is correct
79 Correct 6442 ms 189100 KB Output is correct
80 Correct 4155 ms 163812 KB Output is correct
81 Correct 4701 ms 172724 KB Output is correct
82 Correct 6223 ms 189996 KB Output is correct
83 Correct 6085 ms 187328 KB Output is correct