Submission #123388

# Submission time Handle Problem Language Result Execution time Memory
123388 2019-07-01T10:33:35 Z gs14004 Two Dishes (JOI19_dishes) C++17
100 / 100
3660 ms 151276 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
const int MAXT = 2100000;
const int mod = 1e9 + 7;
using lint = long long;
using pi = pair<int, int>;

struct pnt{
	int x, y;
	lint c;
	bool operator<(const pnt &p)const{
		return pi(x, y) < pi(p.x, p.y);
	}
};

struct seg{
	lint lazy[MAXT], tree[MAXT];
	void lazydown(int p){
		lazy[2*p] += lazy[p];
		lazy[2*p+1] += lazy[p];
		tree[2*p] += lazy[p];
		tree[2*p+1] += lazy[p];
		lazy[p] = 0;
		tree[2*p] = max(tree[2*p], tree[p]);
		tree[2*p+1] = max(tree[2*p+1], tree[p]);
		tree[p] = 0;
	}
	void add(int s, int e, int ps, int pe, int p, lint v){
		if(e < ps || pe < s) return;
		if(s <= ps && pe <= e){
			lazy[p] += v;
			tree[p] += v;
			return;
		}
		int pm = (ps + pe) / 2;
		lazydown(p);
		add(s, e, ps, pm, 2*p, v);
		add(s, e, pm + 1, pe, 2*p + 1, v);
	}
	void upperize(int s, int e, int ps, int pe, int p, lint v){
		if(e < ps || pe < s) return;
		if(s <= ps && pe <= e){
			tree[p] = max(tree[p], v);
			return;
		}
		int pm = (ps + pe) / 2;
		lazydown(p);
		upperize(s, e, ps, pm, 2*p, v);
		upperize(s, e, pm+1, pe, 2*p+1, v);
	}
	lint query(int pos, int s, int e, int p){
		if(s == e) return tree[p];
		int m = (s + e) / 2;
		lazydown(p);
		if(pos <= m) return query(pos, s, m, 2*p);
		return query(pos, m+1, e, 2*p+1);
	}
}seg;

int n, m;
lint a[MAXN], s[MAXN], p[MAXN];
lint b[MAXN], t[MAXN], q[MAXN];
int da[MAXN], db[MAXN];
lint dp[MAXN];
vector<pnt> v, w;

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];
	}
	lint ret = 0;
	v.push_back({0, 0, 0});
	for(int i=1; i<=n; i++){
		da[i] = upper_bound(b, b + m + 1, s[i] - a[i]) - b;
		if(da[i] > m){
			ret += p[i];
			continue;
		}
		if(da[i] > 0){
			if(p[i] > 0) v.push_back({i, da[i], p[i]});
			else w.push_back({i, da[i], -p[i]}), ret += p[i];
		}
	}
	for(int i=1; i<=m; i++){
		db[i] = upper_bound(a, a + n + 1, t[i] - b[i]) - a;
		if(db[i] > n){
			ret += q[i];
			continue;
		}
		if(db[i] > 0){
			if(q[i] > 0) w.push_back({db[i], i, q[i]});
			else v.push_back({db[i], i, -q[i]}), ret += q[i];
		}
	}
	sort(v.begin(), v.end());
	sort(w.begin(), w.end());
	v.push_back({n + 1, m + 1, 0});
	int pw = 0;
	for(int i=1; i<v.size(); ){
		int e = i;
		while(e < v.size() && v[e].x == v[i].x) e++;
		for(int j = i; j < e; j++){
			seg.add(0, v[j].y - 1, 0, m, 1, v[j].c);
		}
		while(pw < w.size() && w[pw].x <= v[i].x){
			seg.add(w[pw].y, m, 0, m, 1, w[pw].c);
			pw++;
		}
		if(v[i].x <= n){
			for(int j = i; j < e; j++){
				dp[j] = seg.query(v[j].y - 1, 0, m, 1);
			}
			for(int j = i; j < e; j++){
				seg.upperize(v[j].y - 1, m, 0, m, 1, dp[j]);
			}
		}
		i = e;
	}
	lint dap = -1e18;
	for(int i=0; i<=m; i++) dap = max(dap, seg.query(i, 0, m, 1));
	cout << ret + dap << endl;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:106:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<v.size(); ){
               ~^~~~~~~~~
dishes.cpp:108:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(e < v.size() && v[e].x == v[i].x) e++;
         ~~^~~~~~~~~~
dishes.cpp:112:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(pw < w.size() && w[pw].x <= v[i].x){
         ~~~^~~~~~~~~~
dishes.cpp:69: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:71:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld",&a[i],&s[i],&p[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld",&b[i],&t[i],&q[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 410 ms 26844 KB Output is correct
2 Correct 424 ms 26352 KB Output is correct
3 Correct 239 ms 19676 KB Output is correct
4 Correct 343 ms 24360 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 365 ms 24884 KB Output is correct
7 Correct 133 ms 14072 KB Output is correct
8 Correct 100 ms 5880 KB Output is correct
9 Correct 245 ms 19612 KB Output is correct
10 Correct 366 ms 27784 KB Output is correct
11 Correct 185 ms 19576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 6 ms 604 KB Output is correct
22 Correct 5 ms 760 KB Output is correct
23 Correct 5 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 6 ms 604 KB Output is correct
22 Correct 5 ms 760 KB Output is correct
23 Correct 5 ms 764 KB Output is correct
24 Correct 320 ms 24452 KB Output is correct
25 Correct 278 ms 22876 KB Output is correct
26 Correct 358 ms 24544 KB Output is correct
27 Correct 286 ms 22904 KB Output is correct
28 Correct 324 ms 21736 KB Output is correct
29 Correct 210 ms 19640 KB Output is correct
30 Correct 561 ms 27216 KB Output is correct
31 Correct 149 ms 15720 KB Output is correct
32 Correct 102 ms 8416 KB Output is correct
33 Correct 418 ms 23396 KB Output is correct
34 Correct 477 ms 25628 KB Output is correct
35 Correct 496 ms 27516 KB Output is correct
36 Correct 487 ms 27240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 6 ms 604 KB Output is correct
22 Correct 5 ms 760 KB Output is correct
23 Correct 5 ms 764 KB Output is correct
24 Correct 320 ms 24452 KB Output is correct
25 Correct 278 ms 22876 KB Output is correct
26 Correct 358 ms 24544 KB Output is correct
27 Correct 286 ms 22904 KB Output is correct
28 Correct 324 ms 21736 KB Output is correct
29 Correct 210 ms 19640 KB Output is correct
30 Correct 561 ms 27216 KB Output is correct
31 Correct 149 ms 15720 KB Output is correct
32 Correct 102 ms 8416 KB Output is correct
33 Correct 418 ms 23396 KB Output is correct
34 Correct 477 ms 25628 KB Output is correct
35 Correct 496 ms 27516 KB Output is correct
36 Correct 487 ms 27240 KB Output is correct
37 Correct 393 ms 24464 KB Output is correct
38 Correct 320 ms 22848 KB Output is correct
39 Correct 419 ms 27604 KB Output is correct
40 Correct 411 ms 27604 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 593 ms 27652 KB Output is correct
43 Correct 431 ms 23268 KB Output is correct
44 Correct 501 ms 25392 KB Output is correct
45 Correct 526 ms 27508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 6 ms 604 KB Output is correct
22 Correct 5 ms 760 KB Output is correct
23 Correct 5 ms 764 KB Output is correct
24 Correct 320 ms 24452 KB Output is correct
25 Correct 278 ms 22876 KB Output is correct
26 Correct 358 ms 24544 KB Output is correct
27 Correct 286 ms 22904 KB Output is correct
28 Correct 324 ms 21736 KB Output is correct
29 Correct 210 ms 19640 KB Output is correct
30 Correct 561 ms 27216 KB Output is correct
31 Correct 149 ms 15720 KB Output is correct
32 Correct 102 ms 8416 KB Output is correct
33 Correct 418 ms 23396 KB Output is correct
34 Correct 477 ms 25628 KB Output is correct
35 Correct 496 ms 27516 KB Output is correct
36 Correct 487 ms 27240 KB Output is correct
37 Correct 393 ms 24464 KB Output is correct
38 Correct 320 ms 22848 KB Output is correct
39 Correct 419 ms 27604 KB Output is correct
40 Correct 411 ms 27604 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 593 ms 27652 KB Output is correct
43 Correct 431 ms 23268 KB Output is correct
44 Correct 501 ms 25392 KB Output is correct
45 Correct 526 ms 27508 KB Output is correct
46 Correct 2021 ms 111620 KB Output is correct
47 Correct 1618 ms 103852 KB Output is correct
48 Correct 2139 ms 127436 KB Output is correct
49 Correct 2168 ms 127308 KB Output is correct
50 Correct 3660 ms 126588 KB Output is correct
51 Correct 2353 ms 104640 KB Output is correct
52 Correct 2685 ms 111644 KB Output is correct
53 Correct 3094 ms 125012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 410 ms 26844 KB Output is correct
2 Correct 424 ms 26352 KB Output is correct
3 Correct 239 ms 19676 KB Output is correct
4 Correct 343 ms 24360 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 365 ms 24884 KB Output is correct
7 Correct 133 ms 14072 KB Output is correct
8 Correct 100 ms 5880 KB Output is correct
9 Correct 245 ms 19612 KB Output is correct
10 Correct 366 ms 27784 KB Output is correct
11 Correct 185 ms 19576 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 6 ms 760 KB Output is correct
31 Correct 5 ms 632 KB Output is correct
32 Correct 6 ms 604 KB Output is correct
33 Correct 5 ms 760 KB Output is correct
34 Correct 5 ms 764 KB Output is correct
35 Correct 320 ms 24452 KB Output is correct
36 Correct 278 ms 22876 KB Output is correct
37 Correct 358 ms 24544 KB Output is correct
38 Correct 286 ms 22904 KB Output is correct
39 Correct 324 ms 21736 KB Output is correct
40 Correct 210 ms 19640 KB Output is correct
41 Correct 561 ms 27216 KB Output is correct
42 Correct 149 ms 15720 KB Output is correct
43 Correct 102 ms 8416 KB Output is correct
44 Correct 418 ms 23396 KB Output is correct
45 Correct 477 ms 25628 KB Output is correct
46 Correct 496 ms 27516 KB Output is correct
47 Correct 487 ms 27240 KB Output is correct
48 Correct 393 ms 24464 KB Output is correct
49 Correct 320 ms 22848 KB Output is correct
50 Correct 419 ms 27604 KB Output is correct
51 Correct 411 ms 27604 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 593 ms 27652 KB Output is correct
54 Correct 431 ms 23268 KB Output is correct
55 Correct 501 ms 25392 KB Output is correct
56 Correct 526 ms 27508 KB Output is correct
57 Correct 319 ms 22900 KB Output is correct
58 Correct 391 ms 30968 KB Output is correct
59 Correct 534 ms 35968 KB Output is correct
60 Correct 390 ms 38132 KB Output is correct
61 Correct 579 ms 38356 KB Output is correct
62 Correct 2 ms 376 KB Output is correct
63 Correct 614 ms 41292 KB Output is correct
64 Correct 427 ms 36664 KB Output is correct
65 Correct 521 ms 39240 KB Output is correct
66 Correct 537 ms 34880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 410 ms 26844 KB Output is correct
2 Correct 424 ms 26352 KB Output is correct
3 Correct 239 ms 19676 KB Output is correct
4 Correct 343 ms 24360 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 365 ms 24884 KB Output is correct
7 Correct 133 ms 14072 KB Output is correct
8 Correct 100 ms 5880 KB Output is correct
9 Correct 245 ms 19612 KB Output is correct
10 Correct 366 ms 27784 KB Output is correct
11 Correct 185 ms 19576 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 6 ms 760 KB Output is correct
31 Correct 5 ms 632 KB Output is correct
32 Correct 6 ms 604 KB Output is correct
33 Correct 5 ms 760 KB Output is correct
34 Correct 5 ms 764 KB Output is correct
35 Correct 320 ms 24452 KB Output is correct
36 Correct 278 ms 22876 KB Output is correct
37 Correct 358 ms 24544 KB Output is correct
38 Correct 286 ms 22904 KB Output is correct
39 Correct 324 ms 21736 KB Output is correct
40 Correct 210 ms 19640 KB Output is correct
41 Correct 561 ms 27216 KB Output is correct
42 Correct 149 ms 15720 KB Output is correct
43 Correct 102 ms 8416 KB Output is correct
44 Correct 418 ms 23396 KB Output is correct
45 Correct 477 ms 25628 KB Output is correct
46 Correct 496 ms 27516 KB Output is correct
47 Correct 487 ms 27240 KB Output is correct
48 Correct 393 ms 24464 KB Output is correct
49 Correct 320 ms 22848 KB Output is correct
50 Correct 419 ms 27604 KB Output is correct
51 Correct 411 ms 27604 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 593 ms 27652 KB Output is correct
54 Correct 431 ms 23268 KB Output is correct
55 Correct 501 ms 25392 KB Output is correct
56 Correct 526 ms 27508 KB Output is correct
57 Correct 2021 ms 111620 KB Output is correct
58 Correct 1618 ms 103852 KB Output is correct
59 Correct 2139 ms 127436 KB Output is correct
60 Correct 2168 ms 127308 KB Output is correct
61 Correct 3660 ms 126588 KB Output is correct
62 Correct 2353 ms 104640 KB Output is correct
63 Correct 2685 ms 111644 KB Output is correct
64 Correct 3094 ms 125012 KB Output is correct
65 Correct 319 ms 22900 KB Output is correct
66 Correct 391 ms 30968 KB Output is correct
67 Correct 534 ms 35968 KB Output is correct
68 Correct 390 ms 38132 KB Output is correct
69 Correct 579 ms 38356 KB Output is correct
70 Correct 2 ms 376 KB Output is correct
71 Correct 614 ms 41292 KB Output is correct
72 Correct 427 ms 36664 KB Output is correct
73 Correct 521 ms 39240 KB Output is correct
74 Correct 537 ms 34880 KB Output is correct
75 Correct 1644 ms 129312 KB Output is correct
76 Correct 2029 ms 136956 KB Output is correct
77 Correct 2810 ms 147624 KB Output is correct
78 Correct 2012 ms 139872 KB Output is correct
79 Correct 3643 ms 151276 KB Output is correct
80 Correct 2371 ms 127936 KB Output is correct
81 Correct 2823 ms 135804 KB Output is correct
82 Correct 3245 ms 138900 KB Output is correct
83 Correct 3407 ms 144272 KB Output is correct