Submission #102539

# Submission time Handle Problem Language Result Execution time Memory
102539 2019-03-25T19:32:00 Z ihdignite Two Dishes (JOI19_dishes) C++14
100 / 100
5876 ms 136288 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 392 ms 28068 KB Output is correct
2 Correct 437 ms 28364 KB Output is correct
3 Correct 273 ms 21048 KB Output is correct
4 Correct 324 ms 21772 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 429 ms 26676 KB Output is correct
7 Correct 187 ms 9384 KB Output is correct
8 Correct 182 ms 10664 KB Output is correct
9 Correct 304 ms 20920 KB Output is correct
10 Correct 407 ms 30284 KB Output is correct
11 Correct 210 ms 20824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 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 3 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 3 ms 432 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 3 ms 384 KB Output is correct
3 Correct 2 ms 384 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 3 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 3 ms 432 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 896 KB Output is correct
19 Correct 7 ms 896 KB Output is correct
20 Correct 5 ms 780 KB Output is correct
21 Correct 7 ms 896 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 7 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 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 3 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 3 ms 432 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 896 KB Output is correct
19 Correct 7 ms 896 KB Output is correct
20 Correct 5 ms 780 KB Output is correct
21 Correct 7 ms 896 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 7 ms 768 KB Output is correct
24 Correct 368 ms 20832 KB Output is correct
25 Correct 412 ms 28104 KB Output is correct
26 Correct 335 ms 27948 KB Output is correct
27 Correct 372 ms 27980 KB Output is correct
28 Correct 428 ms 29204 KB Output is correct
29 Correct 269 ms 20824 KB Output is correct
30 Correct 762 ms 30044 KB Output is correct
31 Correct 161 ms 21588 KB Output is correct
32 Correct 115 ms 10736 KB Output is correct
33 Correct 502 ms 25308 KB Output is correct
34 Correct 664 ms 29892 KB Output is correct
35 Correct 823 ms 30284 KB Output is correct
36 Correct 679 ms 29996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 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 3 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 3 ms 432 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 896 KB Output is correct
19 Correct 7 ms 896 KB Output is correct
20 Correct 5 ms 780 KB Output is correct
21 Correct 7 ms 896 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 7 ms 768 KB Output is correct
24 Correct 368 ms 20832 KB Output is correct
25 Correct 412 ms 28104 KB Output is correct
26 Correct 335 ms 27948 KB Output is correct
27 Correct 372 ms 27980 KB Output is correct
28 Correct 428 ms 29204 KB Output is correct
29 Correct 269 ms 20824 KB Output is correct
30 Correct 762 ms 30044 KB Output is correct
31 Correct 161 ms 21588 KB Output is correct
32 Correct 115 ms 10736 KB Output is correct
33 Correct 502 ms 25308 KB Output is correct
34 Correct 664 ms 29892 KB Output is correct
35 Correct 823 ms 30284 KB Output is correct
36 Correct 679 ms 29996 KB Output is correct
37 Correct 343 ms 27836 KB Output is correct
38 Correct 363 ms 27848 KB Output is correct
39 Correct 392 ms 30268 KB Output is correct
40 Correct 564 ms 30272 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 869 ms 30020 KB Output is correct
43 Correct 522 ms 25400 KB Output is correct
44 Correct 735 ms 29740 KB Output is correct
45 Correct 767 ms 30156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 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 3 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 3 ms 432 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 896 KB Output is correct
19 Correct 7 ms 896 KB Output is correct
20 Correct 5 ms 780 KB Output is correct
21 Correct 7 ms 896 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 7 ms 768 KB Output is correct
24 Correct 368 ms 20832 KB Output is correct
25 Correct 412 ms 28104 KB Output is correct
26 Correct 335 ms 27948 KB Output is correct
27 Correct 372 ms 27980 KB Output is correct
28 Correct 428 ms 29204 KB Output is correct
29 Correct 269 ms 20824 KB Output is correct
30 Correct 762 ms 30044 KB Output is correct
31 Correct 161 ms 21588 KB Output is correct
32 Correct 115 ms 10736 KB Output is correct
33 Correct 502 ms 25308 KB Output is correct
34 Correct 664 ms 29892 KB Output is correct
35 Correct 823 ms 30284 KB Output is correct
36 Correct 679 ms 29996 KB Output is correct
37 Correct 343 ms 27836 KB Output is correct
38 Correct 363 ms 27848 KB Output is correct
39 Correct 392 ms 30268 KB Output is correct
40 Correct 564 ms 30272 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 869 ms 30020 KB Output is correct
43 Correct 522 ms 25400 KB Output is correct
44 Correct 735 ms 29740 KB Output is correct
45 Correct 767 ms 30156 KB Output is correct
46 Correct 1954 ms 124384 KB Output is correct
47 Correct 2028 ms 124180 KB Output is correct
48 Correct 2279 ms 136068 KB Output is correct
49 Correct 2974 ms 135892 KB Output is correct
50 Correct 5157 ms 135348 KB Output is correct
51 Correct 3232 ms 110384 KB Output is correct
52 Correct 3895 ms 131068 KB Output is correct
53 Correct 5074 ms 134672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 392 ms 28068 KB Output is correct
2 Correct 437 ms 28364 KB Output is correct
3 Correct 273 ms 21048 KB Output is correct
4 Correct 324 ms 21772 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 429 ms 26676 KB Output is correct
7 Correct 187 ms 9384 KB Output is correct
8 Correct 182 ms 10664 KB Output is correct
9 Correct 304 ms 20920 KB Output is correct
10 Correct 407 ms 30284 KB Output is correct
11 Correct 210 ms 20824 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 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 2 ms 384 KB Output is correct
18 Correct 3 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 3 ms 432 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 896 KB Output is correct
30 Correct 7 ms 896 KB Output is correct
31 Correct 5 ms 780 KB Output is correct
32 Correct 7 ms 896 KB Output is correct
33 Correct 6 ms 768 KB Output is correct
34 Correct 7 ms 768 KB Output is correct
35 Correct 368 ms 20832 KB Output is correct
36 Correct 412 ms 28104 KB Output is correct
37 Correct 335 ms 27948 KB Output is correct
38 Correct 372 ms 27980 KB Output is correct
39 Correct 428 ms 29204 KB Output is correct
40 Correct 269 ms 20824 KB Output is correct
41 Correct 762 ms 30044 KB Output is correct
42 Correct 161 ms 21588 KB Output is correct
43 Correct 115 ms 10736 KB Output is correct
44 Correct 502 ms 25308 KB Output is correct
45 Correct 664 ms 29892 KB Output is correct
46 Correct 823 ms 30284 KB Output is correct
47 Correct 679 ms 29996 KB Output is correct
48 Correct 343 ms 27836 KB Output is correct
49 Correct 363 ms 27848 KB Output is correct
50 Correct 392 ms 30268 KB Output is correct
51 Correct 564 ms 30272 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 869 ms 30020 KB Output is correct
54 Correct 522 ms 25400 KB Output is correct
55 Correct 735 ms 29740 KB Output is correct
56 Correct 767 ms 30156 KB Output is correct
57 Correct 375 ms 27820 KB Output is correct
58 Correct 404 ms 28364 KB Output is correct
59 Correct 675 ms 30936 KB Output is correct
60 Correct 429 ms 30664 KB Output is correct
61 Correct 604 ms 30792 KB Output is correct
62 Correct 3 ms 384 KB Output is correct
63 Correct 911 ms 30576 KB Output is correct
64 Correct 541 ms 25820 KB Output is correct
65 Correct 663 ms 30480 KB Output is correct
66 Correct 717 ms 30536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 392 ms 28068 KB Output is correct
2 Correct 437 ms 28364 KB Output is correct
3 Correct 273 ms 21048 KB Output is correct
4 Correct 324 ms 21772 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 429 ms 26676 KB Output is correct
7 Correct 187 ms 9384 KB Output is correct
8 Correct 182 ms 10664 KB Output is correct
9 Correct 304 ms 20920 KB Output is correct
10 Correct 407 ms 30284 KB Output is correct
11 Correct 210 ms 20824 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 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 2 ms 384 KB Output is correct
18 Correct 3 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 3 ms 432 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 896 KB Output is correct
30 Correct 7 ms 896 KB Output is correct
31 Correct 5 ms 780 KB Output is correct
32 Correct 7 ms 896 KB Output is correct
33 Correct 6 ms 768 KB Output is correct
34 Correct 7 ms 768 KB Output is correct
35 Correct 368 ms 20832 KB Output is correct
36 Correct 412 ms 28104 KB Output is correct
37 Correct 335 ms 27948 KB Output is correct
38 Correct 372 ms 27980 KB Output is correct
39 Correct 428 ms 29204 KB Output is correct
40 Correct 269 ms 20824 KB Output is correct
41 Correct 762 ms 30044 KB Output is correct
42 Correct 161 ms 21588 KB Output is correct
43 Correct 115 ms 10736 KB Output is correct
44 Correct 502 ms 25308 KB Output is correct
45 Correct 664 ms 29892 KB Output is correct
46 Correct 823 ms 30284 KB Output is correct
47 Correct 679 ms 29996 KB Output is correct
48 Correct 343 ms 27836 KB Output is correct
49 Correct 363 ms 27848 KB Output is correct
50 Correct 392 ms 30268 KB Output is correct
51 Correct 564 ms 30272 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 869 ms 30020 KB Output is correct
54 Correct 522 ms 25400 KB Output is correct
55 Correct 735 ms 29740 KB Output is correct
56 Correct 767 ms 30156 KB Output is correct
57 Correct 1954 ms 124384 KB Output is correct
58 Correct 2028 ms 124180 KB Output is correct
59 Correct 2279 ms 136068 KB Output is correct
60 Correct 2974 ms 135892 KB Output is correct
61 Correct 5157 ms 135348 KB Output is correct
62 Correct 3232 ms 110384 KB Output is correct
63 Correct 3895 ms 131068 KB Output is correct
64 Correct 5074 ms 134672 KB Output is correct
65 Correct 375 ms 27820 KB Output is correct
66 Correct 404 ms 28364 KB Output is correct
67 Correct 675 ms 30936 KB Output is correct
68 Correct 429 ms 30664 KB Output is correct
69 Correct 604 ms 30792 KB Output is correct
70 Correct 3 ms 384 KB Output is correct
71 Correct 911 ms 30576 KB Output is correct
72 Correct 541 ms 25820 KB Output is correct
73 Correct 663 ms 30480 KB Output is correct
74 Correct 717 ms 30536 KB Output is correct
75 Correct 1715 ms 124408 KB Output is correct
76 Correct 2045 ms 124568 KB Output is correct
77 Correct 4447 ms 136264 KB Output is correct
78 Correct 2685 ms 136288 KB Output is correct
79 Correct 5876 ms 135828 KB Output is correct
80 Correct 3222 ms 110916 KB Output is correct
81 Correct 4325 ms 131644 KB Output is correct
82 Correct 5328 ms 135808 KB Output is correct
83 Correct 5071 ms 134420 KB Output is correct