Submission #768096

# Submission time Handle Problem Language Result Execution time Memory
768096 2023-06-27T12:59:02 Z qwerasdfzxcl Two Dishes (JOI19_dishes) C++17
74 / 100
3544 ms 228312 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
constexpr ll INF = 4e18;

struct Foo{
	ll a, b;
	bool id;

	Foo(){}

	ll calc(ll x){return max(a, x) + b;}

	void operator += (const Foo &F){
		if (!id) {*this = F; return;}

		a = (a+b > F.a)?a:(F.a - b);
		b += F.b;
	}
};

struct Seg{
	ll ans[1101000];
	Foo lazy[2202000];
	
	void propagate(int i, int l, int r){
		if (!lazy[i].id) return;

		if (l==r) ans[l] = lazy[i].calc(ans[l]);
		else{
			lazy[i<<1] += lazy[i];
			lazy[i<<1|1] += lazy[i]; 
		}

		lazy[i].id = 0;
	}

	void add(int i, int l, int r, int s, int e, int x){
		propagate(i, l, r);
		if (r<s || e<l) return;
		if (s<=l && r<=e){
			lazy[i].a = -INF, lazy[i].b = x, lazy[i].id = 1;
			propagate(i, l, r);
			return;
		}

		int m = (l+r)>>1;
		add(i<<1, l, m, s, e, x); add(i<<1|1, m+1, r, s, e, x);
	}

	void max(int i, int l, int r, int s, int e, ll x){
		propagate(i, l, r);
		if (r<s || e<l) return;
		if (s<=l && r<=e){
			lazy[i].a = x, lazy[i].b = 0, lazy[i].id = 1;
			propagate(i, l, r);
			return;
		}

		int m = (l+r)>>1;
		max(i<<1, l, m, s, e, x); max(i<<1|1, m+1, r, s, e, x);
	}

	ll query(int i, int l, int r, int p){
		propagate(i, l, r);
		if (l==r) return ans[l];

		int m = (l+r)>>1;
		if (p<=m) return query(i<<1, l, m, p);
		return query(i<<1|1, m+1, r, p);
	}
}tree;

int n, m;
int A[1001000], B[1001000], P[1001000], Q[1001000], mxA[1001000], mxB[1001000];
ll S[1001000], T[1001000], sumA[1001000], sumB[1001000], ans;
vector<pair<int, int>> lowerQ[1001000], upperQ[1001000];

void init(){
	for (int i=1;i<=n;i++) sumA[i] = sumA[i-1] + A[i];
	for (int i=1;i<=m;i++) sumB[i] = sumB[i-1] + B[i];
 
	for (int i=1;i<=n;i++){
		mxB[i] = upper_bound(sumB, sumB+m+1, S[i] - sumA[i]) - sumB - 1;

		if (mxB[i] >= 0) lowerQ[i-1].emplace_back(mxB[i], P[i]);
	}
	for (int i=1;i<=m;i++){
		mxA[i] = upper_bound(sumA, sumA+n+1, T[i] - sumB[i]) - sumA - 1;

		if (mxA[i]==n) ans += Q[i];
		else if (mxA[i] >= 0) upperQ[mxA[i]].emplace_back(i, Q[i]);
	}

	for (int i=0;i<n;i++){
		sort(lowerQ[i].begin(), lowerQ[i].end(), greater<pair<int, int>>());
		sort(upperQ[i].begin(), upperQ[i].end());
	}

}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> n >> m;
	for (int i=1;i<=n;i++) cin >> A[i] >> S[i] >> P[i];
	for (int i=1;i<=m;i++) cin >> B[i] >> T[i] >> Q[i];
 
	init();
 
	for (int x=0;x<n;x++){
		for (auto &[y, val]:upperQ[x]) tree.add(1, 0, m, y, m, val);
		for (auto &[y, val]:lowerQ[x]){
			tree.add(1, 0, m, 0, y, val);
			tree.max(1, 0, m, y+1, m, tree.query(1, 0, m, y));
		}
	}
 
	printf("%lld\n", tree.query(1, 0, m, m) + ans);
}
# Verdict Execution time Memory Grader output
1 Correct 275 ms 80540 KB Output is correct
2 Correct 260 ms 80108 KB Output is correct
3 Correct 212 ms 77976 KB Output is correct
4 Correct 236 ms 88084 KB Output is correct
5 Correct 26 ms 47380 KB Output is correct
6 Correct 283 ms 90832 KB Output is correct
7 Correct 89 ms 59756 KB Output is correct
8 Correct 113 ms 66040 KB Output is correct
9 Correct 177 ms 79028 KB Output is correct
10 Correct 248 ms 92056 KB Output is correct
11 Correct 154 ms 72452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47332 KB Output is correct
2 Correct 25 ms 47316 KB Output is correct
3 Correct 25 ms 47432 KB Output is correct
4 Correct 27 ms 47300 KB Output is correct
5 Correct 28 ms 47316 KB Output is correct
6 Correct 24 ms 47376 KB Output is correct
7 Correct 27 ms 47316 KB Output is correct
8 Correct 23 ms 47332 KB Output is correct
9 Correct 24 ms 47396 KB Output is correct
10 Correct 23 ms 47376 KB Output is correct
11 Correct 22 ms 47312 KB Output is correct
12 Correct 26 ms 47396 KB Output is correct
13 Correct 22 ms 47412 KB Output is correct
14 Correct 27 ms 47316 KB Output is correct
15 Correct 29 ms 47316 KB Output is correct
16 Correct 24 ms 47388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47332 KB Output is correct
2 Correct 25 ms 47316 KB Output is correct
3 Correct 25 ms 47432 KB Output is correct
4 Correct 27 ms 47300 KB Output is correct
5 Correct 28 ms 47316 KB Output is correct
6 Correct 24 ms 47376 KB Output is correct
7 Correct 27 ms 47316 KB Output is correct
8 Correct 23 ms 47332 KB Output is correct
9 Correct 24 ms 47396 KB Output is correct
10 Correct 23 ms 47376 KB Output is correct
11 Correct 22 ms 47312 KB Output is correct
12 Correct 26 ms 47396 KB Output is correct
13 Correct 22 ms 47412 KB Output is correct
14 Correct 27 ms 47316 KB Output is correct
15 Correct 29 ms 47316 KB Output is correct
16 Correct 24 ms 47388 KB Output is correct
17 Correct 25 ms 47628 KB Output is correct
18 Correct 24 ms 47604 KB Output is correct
19 Correct 25 ms 47724 KB Output is correct
20 Correct 30 ms 47636 KB Output is correct
21 Correct 28 ms 47692 KB Output is correct
22 Correct 28 ms 47648 KB Output is correct
23 Correct 26 ms 47628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47332 KB Output is correct
2 Correct 25 ms 47316 KB Output is correct
3 Correct 25 ms 47432 KB Output is correct
4 Correct 27 ms 47300 KB Output is correct
5 Correct 28 ms 47316 KB Output is correct
6 Correct 24 ms 47376 KB Output is correct
7 Correct 27 ms 47316 KB Output is correct
8 Correct 23 ms 47332 KB Output is correct
9 Correct 24 ms 47396 KB Output is correct
10 Correct 23 ms 47376 KB Output is correct
11 Correct 22 ms 47312 KB Output is correct
12 Correct 26 ms 47396 KB Output is correct
13 Correct 22 ms 47412 KB Output is correct
14 Correct 27 ms 47316 KB Output is correct
15 Correct 29 ms 47316 KB Output is correct
16 Correct 24 ms 47388 KB Output is correct
17 Correct 25 ms 47628 KB Output is correct
18 Correct 24 ms 47604 KB Output is correct
19 Correct 25 ms 47724 KB Output is correct
20 Correct 30 ms 47636 KB Output is correct
21 Correct 28 ms 47692 KB Output is correct
22 Correct 28 ms 47648 KB Output is correct
23 Correct 26 ms 47628 KB Output is correct
24 Correct 192 ms 64704 KB Output is correct
25 Correct 180 ms 76992 KB Output is correct
26 Correct 220 ms 78420 KB Output is correct
27 Correct 242 ms 81580 KB Output is correct
28 Correct 249 ms 79052 KB Output is correct
29 Correct 152 ms 64716 KB Output is correct
30 Correct 546 ms 82464 KB Output is correct
31 Correct 119 ms 67652 KB Output is correct
32 Correct 85 ms 59112 KB Output is correct
33 Correct 337 ms 77816 KB Output is correct
34 Correct 430 ms 81104 KB Output is correct
35 Correct 489 ms 82672 KB Output is correct
36 Correct 490 ms 82356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47332 KB Output is correct
2 Correct 25 ms 47316 KB Output is correct
3 Correct 25 ms 47432 KB Output is correct
4 Correct 27 ms 47300 KB Output is correct
5 Correct 28 ms 47316 KB Output is correct
6 Correct 24 ms 47376 KB Output is correct
7 Correct 27 ms 47316 KB Output is correct
8 Correct 23 ms 47332 KB Output is correct
9 Correct 24 ms 47396 KB Output is correct
10 Correct 23 ms 47376 KB Output is correct
11 Correct 22 ms 47312 KB Output is correct
12 Correct 26 ms 47396 KB Output is correct
13 Correct 22 ms 47412 KB Output is correct
14 Correct 27 ms 47316 KB Output is correct
15 Correct 29 ms 47316 KB Output is correct
16 Correct 24 ms 47388 KB Output is correct
17 Correct 25 ms 47628 KB Output is correct
18 Correct 24 ms 47604 KB Output is correct
19 Correct 25 ms 47724 KB Output is correct
20 Correct 30 ms 47636 KB Output is correct
21 Correct 28 ms 47692 KB Output is correct
22 Correct 28 ms 47648 KB Output is correct
23 Correct 26 ms 47628 KB Output is correct
24 Correct 192 ms 64704 KB Output is correct
25 Correct 180 ms 76992 KB Output is correct
26 Correct 220 ms 78420 KB Output is correct
27 Correct 242 ms 81580 KB Output is correct
28 Correct 249 ms 79052 KB Output is correct
29 Correct 152 ms 64716 KB Output is correct
30 Correct 546 ms 82464 KB Output is correct
31 Correct 119 ms 67652 KB Output is correct
32 Correct 85 ms 59112 KB Output is correct
33 Correct 337 ms 77816 KB Output is correct
34 Correct 430 ms 81104 KB Output is correct
35 Correct 489 ms 82672 KB Output is correct
36 Correct 490 ms 82356 KB Output is correct
37 Correct 247 ms 78412 KB Output is correct
38 Correct 235 ms 95216 KB Output is correct
39 Correct 286 ms 95812 KB Output is correct
40 Correct 301 ms 95748 KB Output is correct
41 Correct 25 ms 47316 KB Output is correct
42 Correct 593 ms 96300 KB Output is correct
43 Correct 360 ms 90956 KB Output is correct
44 Correct 439 ms 94640 KB Output is correct
45 Correct 503 ms 90060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47332 KB Output is correct
2 Correct 25 ms 47316 KB Output is correct
3 Correct 25 ms 47432 KB Output is correct
4 Correct 27 ms 47300 KB Output is correct
5 Correct 28 ms 47316 KB Output is correct
6 Correct 24 ms 47376 KB Output is correct
7 Correct 27 ms 47316 KB Output is correct
8 Correct 23 ms 47332 KB Output is correct
9 Correct 24 ms 47396 KB Output is correct
10 Correct 23 ms 47376 KB Output is correct
11 Correct 22 ms 47312 KB Output is correct
12 Correct 26 ms 47396 KB Output is correct
13 Correct 22 ms 47412 KB Output is correct
14 Correct 27 ms 47316 KB Output is correct
15 Correct 29 ms 47316 KB Output is correct
16 Correct 24 ms 47388 KB Output is correct
17 Correct 25 ms 47628 KB Output is correct
18 Correct 24 ms 47604 KB Output is correct
19 Correct 25 ms 47724 KB Output is correct
20 Correct 30 ms 47636 KB Output is correct
21 Correct 28 ms 47692 KB Output is correct
22 Correct 28 ms 47648 KB Output is correct
23 Correct 26 ms 47628 KB Output is correct
24 Correct 192 ms 64704 KB Output is correct
25 Correct 180 ms 76992 KB Output is correct
26 Correct 220 ms 78420 KB Output is correct
27 Correct 242 ms 81580 KB Output is correct
28 Correct 249 ms 79052 KB Output is correct
29 Correct 152 ms 64716 KB Output is correct
30 Correct 546 ms 82464 KB Output is correct
31 Correct 119 ms 67652 KB Output is correct
32 Correct 85 ms 59112 KB Output is correct
33 Correct 337 ms 77816 KB Output is correct
34 Correct 430 ms 81104 KB Output is correct
35 Correct 489 ms 82672 KB Output is correct
36 Correct 490 ms 82356 KB Output is correct
37 Correct 247 ms 78412 KB Output is correct
38 Correct 235 ms 95216 KB Output is correct
39 Correct 286 ms 95812 KB Output is correct
40 Correct 301 ms 95748 KB Output is correct
41 Correct 25 ms 47316 KB Output is correct
42 Correct 593 ms 96300 KB Output is correct
43 Correct 360 ms 90956 KB Output is correct
44 Correct 439 ms 94640 KB Output is correct
45 Correct 503 ms 90060 KB Output is correct
46 Correct 1195 ms 194744 KB Output is correct
47 Correct 1132 ms 212420 KB Output is correct
48 Correct 1319 ms 224912 KB Output is correct
49 Correct 1441 ms 228312 KB Output is correct
50 Correct 3544 ms 214720 KB Output is correct
51 Correct 2072 ms 186956 KB Output is correct
52 Correct 2562 ms 203344 KB Output is correct
53 Correct 3395 ms 215384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 275 ms 80540 KB Output is correct
2 Correct 260 ms 80108 KB Output is correct
3 Correct 212 ms 77976 KB Output is correct
4 Correct 236 ms 88084 KB Output is correct
5 Correct 26 ms 47380 KB Output is correct
6 Correct 283 ms 90832 KB Output is correct
7 Correct 89 ms 59756 KB Output is correct
8 Correct 113 ms 66040 KB Output is correct
9 Correct 177 ms 79028 KB Output is correct
10 Correct 248 ms 92056 KB Output is correct
11 Correct 154 ms 72452 KB Output is correct
12 Correct 26 ms 47332 KB Output is correct
13 Correct 25 ms 47316 KB Output is correct
14 Correct 25 ms 47432 KB Output is correct
15 Correct 27 ms 47300 KB Output is correct
16 Correct 28 ms 47316 KB Output is correct
17 Correct 24 ms 47376 KB Output is correct
18 Correct 27 ms 47316 KB Output is correct
19 Correct 23 ms 47332 KB Output is correct
20 Correct 24 ms 47396 KB Output is correct
21 Correct 23 ms 47376 KB Output is correct
22 Correct 22 ms 47312 KB Output is correct
23 Correct 26 ms 47396 KB Output is correct
24 Correct 22 ms 47412 KB Output is correct
25 Correct 27 ms 47316 KB Output is correct
26 Correct 29 ms 47316 KB Output is correct
27 Correct 24 ms 47388 KB Output is correct
28 Correct 25 ms 47628 KB Output is correct
29 Correct 24 ms 47604 KB Output is correct
30 Correct 25 ms 47724 KB Output is correct
31 Correct 30 ms 47636 KB Output is correct
32 Correct 28 ms 47692 KB Output is correct
33 Correct 28 ms 47648 KB Output is correct
34 Correct 26 ms 47628 KB Output is correct
35 Correct 192 ms 64704 KB Output is correct
36 Correct 180 ms 76992 KB Output is correct
37 Correct 220 ms 78420 KB Output is correct
38 Correct 242 ms 81580 KB Output is correct
39 Correct 249 ms 79052 KB Output is correct
40 Correct 152 ms 64716 KB Output is correct
41 Correct 546 ms 82464 KB Output is correct
42 Correct 119 ms 67652 KB Output is correct
43 Correct 85 ms 59112 KB Output is correct
44 Correct 337 ms 77816 KB Output is correct
45 Correct 430 ms 81104 KB Output is correct
46 Correct 489 ms 82672 KB Output is correct
47 Correct 490 ms 82356 KB Output is correct
48 Correct 247 ms 78412 KB Output is correct
49 Correct 235 ms 95216 KB Output is correct
50 Correct 286 ms 95812 KB Output is correct
51 Correct 301 ms 95748 KB Output is correct
52 Correct 25 ms 47316 KB Output is correct
53 Correct 593 ms 96300 KB Output is correct
54 Correct 360 ms 90956 KB Output is correct
55 Correct 439 ms 94640 KB Output is correct
56 Correct 503 ms 90060 KB Output is correct
57 Correct 283 ms 87376 KB Output is correct
58 Incorrect 276 ms 88956 KB Output isn't correct
59 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 275 ms 80540 KB Output is correct
2 Correct 260 ms 80108 KB Output is correct
3 Correct 212 ms 77976 KB Output is correct
4 Correct 236 ms 88084 KB Output is correct
5 Correct 26 ms 47380 KB Output is correct
6 Correct 283 ms 90832 KB Output is correct
7 Correct 89 ms 59756 KB Output is correct
8 Correct 113 ms 66040 KB Output is correct
9 Correct 177 ms 79028 KB Output is correct
10 Correct 248 ms 92056 KB Output is correct
11 Correct 154 ms 72452 KB Output is correct
12 Correct 26 ms 47332 KB Output is correct
13 Correct 25 ms 47316 KB Output is correct
14 Correct 25 ms 47432 KB Output is correct
15 Correct 27 ms 47300 KB Output is correct
16 Correct 28 ms 47316 KB Output is correct
17 Correct 24 ms 47376 KB Output is correct
18 Correct 27 ms 47316 KB Output is correct
19 Correct 23 ms 47332 KB Output is correct
20 Correct 24 ms 47396 KB Output is correct
21 Correct 23 ms 47376 KB Output is correct
22 Correct 22 ms 47312 KB Output is correct
23 Correct 26 ms 47396 KB Output is correct
24 Correct 22 ms 47412 KB Output is correct
25 Correct 27 ms 47316 KB Output is correct
26 Correct 29 ms 47316 KB Output is correct
27 Correct 24 ms 47388 KB Output is correct
28 Correct 25 ms 47628 KB Output is correct
29 Correct 24 ms 47604 KB Output is correct
30 Correct 25 ms 47724 KB Output is correct
31 Correct 30 ms 47636 KB Output is correct
32 Correct 28 ms 47692 KB Output is correct
33 Correct 28 ms 47648 KB Output is correct
34 Correct 26 ms 47628 KB Output is correct
35 Correct 192 ms 64704 KB Output is correct
36 Correct 180 ms 76992 KB Output is correct
37 Correct 220 ms 78420 KB Output is correct
38 Correct 242 ms 81580 KB Output is correct
39 Correct 249 ms 79052 KB Output is correct
40 Correct 152 ms 64716 KB Output is correct
41 Correct 546 ms 82464 KB Output is correct
42 Correct 119 ms 67652 KB Output is correct
43 Correct 85 ms 59112 KB Output is correct
44 Correct 337 ms 77816 KB Output is correct
45 Correct 430 ms 81104 KB Output is correct
46 Correct 489 ms 82672 KB Output is correct
47 Correct 490 ms 82356 KB Output is correct
48 Correct 247 ms 78412 KB Output is correct
49 Correct 235 ms 95216 KB Output is correct
50 Correct 286 ms 95812 KB Output is correct
51 Correct 301 ms 95748 KB Output is correct
52 Correct 25 ms 47316 KB Output is correct
53 Correct 593 ms 96300 KB Output is correct
54 Correct 360 ms 90956 KB Output is correct
55 Correct 439 ms 94640 KB Output is correct
56 Correct 503 ms 90060 KB Output is correct
57 Correct 1195 ms 194744 KB Output is correct
58 Correct 1132 ms 212420 KB Output is correct
59 Correct 1319 ms 224912 KB Output is correct
60 Correct 1441 ms 228312 KB Output is correct
61 Correct 3544 ms 214720 KB Output is correct
62 Correct 2072 ms 186956 KB Output is correct
63 Correct 2562 ms 203344 KB Output is correct
64 Correct 3395 ms 215384 KB Output is correct
65 Correct 283 ms 87376 KB Output is correct
66 Incorrect 276 ms 88956 KB Output isn't correct
67 Halted 0 ms 0 KB -