Submission #105120

# Submission time Handle Problem Language Result Execution time Memory
105120 2019-04-10T15:19:14 Z reality Two Dishes (JOI19_dishes) C++17
100 / 100
8266 ms 212512 KB
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 1e6 + 5;
ll A[N],C[N],D[N];
ll B[N],E[N],F[N];
map < pii , ll > M;
ll T[N * 4];
ll Lz[N * 4];
void llz(int l,int r,int node) {
	T[node] += Lz[node];
	if (l != r) {
		Lz[node * 2] += Lz[node];
		Lz[node * 2 + 1] += Lz[node];
	}
	Lz[node] = 0;
}
void update(int l,int r,int pos,ll val,int node) {
	llz(l,r,node);
	if (l == r)
		T[node] = val;
	else {
		int m = (l + r) / 2;
		if (pos <= m)
			update(l,m,pos,val,node * 2),llz(m+1,r,node * 2 + 1);
		else
			update(m+1,r,pos,val,node * 2 + 1),llz(l,m,node * 2);
		T[node] = max(T[node * 2],T[node * 2 + 1]);
	}
}
void Add(int l,int r,int l1,int r1,ll Val,int node) {
	llz(l,r,node);
	if (l1 <= l && r <= r1) {
		Lz[node] += Val;
		llz(l,r,node);
	} else {
		int m = (l + r) / 2;
		if (l1 <= m)
			Add(l,m,l1,r1,Val,node * 2);
		else
			llz(l,m,node * 2);
		if (m+1<=r1)
			Add(m+1,r,l1,r1,Val,node * 2 + 1);
		else
			llz(m+1,r,node * 2 + 1);
		T[node] = max(T[node * 2],T[node * 2 + 1]);
	}
}
ll query(int l,int r,int l1,int r1,int node) {
	llz(l,r,node);
	if (l1 <= l && r <= r1)
		return T[node];
	int m = (l + r) / 2;
	ll ans = -1e18;
	if (l1 <= m)
		smax(ans,query(l,m,l1,r1,node * 2));
	if (m+1<=r1)
		smax(ans,query(m+1,r,l1,r1,node * 2 + 1));
	return ans;
}
char c;
ll Get(void) {
	while (c != '-' && !('0' <= c && c <= '9'))
		c = getchar();
	int sign = c == '-' ? -1 : 1;
	ll ans = 0;
	if (c == '-')
		c = getchar();
	while ('0' <= c && c <= '9')
		ans = ans * 10 + c - '0',c = getchar();
	return ans * sign;
}
int main(void) {
    int n,m;
    c = getchar();
    n = Get();
    m = Get();
    for (int i = 1;i <= n;++i)
    	A[i] = Get(),C[i] = Get(),D[i] = Get(),A[i] += A[i - 1];
    for (int i = 1;i <= m;++i)
    	B[i] = Get(),E[i] = Get(),F[i] = Get(),B[i] += B[i - 1];
    ll bst = 0;
    for (int i = 1;i <= n;++i) {
    	if (A[i] > C[i]) {
    		continue;
    	}
    	if (A[i] + B[m] <= C[i]) {
    		bst += D[i];
    		continue;
    	}
    	int Index = lower_bound(B + 1,B + 1 + m,C[i] - A[i] + 1) - B;
    	--Index;
    	M[mp(i - 1,- 1 - Index)] += D[i];
    }
    for (int i = 1;i <= m;++i) {
    	if (B[i] > E[i]) {
    		continue;
    	}
    	if (A[n] + B[i] <= E[i]) {
    		bst += F[i];
    		continue;
    	}
    	int Index = lower_bound(A + 1,A + 1 + n,E[i] - B[i] + 1) - A;
    	--Index;
    	M[mp(Index,-i)] -= F[i];
    	bst += F[i];
    }
    for (auto It : M) {
    	const int Pos = -It.fi.se;
	    update(0,m + 1,Pos,query(0,m + 1,0,Pos,1),1);
	    Add(0,m + 1,0,Pos - 1,It.se,1);
    }
    cout << query(0,m + 1,0,m + 1,1) + bst << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 466 ms 33912 KB Output is correct
2 Correct 423 ms 32988 KB Output is correct
3 Correct 153 ms 11496 KB Output is correct
4 Correct 306 ms 24204 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 410 ms 28576 KB Output is correct
7 Correct 86 ms 5636 KB Output is correct
8 Correct 75 ms 5496 KB Output is correct
9 Correct 171 ms 10844 KB Output is correct
10 Correct 358 ms 31016 KB Output is correct
11 Correct 83 ms 10232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 3 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 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 412 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 3 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 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 412 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 7 ms 768 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 7 ms 768 KB Output is correct
23 Correct 5 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 3 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 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 412 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 7 ms 768 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 7 ms 768 KB Output is correct
23 Correct 5 ms 876 KB Output is correct
24 Correct 333 ms 23484 KB Output is correct
25 Correct 365 ms 31556 KB Output is correct
26 Correct 385 ms 31540 KB Output is correct
27 Correct 427 ms 31480 KB Output is correct
28 Correct 374 ms 25208 KB Output is correct
29 Correct 127 ms 10748 KB Output is correct
30 Correct 1175 ms 43000 KB Output is correct
31 Correct 177 ms 20116 KB Output is correct
32 Correct 95 ms 11784 KB Output is correct
33 Correct 659 ms 30992 KB Output is correct
34 Correct 1018 ms 38436 KB Output is correct
35 Correct 1181 ms 43128 KB Output is correct
36 Correct 1091 ms 42200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 3 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 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 412 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 7 ms 768 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 7 ms 768 KB Output is correct
23 Correct 5 ms 876 KB Output is correct
24 Correct 333 ms 23484 KB Output is correct
25 Correct 365 ms 31556 KB Output is correct
26 Correct 385 ms 31540 KB Output is correct
27 Correct 427 ms 31480 KB Output is correct
28 Correct 374 ms 25208 KB Output is correct
29 Correct 127 ms 10748 KB Output is correct
30 Correct 1175 ms 43000 KB Output is correct
31 Correct 177 ms 20116 KB Output is correct
32 Correct 95 ms 11784 KB Output is correct
33 Correct 659 ms 30992 KB Output is correct
34 Correct 1018 ms 38436 KB Output is correct
35 Correct 1181 ms 43128 KB Output is correct
36 Correct 1091 ms 42200 KB Output is correct
37 Correct 367 ms 31480 KB Output is correct
38 Correct 382 ms 31656 KB Output is correct
39 Correct 407 ms 31560 KB Output is correct
40 Correct 399 ms 31608 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1197 ms 43220 KB Output is correct
43 Correct 599 ms 30624 KB Output is correct
44 Correct 930 ms 37628 KB Output is correct
45 Correct 1097 ms 43112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 3 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 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 412 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 7 ms 768 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 7 ms 768 KB Output is correct
23 Correct 5 ms 876 KB Output is correct
24 Correct 333 ms 23484 KB Output is correct
25 Correct 365 ms 31556 KB Output is correct
26 Correct 385 ms 31540 KB Output is correct
27 Correct 427 ms 31480 KB Output is correct
28 Correct 374 ms 25208 KB Output is correct
29 Correct 127 ms 10748 KB Output is correct
30 Correct 1175 ms 43000 KB Output is correct
31 Correct 177 ms 20116 KB Output is correct
32 Correct 95 ms 11784 KB Output is correct
33 Correct 659 ms 30992 KB Output is correct
34 Correct 1018 ms 38436 KB Output is correct
35 Correct 1181 ms 43128 KB Output is correct
36 Correct 1091 ms 42200 KB Output is correct
37 Correct 367 ms 31480 KB Output is correct
38 Correct 382 ms 31656 KB Output is correct
39 Correct 407 ms 31560 KB Output is correct
40 Correct 399 ms 31608 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1197 ms 43220 KB Output is correct
43 Correct 599 ms 30624 KB Output is correct
44 Correct 930 ms 37628 KB Output is correct
45 Correct 1097 ms 43112 KB Output is correct
46 Correct 2104 ms 142820 KB Output is correct
47 Correct 1939 ms 142948 KB Output is correct
48 Correct 2241 ms 142744 KB Output is correct
49 Correct 2168 ms 142812 KB Output is correct
50 Correct 8223 ms 202968 KB Output is correct
51 Correct 3888 ms 144920 KB Output is correct
52 Correct 5681 ms 171204 KB Output is correct
53 Correct 7431 ms 202340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 466 ms 33912 KB Output is correct
2 Correct 423 ms 32988 KB Output is correct
3 Correct 153 ms 11496 KB Output is correct
4 Correct 306 ms 24204 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 410 ms 28576 KB Output is correct
7 Correct 86 ms 5636 KB Output is correct
8 Correct 75 ms 5496 KB Output is correct
9 Correct 171 ms 10844 KB Output is correct
10 Correct 358 ms 31016 KB Output is correct
11 Correct 83 ms 10232 KB Output is correct
12 Correct 3 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 3 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 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 3 ms 412 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 5 ms 640 KB Output is correct
29 Correct 6 ms 768 KB Output is correct
30 Correct 7 ms 768 KB Output is correct
31 Correct 5 ms 640 KB Output is correct
32 Correct 7 ms 768 KB Output is correct
33 Correct 7 ms 768 KB Output is correct
34 Correct 5 ms 876 KB Output is correct
35 Correct 333 ms 23484 KB Output is correct
36 Correct 365 ms 31556 KB Output is correct
37 Correct 385 ms 31540 KB Output is correct
38 Correct 427 ms 31480 KB Output is correct
39 Correct 374 ms 25208 KB Output is correct
40 Correct 127 ms 10748 KB Output is correct
41 Correct 1175 ms 43000 KB Output is correct
42 Correct 177 ms 20116 KB Output is correct
43 Correct 95 ms 11784 KB Output is correct
44 Correct 659 ms 30992 KB Output is correct
45 Correct 1018 ms 38436 KB Output is correct
46 Correct 1181 ms 43128 KB Output is correct
47 Correct 1091 ms 42200 KB Output is correct
48 Correct 367 ms 31480 KB Output is correct
49 Correct 382 ms 31656 KB Output is correct
50 Correct 407 ms 31560 KB Output is correct
51 Correct 399 ms 31608 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1197 ms 43220 KB Output is correct
54 Correct 599 ms 30624 KB Output is correct
55 Correct 930 ms 37628 KB Output is correct
56 Correct 1097 ms 43112 KB Output is correct
57 Correct 427 ms 30784 KB Output is correct
58 Correct 343 ms 30744 KB Output is correct
59 Correct 415 ms 30772 KB Output is correct
60 Correct 442 ms 30688 KB Output is correct
61 Correct 1145 ms 43304 KB Output is correct
62 Correct 3 ms 384 KB Output is correct
63 Correct 1158 ms 42396 KB Output is correct
64 Correct 665 ms 30092 KB Output is correct
65 Correct 924 ms 37136 KB Output is correct
66 Correct 1043 ms 41848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 466 ms 33912 KB Output is correct
2 Correct 423 ms 32988 KB Output is correct
3 Correct 153 ms 11496 KB Output is correct
4 Correct 306 ms 24204 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 410 ms 28576 KB Output is correct
7 Correct 86 ms 5636 KB Output is correct
8 Correct 75 ms 5496 KB Output is correct
9 Correct 171 ms 10844 KB Output is correct
10 Correct 358 ms 31016 KB Output is correct
11 Correct 83 ms 10232 KB Output is correct
12 Correct 3 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 3 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 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 3 ms 412 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 5 ms 640 KB Output is correct
29 Correct 6 ms 768 KB Output is correct
30 Correct 7 ms 768 KB Output is correct
31 Correct 5 ms 640 KB Output is correct
32 Correct 7 ms 768 KB Output is correct
33 Correct 7 ms 768 KB Output is correct
34 Correct 5 ms 876 KB Output is correct
35 Correct 333 ms 23484 KB Output is correct
36 Correct 365 ms 31556 KB Output is correct
37 Correct 385 ms 31540 KB Output is correct
38 Correct 427 ms 31480 KB Output is correct
39 Correct 374 ms 25208 KB Output is correct
40 Correct 127 ms 10748 KB Output is correct
41 Correct 1175 ms 43000 KB Output is correct
42 Correct 177 ms 20116 KB Output is correct
43 Correct 95 ms 11784 KB Output is correct
44 Correct 659 ms 30992 KB Output is correct
45 Correct 1018 ms 38436 KB Output is correct
46 Correct 1181 ms 43128 KB Output is correct
47 Correct 1091 ms 42200 KB Output is correct
48 Correct 367 ms 31480 KB Output is correct
49 Correct 382 ms 31656 KB Output is correct
50 Correct 407 ms 31560 KB Output is correct
51 Correct 399 ms 31608 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1197 ms 43220 KB Output is correct
54 Correct 599 ms 30624 KB Output is correct
55 Correct 930 ms 37628 KB Output is correct
56 Correct 1097 ms 43112 KB Output is correct
57 Correct 2104 ms 142820 KB Output is correct
58 Correct 1939 ms 142948 KB Output is correct
59 Correct 2241 ms 142744 KB Output is correct
60 Correct 2168 ms 142812 KB Output is correct
61 Correct 8223 ms 202968 KB Output is correct
62 Correct 3888 ms 144920 KB Output is correct
63 Correct 5681 ms 171204 KB Output is correct
64 Correct 7431 ms 202340 KB Output is correct
65 Correct 427 ms 30784 KB Output is correct
66 Correct 343 ms 30744 KB Output is correct
67 Correct 415 ms 30772 KB Output is correct
68 Correct 442 ms 30688 KB Output is correct
69 Correct 1145 ms 43304 KB Output is correct
70 Correct 3 ms 384 KB Output is correct
71 Correct 1158 ms 42396 KB Output is correct
72 Correct 665 ms 30092 KB Output is correct
73 Correct 924 ms 37136 KB Output is correct
74 Correct 1043 ms 41848 KB Output is correct
75 Correct 2033 ms 152024 KB Output is correct
76 Correct 2248 ms 152196 KB Output is correct
77 Correct 2190 ms 150884 KB Output is correct
78 Correct 2351 ms 150848 KB Output is correct
79 Correct 8266 ms 212512 KB Output is correct
80 Correct 4030 ms 145956 KB Output is correct
81 Correct 5560 ms 167976 KB Output is correct
82 Correct 7903 ms 206932 KB Output is correct
83 Correct 7511 ms 196552 KB Output is correct