Submission #118850

# Submission time Handle Problem Language Result Execution time Memory
118850 2019-06-19T23:45:14 Z tmwilliamlin168 Two Dishes (JOI19_dishes) C++14
100 / 100
5296 ms 206040 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=1e6;
int n, m, p[mxN], q[mxN];
ll a[mxN+1], b[mxN+1], s[mxN], t[mxN], ans, lz[1<<21];
vector<array<ll, 3>> e;
array<ll, 2> st[1<<21];

void app(int i, ll x) {
	st[i][0]+=x;
	st[i][1]+=x;
	lz[i]+=x;
}

void psh(int i) {
	app(2*i, lz[i]);
	app(2*i+1, lz[i]);
	lz[i]=0;
}

void upd1(int l1, int r1, ll x, int i=1, int l2=0, int r2=m) {
	if(l1<=l2&&r2<=r1) {
		app(i, x);
		return;
	}
	int m2=(l2+r2)/2;
	psh(i);
	if(l1<=m2)
		upd1(l1, r1, x, 2*i, l2, m2);
	if(m2<r1)
		upd1(l1, r1, x, 2*i+1, m2+1, r2);
	st[i][0]=min(st[2*i][0], st[2*i+1][0]);
	st[i][1]=max(st[2*i][1], st[2*i+1][1]);
}

void upd2(int l1, int r1, ll x, int i=1, int l2=0, int r2=m) {
	if(st[i][0]>=x)
		return;
	if(l1<=l2&&r2<=r1&&st[i][0]==st[i][1]) {
		app(i, x-st[i][0]);
		return;
	}
	int m2=(l2+r2)/2;
	psh(i);
	if(l1<=m2)
		upd2(l1, r1, x, 2*i, l2, m2);
	if(m2<r1)
		upd2(l1, r1, x, 2*i+1, m2+1, r2);
	st[i][0]=min(st[2*i][0], st[2*i+1][0]);
	st[i][1]=max(st[2*i][1], st[2*i+1][1]);
}

ll qry(int l1, int i=1, int l2=0, int r2=m) {
	if(l2==r2)
		return st[i][0];
	int m2=(l2+r2)/2;
	psh(i);
	return l1<=m2?qry(l1, 2*i, l2, m2):qry(l1, 2*i+1, m2+1, r2);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> n >> m;
	for(int i=0; i<n; ++i)
		cin >> a[i+1] >> s[i] >> p[i], a[i+1]+=a[i];
	for(int i=0; i<m; ++i) {
		cin >> b[i+1] >> t[i] >> q[i], b[i+1]+=b[i];
		e.push_back({upper_bound(a, a+n+1, t[i]-b[i+1])-a, -i, -q[i]});
		if(e.back()[0])
			ans+=q[i];
		else
			e.pop_back();
	}
	for(int i=0; i<n; ++i) {
		int j=upper_bound(b, b+m+1, s[i]-a[i+1])-b;
		if(j)
			e.push_back({i+1, -j+1, p[i]});
	}
	sort(e.begin(), e.end());
	for(array<ll, 3> f : e) {
		if(f[0]>n)
			break;
		upd1(0, -f[1], f[2]);
		upd2(-f[1], m, qry(-f[1]));
	}
	cout << ans+qry(m);
}
# Verdict Execution time Memory Grader output
1 Correct 377 ms 41548 KB Output is correct
2 Correct 474 ms 42184 KB Output is correct
3 Correct 261 ms 34196 KB Output is correct
4 Correct 305 ms 35544 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 383 ms 39880 KB Output is correct
7 Correct 100 ms 15576 KB Output is correct
8 Correct 99 ms 17640 KB Output is correct
9 Correct 264 ms 35472 KB Output is correct
10 Correct 393 ms 37668 KB Output is correct
11 Correct 204 ms 28504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 6 ms 896 KB Output is correct
20 Correct 5 ms 768 KB Output is correct
21 Correct 6 ms 896 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 5 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 6 ms 896 KB Output is correct
20 Correct 5 ms 768 KB Output is correct
21 Correct 6 ms 896 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 5 ms 768 KB Output is correct
24 Correct 329 ms 31320 KB Output is correct
25 Correct 336 ms 38344 KB Output is correct
26 Correct 345 ms 38504 KB Output is correct
27 Correct 343 ms 38628 KB Output is correct
28 Correct 382 ms 39808 KB Output is correct
29 Correct 247 ms 31960 KB Output is correct
30 Correct 714 ms 40752 KB Output is correct
31 Correct 151 ms 26712 KB Output is correct
32 Correct 92 ms 15848 KB Output is correct
33 Correct 421 ms 35748 KB Output is correct
34 Correct 606 ms 40264 KB Output is correct
35 Correct 635 ms 34380 KB Output is correct
36 Correct 617 ms 34176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 6 ms 896 KB Output is correct
20 Correct 5 ms 768 KB Output is correct
21 Correct 6 ms 896 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 5 ms 768 KB Output is correct
24 Correct 329 ms 31320 KB Output is correct
25 Correct 336 ms 38344 KB Output is correct
26 Correct 345 ms 38504 KB Output is correct
27 Correct 343 ms 38628 KB Output is correct
28 Correct 382 ms 39808 KB Output is correct
29 Correct 247 ms 31960 KB Output is correct
30 Correct 714 ms 40752 KB Output is correct
31 Correct 151 ms 26712 KB Output is correct
32 Correct 92 ms 15848 KB Output is correct
33 Correct 421 ms 35748 KB Output is correct
34 Correct 606 ms 40264 KB Output is correct
35 Correct 635 ms 34380 KB Output is correct
36 Correct 617 ms 34176 KB Output is correct
37 Correct 401 ms 41452 KB Output is correct
38 Correct 353 ms 41384 KB Output is correct
39 Correct 397 ms 41320 KB Output is correct
40 Correct 522 ms 41256 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1064 ms 43692 KB Output is correct
43 Correct 456 ms 38616 KB Output is correct
44 Correct 612 ms 43360 KB Output is correct
45 Correct 761 ms 37320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 6 ms 896 KB Output is correct
20 Correct 5 ms 768 KB Output is correct
21 Correct 6 ms 896 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 5 ms 768 KB Output is correct
24 Correct 329 ms 31320 KB Output is correct
25 Correct 336 ms 38344 KB Output is correct
26 Correct 345 ms 38504 KB Output is correct
27 Correct 343 ms 38628 KB Output is correct
28 Correct 382 ms 39808 KB Output is correct
29 Correct 247 ms 31960 KB Output is correct
30 Correct 714 ms 40752 KB Output is correct
31 Correct 151 ms 26712 KB Output is correct
32 Correct 92 ms 15848 KB Output is correct
33 Correct 421 ms 35748 KB Output is correct
34 Correct 606 ms 40264 KB Output is correct
35 Correct 635 ms 34380 KB Output is correct
36 Correct 617 ms 34176 KB Output is correct
37 Correct 401 ms 41452 KB Output is correct
38 Correct 353 ms 41384 KB Output is correct
39 Correct 397 ms 41320 KB Output is correct
40 Correct 522 ms 41256 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1064 ms 43692 KB Output is correct
43 Correct 456 ms 38616 KB Output is correct
44 Correct 612 ms 43360 KB Output is correct
45 Correct 761 ms 37320 KB Output is correct
46 Correct 1814 ms 194120 KB Output is correct
47 Correct 1906 ms 194288 KB Output is correct
48 Correct 2291 ms 192184 KB Output is correct
49 Correct 2864 ms 192140 KB Output is correct
50 Correct 5202 ms 205476 KB Output is correct
51 Correct 2899 ms 177580 KB Output is correct
52 Correct 3706 ms 196984 KB Output is correct
53 Correct 4750 ms 173452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 377 ms 41548 KB Output is correct
2 Correct 474 ms 42184 KB Output is correct
3 Correct 261 ms 34196 KB Output is correct
4 Correct 305 ms 35544 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 383 ms 39880 KB Output is correct
7 Correct 100 ms 15576 KB Output is correct
8 Correct 99 ms 17640 KB Output is correct
9 Correct 264 ms 35472 KB Output is correct
10 Correct 393 ms 37668 KB Output is correct
11 Correct 204 ms 28504 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 440 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 5 ms 768 KB Output is correct
29 Correct 5 ms 768 KB Output is correct
30 Correct 6 ms 896 KB Output is correct
31 Correct 5 ms 768 KB Output is correct
32 Correct 6 ms 896 KB Output is correct
33 Correct 5 ms 768 KB Output is correct
34 Correct 5 ms 768 KB Output is correct
35 Correct 329 ms 31320 KB Output is correct
36 Correct 336 ms 38344 KB Output is correct
37 Correct 345 ms 38504 KB Output is correct
38 Correct 343 ms 38628 KB Output is correct
39 Correct 382 ms 39808 KB Output is correct
40 Correct 247 ms 31960 KB Output is correct
41 Correct 714 ms 40752 KB Output is correct
42 Correct 151 ms 26712 KB Output is correct
43 Correct 92 ms 15848 KB Output is correct
44 Correct 421 ms 35748 KB Output is correct
45 Correct 606 ms 40264 KB Output is correct
46 Correct 635 ms 34380 KB Output is correct
47 Correct 617 ms 34176 KB Output is correct
48 Correct 401 ms 41452 KB Output is correct
49 Correct 353 ms 41384 KB Output is correct
50 Correct 397 ms 41320 KB Output is correct
51 Correct 522 ms 41256 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1064 ms 43692 KB Output is correct
54 Correct 456 ms 38616 KB Output is correct
55 Correct 612 ms 43360 KB Output is correct
56 Correct 761 ms 37320 KB Output is correct
57 Correct 356 ms 41948 KB Output is correct
58 Correct 373 ms 41828 KB Output is correct
59 Correct 606 ms 42276 KB Output is correct
60 Correct 404 ms 42104 KB Output is correct
61 Correct 573 ms 41048 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 802 ms 43976 KB Output is correct
64 Correct 479 ms 38628 KB Output is correct
65 Correct 656 ms 43488 KB Output is correct
66 Correct 689 ms 37448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 377 ms 41548 KB Output is correct
2 Correct 474 ms 42184 KB Output is correct
3 Correct 261 ms 34196 KB Output is correct
4 Correct 305 ms 35544 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 383 ms 39880 KB Output is correct
7 Correct 100 ms 15576 KB Output is correct
8 Correct 99 ms 17640 KB Output is correct
9 Correct 264 ms 35472 KB Output is correct
10 Correct 393 ms 37668 KB Output is correct
11 Correct 204 ms 28504 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 440 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 5 ms 768 KB Output is correct
29 Correct 5 ms 768 KB Output is correct
30 Correct 6 ms 896 KB Output is correct
31 Correct 5 ms 768 KB Output is correct
32 Correct 6 ms 896 KB Output is correct
33 Correct 5 ms 768 KB Output is correct
34 Correct 5 ms 768 KB Output is correct
35 Correct 329 ms 31320 KB Output is correct
36 Correct 336 ms 38344 KB Output is correct
37 Correct 345 ms 38504 KB Output is correct
38 Correct 343 ms 38628 KB Output is correct
39 Correct 382 ms 39808 KB Output is correct
40 Correct 247 ms 31960 KB Output is correct
41 Correct 714 ms 40752 KB Output is correct
42 Correct 151 ms 26712 KB Output is correct
43 Correct 92 ms 15848 KB Output is correct
44 Correct 421 ms 35748 KB Output is correct
45 Correct 606 ms 40264 KB Output is correct
46 Correct 635 ms 34380 KB Output is correct
47 Correct 617 ms 34176 KB Output is correct
48 Correct 401 ms 41452 KB Output is correct
49 Correct 353 ms 41384 KB Output is correct
50 Correct 397 ms 41320 KB Output is correct
51 Correct 522 ms 41256 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1064 ms 43692 KB Output is correct
54 Correct 456 ms 38616 KB Output is correct
55 Correct 612 ms 43360 KB Output is correct
56 Correct 761 ms 37320 KB Output is correct
57 Correct 1814 ms 194120 KB Output is correct
58 Correct 1906 ms 194288 KB Output is correct
59 Correct 2291 ms 192184 KB Output is correct
60 Correct 2864 ms 192140 KB Output is correct
61 Correct 5202 ms 205476 KB Output is correct
62 Correct 2899 ms 177580 KB Output is correct
63 Correct 3706 ms 196984 KB Output is correct
64 Correct 4750 ms 173452 KB Output is correct
65 Correct 356 ms 41948 KB Output is correct
66 Correct 373 ms 41828 KB Output is correct
67 Correct 606 ms 42276 KB Output is correct
68 Correct 404 ms 42104 KB Output is correct
69 Correct 573 ms 41048 KB Output is correct
70 Correct 2 ms 384 KB Output is correct
71 Correct 802 ms 43976 KB Output is correct
72 Correct 479 ms 38628 KB Output is correct
73 Correct 656 ms 43488 KB Output is correct
74 Correct 689 ms 37448 KB Output is correct
75 Correct 1760 ms 195916 KB Output is correct
76 Correct 2004 ms 196048 KB Output is correct
77 Correct 3414 ms 194936 KB Output is correct
78 Correct 2178 ms 194792 KB Output is correct
79 Correct 5296 ms 206040 KB Output is correct
80 Correct 2918 ms 178176 KB Output is correct
81 Correct 3683 ms 198512 KB Output is correct
82 Correct 4714 ms 173856 KB Output is correct
83 Correct 4797 ms 192560 KB Output is correct