Submission #123513

# Submission time Handle Problem Language Result Execution time Memory
123513 2019-07-01T14:13:04 Z sebinkim Two Dishes (JOI19_dishes) C++14
74 / 100
3304 ms 161020 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct fenwick{
	ll T[1010101];
	ll m;
	
	void init(ll _m) { m = _m; }
	
	void addval(ll p, ll v)
	{
		if(!p) T[0] += v;
		else{
			for(; p<=m; p+=p&-p){
				T[p] += v;
			}
		}
	}
	
	ll getval(ll p)
	{
		ll ret = T[0];
		
		for(; p; p-=p&-p){
			ret += T[p];
		}
		
		return ret;
	}
};

ll A[1010101], S[1010101], P[1010101];
ll B[1010101], T[1010101], Q[1010101];
vector <ll> V[1010101];
set <ll> X;
fenwick F;
ll n, m, ans;

void query(ll f, ll p, ll k)
{
	ll x;
	
	if(f == 0) F.addval(0, k);
	else if(f == 1){
		if(X.find(p) == X.end()) X.insert(p);
		F.addval(p, k);
		return;
	}
	else if(f == 2){
		if(X.find(p) == X.end()) X.insert(p);
		F.addval(p, k);
	}
	
	for(; ; ){
		auto it = X.upper_bound(p);
		if(it == X.end()) break;
		
		x = F.getval(*it) - F.getval(*it - 1) - Q[*it];
		
		if(x <= k){
			F.addval(*it, -x); k -= x;
			X.erase(it);
		}
		else{
			F.addval(*it, -k);
			break;
		}
	}
}

int main()
{
	ll i, k, x;
	
	scanf("%lld%lld", &n, &m);
	
	for(i=1; i<=n; i++){
		scanf("%lld%lld%lld", A + i, S + i, P + i);
		A[i] += A[i - 1];
	}
	
	for(i=1; i<=m; i++){
		scanf("%lld%lld%lld", B + i, T + i, Q + i);
		B[i] += B[i - 1];
	}	
	
	for(i=1; i<=n; i++){
		S[i] = upper_bound(B, B + m + 1, S[i] - A[i]) - B;
	}
	
	for(i=1; i<=m; i++){
		T[i] = upper_bound(A, A + n + 1, T[i] - B[i]) - A;
		V[T[i]].push_back(i);
	}
	
	F.init(m);
	
	for(i=1; i<=m; i++){
		if(T[i] == 0) Q[i] = 0;
		F.addval(i, Q[i]);
	}
	
	for(i=1; i<=n; i++){
		for(ll &t: V[i]){
			if(Q[t] >= 0){
				Q[t] = 0;
				if(X.find(t) == X.end()) X.insert(t);
			}
			else{
				Q[t] = 0;
				x = F.getval(t) - F.getval(t - 1);
				if(x <= 0){
					if(X.find(t) != X.end()) X.erase(t);
					query(2, t, - x);
				}
			}
		}
		
		if(S[i] == 0) continue;
		else if(S[i] > m) F.addval(0, P[i]);
		else{
			if(X.find(S[i]) == X.end()) X.insert(S[i]);
			query(0, S[i] - 1, P[i]);
		}
	}
	
	printf("%lld\n", F.getval(m) + ans);
	
	return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:76:8: warning: unused variable 'k' [-Wunused-variable]
  ll i, k, x;
        ^
dishes.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
dishes.cpp:81: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:86: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 344 ms 48496 KB Output is correct
2 Correct 306 ms 39952 KB Output is correct
3 Correct 253 ms 44900 KB Output is correct
4 Correct 363 ms 53488 KB Output is correct
5 Correct 22 ms 24056 KB Output is correct
6 Correct 316 ms 47188 KB Output is correct
7 Correct 139 ms 37824 KB Output is correct
8 Correct 135 ms 34376 KB Output is correct
9 Correct 266 ms 46744 KB Output is correct
10 Correct 264 ms 47096 KB Output is correct
11 Correct 188 ms 42348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24184 KB Output is correct
2 Correct 23 ms 24056 KB Output is correct
3 Correct 23 ms 24056 KB Output is correct
4 Correct 25 ms 24136 KB Output is correct
5 Correct 24 ms 24184 KB Output is correct
6 Correct 28 ms 24060 KB Output is correct
7 Correct 28 ms 24056 KB Output is correct
8 Correct 22 ms 24056 KB Output is correct
9 Correct 23 ms 24056 KB Output is correct
10 Correct 23 ms 24056 KB Output is correct
11 Correct 23 ms 24056 KB Output is correct
12 Correct 23 ms 24056 KB Output is correct
13 Correct 23 ms 24056 KB Output is correct
14 Correct 23 ms 24056 KB Output is correct
15 Correct 23 ms 24184 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24184 KB Output is correct
2 Correct 23 ms 24056 KB Output is correct
3 Correct 23 ms 24056 KB Output is correct
4 Correct 25 ms 24136 KB Output is correct
5 Correct 24 ms 24184 KB Output is correct
6 Correct 28 ms 24060 KB Output is correct
7 Correct 28 ms 24056 KB Output is correct
8 Correct 22 ms 24056 KB Output is correct
9 Correct 23 ms 24056 KB Output is correct
10 Correct 23 ms 24056 KB Output is correct
11 Correct 23 ms 24056 KB Output is correct
12 Correct 23 ms 24056 KB Output is correct
13 Correct 23 ms 24056 KB Output is correct
14 Correct 23 ms 24056 KB Output is correct
15 Correct 23 ms 24184 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 25 ms 24312 KB Output is correct
18 Correct 26 ms 24340 KB Output is correct
19 Correct 32 ms 24488 KB Output is correct
20 Correct 26 ms 24312 KB Output is correct
21 Correct 32 ms 24360 KB Output is correct
22 Correct 26 ms 24312 KB Output is correct
23 Correct 26 ms 24312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24184 KB Output is correct
2 Correct 23 ms 24056 KB Output is correct
3 Correct 23 ms 24056 KB Output is correct
4 Correct 25 ms 24136 KB Output is correct
5 Correct 24 ms 24184 KB Output is correct
6 Correct 28 ms 24060 KB Output is correct
7 Correct 28 ms 24056 KB Output is correct
8 Correct 22 ms 24056 KB Output is correct
9 Correct 23 ms 24056 KB Output is correct
10 Correct 23 ms 24056 KB Output is correct
11 Correct 23 ms 24056 KB Output is correct
12 Correct 23 ms 24056 KB Output is correct
13 Correct 23 ms 24056 KB Output is correct
14 Correct 23 ms 24056 KB Output is correct
15 Correct 23 ms 24184 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 25 ms 24312 KB Output is correct
18 Correct 26 ms 24340 KB Output is correct
19 Correct 32 ms 24488 KB Output is correct
20 Correct 26 ms 24312 KB Output is correct
21 Correct 32 ms 24360 KB Output is correct
22 Correct 26 ms 24312 KB Output is correct
23 Correct 26 ms 24312 KB Output is correct
24 Correct 267 ms 43176 KB Output is correct
25 Correct 328 ms 53072 KB Output is correct
26 Correct 262 ms 44404 KB Output is correct
27 Correct 353 ms 58348 KB Output is correct
28 Correct 328 ms 45544 KB Output is correct
29 Correct 216 ms 44772 KB Output is correct
30 Correct 524 ms 47548 KB Output is correct
31 Correct 169 ms 41872 KB Output is correct
32 Correct 124 ms 34040 KB Output is correct
33 Correct 385 ms 45776 KB Output is correct
34 Correct 454 ms 49560 KB Output is correct
35 Correct 458 ms 43752 KB Output is correct
36 Correct 445 ms 43640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24184 KB Output is correct
2 Correct 23 ms 24056 KB Output is correct
3 Correct 23 ms 24056 KB Output is correct
4 Correct 25 ms 24136 KB Output is correct
5 Correct 24 ms 24184 KB Output is correct
6 Correct 28 ms 24060 KB Output is correct
7 Correct 28 ms 24056 KB Output is correct
8 Correct 22 ms 24056 KB Output is correct
9 Correct 23 ms 24056 KB Output is correct
10 Correct 23 ms 24056 KB Output is correct
11 Correct 23 ms 24056 KB Output is correct
12 Correct 23 ms 24056 KB Output is correct
13 Correct 23 ms 24056 KB Output is correct
14 Correct 23 ms 24056 KB Output is correct
15 Correct 23 ms 24184 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 25 ms 24312 KB Output is correct
18 Correct 26 ms 24340 KB Output is correct
19 Correct 32 ms 24488 KB Output is correct
20 Correct 26 ms 24312 KB Output is correct
21 Correct 32 ms 24360 KB Output is correct
22 Correct 26 ms 24312 KB Output is correct
23 Correct 26 ms 24312 KB Output is correct
24 Correct 267 ms 43176 KB Output is correct
25 Correct 328 ms 53072 KB Output is correct
26 Correct 262 ms 44404 KB Output is correct
27 Correct 353 ms 58348 KB Output is correct
28 Correct 328 ms 45544 KB Output is correct
29 Correct 216 ms 44772 KB Output is correct
30 Correct 524 ms 47548 KB Output is correct
31 Correct 169 ms 41872 KB Output is correct
32 Correct 124 ms 34040 KB Output is correct
33 Correct 385 ms 45776 KB Output is correct
34 Correct 454 ms 49560 KB Output is correct
35 Correct 458 ms 43752 KB Output is correct
36 Correct 445 ms 43640 KB Output is correct
37 Correct 307 ms 46780 KB Output is correct
38 Correct 399 ms 60792 KB Output is correct
39 Correct 465 ms 59896 KB Output is correct
40 Correct 281 ms 50424 KB Output is correct
41 Correct 23 ms 24056 KB Output is correct
42 Correct 582 ms 50248 KB Output is correct
43 Correct 422 ms 49276 KB Output is correct
44 Correct 495 ms 52520 KB Output is correct
45 Correct 502 ms 45048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24184 KB Output is correct
2 Correct 23 ms 24056 KB Output is correct
3 Correct 23 ms 24056 KB Output is correct
4 Correct 25 ms 24136 KB Output is correct
5 Correct 24 ms 24184 KB Output is correct
6 Correct 28 ms 24060 KB Output is correct
7 Correct 28 ms 24056 KB Output is correct
8 Correct 22 ms 24056 KB Output is correct
9 Correct 23 ms 24056 KB Output is correct
10 Correct 23 ms 24056 KB Output is correct
11 Correct 23 ms 24056 KB Output is correct
12 Correct 23 ms 24056 KB Output is correct
13 Correct 23 ms 24056 KB Output is correct
14 Correct 23 ms 24056 KB Output is correct
15 Correct 23 ms 24184 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 25 ms 24312 KB Output is correct
18 Correct 26 ms 24340 KB Output is correct
19 Correct 32 ms 24488 KB Output is correct
20 Correct 26 ms 24312 KB Output is correct
21 Correct 32 ms 24360 KB Output is correct
22 Correct 26 ms 24312 KB Output is correct
23 Correct 26 ms 24312 KB Output is correct
24 Correct 267 ms 43176 KB Output is correct
25 Correct 328 ms 53072 KB Output is correct
26 Correct 262 ms 44404 KB Output is correct
27 Correct 353 ms 58348 KB Output is correct
28 Correct 328 ms 45544 KB Output is correct
29 Correct 216 ms 44772 KB Output is correct
30 Correct 524 ms 47548 KB Output is correct
31 Correct 169 ms 41872 KB Output is correct
32 Correct 124 ms 34040 KB Output is correct
33 Correct 385 ms 45776 KB Output is correct
34 Correct 454 ms 49560 KB Output is correct
35 Correct 458 ms 43752 KB Output is correct
36 Correct 445 ms 43640 KB Output is correct
37 Correct 307 ms 46780 KB Output is correct
38 Correct 399 ms 60792 KB Output is correct
39 Correct 465 ms 59896 KB Output is correct
40 Correct 281 ms 50424 KB Output is correct
41 Correct 23 ms 24056 KB Output is correct
42 Correct 582 ms 50248 KB Output is correct
43 Correct 422 ms 49276 KB Output is correct
44 Correct 495 ms 52520 KB Output is correct
45 Correct 502 ms 45048 KB Output is correct
46 Correct 1453 ms 92324 KB Output is correct
47 Correct 2003 ms 161020 KB Output is correct
48 Correct 2536 ms 160492 KB Output is correct
49 Correct 1326 ms 113524 KB Output is correct
50 Correct 3304 ms 103800 KB Output is correct
51 Correct 2228 ms 96932 KB Output is correct
52 Correct 2781 ms 113356 KB Output is correct
53 Correct 2869 ms 111112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 344 ms 48496 KB Output is correct
2 Correct 306 ms 39952 KB Output is correct
3 Correct 253 ms 44900 KB Output is correct
4 Correct 363 ms 53488 KB Output is correct
5 Correct 22 ms 24056 KB Output is correct
6 Correct 316 ms 47188 KB Output is correct
7 Correct 139 ms 37824 KB Output is correct
8 Correct 135 ms 34376 KB Output is correct
9 Correct 266 ms 46744 KB Output is correct
10 Correct 264 ms 47096 KB Output is correct
11 Correct 188 ms 42348 KB Output is correct
12 Correct 23 ms 24184 KB Output is correct
13 Correct 23 ms 24056 KB Output is correct
14 Correct 23 ms 24056 KB Output is correct
15 Correct 25 ms 24136 KB Output is correct
16 Correct 24 ms 24184 KB Output is correct
17 Correct 28 ms 24060 KB Output is correct
18 Correct 28 ms 24056 KB Output is correct
19 Correct 22 ms 24056 KB Output is correct
20 Correct 23 ms 24056 KB Output is correct
21 Correct 23 ms 24056 KB Output is correct
22 Correct 23 ms 24056 KB Output is correct
23 Correct 23 ms 24056 KB Output is correct
24 Correct 23 ms 24056 KB Output is correct
25 Correct 23 ms 24056 KB Output is correct
26 Correct 23 ms 24184 KB Output is correct
27 Correct 23 ms 24056 KB Output is correct
28 Correct 25 ms 24312 KB Output is correct
29 Correct 26 ms 24340 KB Output is correct
30 Correct 32 ms 24488 KB Output is correct
31 Correct 26 ms 24312 KB Output is correct
32 Correct 32 ms 24360 KB Output is correct
33 Correct 26 ms 24312 KB Output is correct
34 Correct 26 ms 24312 KB Output is correct
35 Correct 267 ms 43176 KB Output is correct
36 Correct 328 ms 53072 KB Output is correct
37 Correct 262 ms 44404 KB Output is correct
38 Correct 353 ms 58348 KB Output is correct
39 Correct 328 ms 45544 KB Output is correct
40 Correct 216 ms 44772 KB Output is correct
41 Correct 524 ms 47548 KB Output is correct
42 Correct 169 ms 41872 KB Output is correct
43 Correct 124 ms 34040 KB Output is correct
44 Correct 385 ms 45776 KB Output is correct
45 Correct 454 ms 49560 KB Output is correct
46 Correct 458 ms 43752 KB Output is correct
47 Correct 445 ms 43640 KB Output is correct
48 Correct 307 ms 46780 KB Output is correct
49 Correct 399 ms 60792 KB Output is correct
50 Correct 465 ms 59896 KB Output is correct
51 Correct 281 ms 50424 KB Output is correct
52 Correct 23 ms 24056 KB Output is correct
53 Correct 582 ms 50248 KB Output is correct
54 Correct 422 ms 49276 KB Output is correct
55 Correct 495 ms 52520 KB Output is correct
56 Correct 502 ms 45048 KB Output is correct
57 Correct 425 ms 57024 KB Output is correct
58 Correct 459 ms 62368 KB Output is correct
59 Incorrect 302 ms 52080 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 344 ms 48496 KB Output is correct
2 Correct 306 ms 39952 KB Output is correct
3 Correct 253 ms 44900 KB Output is correct
4 Correct 363 ms 53488 KB Output is correct
5 Correct 22 ms 24056 KB Output is correct
6 Correct 316 ms 47188 KB Output is correct
7 Correct 139 ms 37824 KB Output is correct
8 Correct 135 ms 34376 KB Output is correct
9 Correct 266 ms 46744 KB Output is correct
10 Correct 264 ms 47096 KB Output is correct
11 Correct 188 ms 42348 KB Output is correct
12 Correct 23 ms 24184 KB Output is correct
13 Correct 23 ms 24056 KB Output is correct
14 Correct 23 ms 24056 KB Output is correct
15 Correct 25 ms 24136 KB Output is correct
16 Correct 24 ms 24184 KB Output is correct
17 Correct 28 ms 24060 KB Output is correct
18 Correct 28 ms 24056 KB Output is correct
19 Correct 22 ms 24056 KB Output is correct
20 Correct 23 ms 24056 KB Output is correct
21 Correct 23 ms 24056 KB Output is correct
22 Correct 23 ms 24056 KB Output is correct
23 Correct 23 ms 24056 KB Output is correct
24 Correct 23 ms 24056 KB Output is correct
25 Correct 23 ms 24056 KB Output is correct
26 Correct 23 ms 24184 KB Output is correct
27 Correct 23 ms 24056 KB Output is correct
28 Correct 25 ms 24312 KB Output is correct
29 Correct 26 ms 24340 KB Output is correct
30 Correct 32 ms 24488 KB Output is correct
31 Correct 26 ms 24312 KB Output is correct
32 Correct 32 ms 24360 KB Output is correct
33 Correct 26 ms 24312 KB Output is correct
34 Correct 26 ms 24312 KB Output is correct
35 Correct 267 ms 43176 KB Output is correct
36 Correct 328 ms 53072 KB Output is correct
37 Correct 262 ms 44404 KB Output is correct
38 Correct 353 ms 58348 KB Output is correct
39 Correct 328 ms 45544 KB Output is correct
40 Correct 216 ms 44772 KB Output is correct
41 Correct 524 ms 47548 KB Output is correct
42 Correct 169 ms 41872 KB Output is correct
43 Correct 124 ms 34040 KB Output is correct
44 Correct 385 ms 45776 KB Output is correct
45 Correct 454 ms 49560 KB Output is correct
46 Correct 458 ms 43752 KB Output is correct
47 Correct 445 ms 43640 KB Output is correct
48 Correct 307 ms 46780 KB Output is correct
49 Correct 399 ms 60792 KB Output is correct
50 Correct 465 ms 59896 KB Output is correct
51 Correct 281 ms 50424 KB Output is correct
52 Correct 23 ms 24056 KB Output is correct
53 Correct 582 ms 50248 KB Output is correct
54 Correct 422 ms 49276 KB Output is correct
55 Correct 495 ms 52520 KB Output is correct
56 Correct 502 ms 45048 KB Output is correct
57 Correct 1453 ms 92324 KB Output is correct
58 Correct 2003 ms 161020 KB Output is correct
59 Correct 2536 ms 160492 KB Output is correct
60 Correct 1326 ms 113524 KB Output is correct
61 Correct 3304 ms 103800 KB Output is correct
62 Correct 2228 ms 96932 KB Output is correct
63 Correct 2781 ms 113356 KB Output is correct
64 Correct 2869 ms 111112 KB Output is correct
65 Correct 425 ms 57024 KB Output is correct
66 Correct 459 ms 62368 KB Output is correct
67 Incorrect 302 ms 52080 KB Output isn't correct
68 Halted 0 ms 0 KB -