답안 #123474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123474 2019-07-01T13:45:09 Z sebinkim Two Dishes (JOI19_dishes) C++14
74 / 100
2939 ms 167952 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], P1[1010101], P2[1010101];
ll B[1010101], T[1010101], Q1[1010101], Q2[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) - Q1[*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, P1 + i);
		A[i] += A[i - 1];
		if(P1[i] < 0){
			ans += P1[i];
			P2[i] = -P1[i], P1[i] = 0;
		}
	}
	
	for(i=1; i<=m; i++){
		scanf("%lld%lld%lld", B + i, T + i, Q1 + i);
		B[i] += B[i - 1];
		if(Q1[i] < 0){
			ans += Q1[i];
			Q2[i] = -Q1[i], Q1[i] = 0;
		}
	}	
	
	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) swap(Q1[i], Q2[i]);
		F.addval(i, Q1[i]);
	}
	
	for(i=1; i<=n; i++){
		for(ll &t: V[i]){
			swap(Q1[t], Q2[t]);
			
			if(Q1[t] == 0){
				if(X.find(t) == X.end()) X.insert(t);
			}
/*			else{
				x = F.getval(t) - F.getval(t - 1);
				if(x <= Q1[t]){
					if(X.find(t) != X.end()) X.erase(t);
					query(2, t, Q1[t] - x);
				}
			}
*/		}
		
		if(S[i] == 0) F.addval(0, P2[i]);
		else if(S[i] > m) F.addval(0, P1[i]);
		else{
			query(0, S[i] - 1, P1[i]);
//			query(1, S[i], P2[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:76:11: warning: unused variable 'x' [-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, P1 + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:90: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, Q1 + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 340 ms 58824 KB Output is correct
2 Correct 312 ms 49868 KB Output is correct
3 Correct 255 ms 46328 KB Output is correct
4 Correct 347 ms 56432 KB Output is correct
5 Correct 23 ms 24056 KB Output is correct
6 Correct 313 ms 48220 KB Output is correct
7 Correct 139 ms 38196 KB Output is correct
8 Correct 135 ms 34808 KB Output is correct
9 Correct 270 ms 45924 KB Output is correct
10 Correct 265 ms 49528 KB Output is correct
11 Correct 189 ms 43492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24184 KB Output is correct
2 Correct 23 ms 24184 KB Output is correct
3 Correct 24 ms 24184 KB Output is correct
4 Correct 26 ms 24184 KB Output is correct
5 Correct 28 ms 24184 KB Output is correct
6 Correct 23 ms 24152 KB Output is correct
7 Correct 22 ms 24056 KB Output is correct
8 Correct 23 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 24 ms 24184 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 24184 KB Output is correct
15 Correct 23 ms 24056 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24184 KB Output is correct
2 Correct 23 ms 24184 KB Output is correct
3 Correct 24 ms 24184 KB Output is correct
4 Correct 26 ms 24184 KB Output is correct
5 Correct 28 ms 24184 KB Output is correct
6 Correct 23 ms 24152 KB Output is correct
7 Correct 22 ms 24056 KB Output is correct
8 Correct 23 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 24 ms 24184 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 24184 KB Output is correct
15 Correct 23 ms 24056 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 26 ms 24312 KB Output is correct
18 Correct 26 ms 24440 KB Output is correct
19 Correct 30 ms 24316 KB Output is correct
20 Correct 32 ms 24312 KB Output is correct
21 Correct 26 ms 24440 KB Output is correct
22 Correct 30 ms 24312 KB Output is correct
23 Correct 34 ms 24312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24184 KB Output is correct
2 Correct 23 ms 24184 KB Output is correct
3 Correct 24 ms 24184 KB Output is correct
4 Correct 26 ms 24184 KB Output is correct
5 Correct 28 ms 24184 KB Output is correct
6 Correct 23 ms 24152 KB Output is correct
7 Correct 22 ms 24056 KB Output is correct
8 Correct 23 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 24 ms 24184 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 24184 KB Output is correct
15 Correct 23 ms 24056 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 26 ms 24312 KB Output is correct
18 Correct 26 ms 24440 KB Output is correct
19 Correct 30 ms 24316 KB Output is correct
20 Correct 32 ms 24312 KB Output is correct
21 Correct 26 ms 24440 KB Output is correct
22 Correct 30 ms 24312 KB Output is correct
23 Correct 34 ms 24312 KB Output is correct
24 Correct 239 ms 47104 KB Output is correct
25 Correct 343 ms 55632 KB Output is correct
26 Correct 250 ms 45824 KB Output is correct
27 Correct 354 ms 59876 KB Output is correct
28 Correct 308 ms 46824 KB Output is correct
29 Correct 219 ms 44672 KB Output is correct
30 Correct 468 ms 48220 KB Output is correct
31 Correct 170 ms 42512 KB Output is correct
32 Correct 120 ms 33156 KB Output is correct
33 Correct 357 ms 47480 KB Output is correct
34 Correct 421 ms 50928 KB Output is correct
35 Correct 398 ms 44664 KB Output is correct
36 Correct 401 ms 44536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24184 KB Output is correct
2 Correct 23 ms 24184 KB Output is correct
3 Correct 24 ms 24184 KB Output is correct
4 Correct 26 ms 24184 KB Output is correct
5 Correct 28 ms 24184 KB Output is correct
6 Correct 23 ms 24152 KB Output is correct
7 Correct 22 ms 24056 KB Output is correct
8 Correct 23 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 24 ms 24184 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 24184 KB Output is correct
15 Correct 23 ms 24056 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 26 ms 24312 KB Output is correct
18 Correct 26 ms 24440 KB Output is correct
19 Correct 30 ms 24316 KB Output is correct
20 Correct 32 ms 24312 KB Output is correct
21 Correct 26 ms 24440 KB Output is correct
22 Correct 30 ms 24312 KB Output is correct
23 Correct 34 ms 24312 KB Output is correct
24 Correct 239 ms 47104 KB Output is correct
25 Correct 343 ms 55632 KB Output is correct
26 Correct 250 ms 45824 KB Output is correct
27 Correct 354 ms 59876 KB Output is correct
28 Correct 308 ms 46824 KB Output is correct
29 Correct 219 ms 44672 KB Output is correct
30 Correct 468 ms 48220 KB Output is correct
31 Correct 170 ms 42512 KB Output is correct
32 Correct 120 ms 33156 KB Output is correct
33 Correct 357 ms 47480 KB Output is correct
34 Correct 421 ms 50928 KB Output is correct
35 Correct 398 ms 44664 KB Output is correct
36 Correct 401 ms 44536 KB Output is correct
37 Correct 292 ms 45664 KB Output is correct
38 Correct 397 ms 59256 KB Output is correct
39 Correct 447 ms 58948 KB Output is correct
40 Correct 285 ms 49392 KB Output is correct
41 Correct 28 ms 24056 KB Output is correct
42 Correct 515 ms 46676 KB Output is correct
43 Correct 395 ms 45108 KB Output is correct
44 Correct 468 ms 48640 KB Output is correct
45 Correct 433 ms 46864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24184 KB Output is correct
2 Correct 23 ms 24184 KB Output is correct
3 Correct 24 ms 24184 KB Output is correct
4 Correct 26 ms 24184 KB Output is correct
5 Correct 28 ms 24184 KB Output is correct
6 Correct 23 ms 24152 KB Output is correct
7 Correct 22 ms 24056 KB Output is correct
8 Correct 23 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 24 ms 24184 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 24184 KB Output is correct
15 Correct 23 ms 24056 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 26 ms 24312 KB Output is correct
18 Correct 26 ms 24440 KB Output is correct
19 Correct 30 ms 24316 KB Output is correct
20 Correct 32 ms 24312 KB Output is correct
21 Correct 26 ms 24440 KB Output is correct
22 Correct 30 ms 24312 KB Output is correct
23 Correct 34 ms 24312 KB Output is correct
24 Correct 239 ms 47104 KB Output is correct
25 Correct 343 ms 55632 KB Output is correct
26 Correct 250 ms 45824 KB Output is correct
27 Correct 354 ms 59876 KB Output is correct
28 Correct 308 ms 46824 KB Output is correct
29 Correct 219 ms 44672 KB Output is correct
30 Correct 468 ms 48220 KB Output is correct
31 Correct 170 ms 42512 KB Output is correct
32 Correct 120 ms 33156 KB Output is correct
33 Correct 357 ms 47480 KB Output is correct
34 Correct 421 ms 50928 KB Output is correct
35 Correct 398 ms 44664 KB Output is correct
36 Correct 401 ms 44536 KB Output is correct
37 Correct 292 ms 45664 KB Output is correct
38 Correct 397 ms 59256 KB Output is correct
39 Correct 447 ms 58948 KB Output is correct
40 Correct 285 ms 49392 KB Output is correct
41 Correct 28 ms 24056 KB Output is correct
42 Correct 515 ms 46676 KB Output is correct
43 Correct 395 ms 45108 KB Output is correct
44 Correct 468 ms 48640 KB Output is correct
45 Correct 433 ms 46864 KB Output is correct
46 Correct 1367 ms 98492 KB Output is correct
47 Correct 2017 ms 167952 KB Output is correct
48 Correct 2292 ms 167748 KB Output is correct
49 Correct 1347 ms 120864 KB Output is correct
50 Correct 2939 ms 111028 KB Output is correct
51 Correct 2052 ms 104284 KB Output is correct
52 Correct 2533 ms 119784 KB Output is correct
53 Correct 2516 ms 114056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 340 ms 58824 KB Output is correct
2 Correct 312 ms 49868 KB Output is correct
3 Correct 255 ms 46328 KB Output is correct
4 Correct 347 ms 56432 KB Output is correct
5 Correct 23 ms 24056 KB Output is correct
6 Correct 313 ms 48220 KB Output is correct
7 Correct 139 ms 38196 KB Output is correct
8 Correct 135 ms 34808 KB Output is correct
9 Correct 270 ms 45924 KB Output is correct
10 Correct 265 ms 49528 KB Output is correct
11 Correct 189 ms 43492 KB Output is correct
12 Correct 29 ms 24184 KB Output is correct
13 Correct 23 ms 24184 KB Output is correct
14 Correct 24 ms 24184 KB Output is correct
15 Correct 26 ms 24184 KB Output is correct
16 Correct 28 ms 24184 KB Output is correct
17 Correct 23 ms 24152 KB Output is correct
18 Correct 22 ms 24056 KB Output is correct
19 Correct 23 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 24 ms 24184 KB Output is correct
23 Correct 23 ms 24184 KB Output is correct
24 Correct 23 ms 24056 KB Output is correct
25 Correct 23 ms 24184 KB Output is correct
26 Correct 23 ms 24056 KB Output is correct
27 Correct 23 ms 24056 KB Output is correct
28 Correct 26 ms 24312 KB Output is correct
29 Correct 26 ms 24440 KB Output is correct
30 Correct 30 ms 24316 KB Output is correct
31 Correct 32 ms 24312 KB Output is correct
32 Correct 26 ms 24440 KB Output is correct
33 Correct 30 ms 24312 KB Output is correct
34 Correct 34 ms 24312 KB Output is correct
35 Correct 239 ms 47104 KB Output is correct
36 Correct 343 ms 55632 KB Output is correct
37 Correct 250 ms 45824 KB Output is correct
38 Correct 354 ms 59876 KB Output is correct
39 Correct 308 ms 46824 KB Output is correct
40 Correct 219 ms 44672 KB Output is correct
41 Correct 468 ms 48220 KB Output is correct
42 Correct 170 ms 42512 KB Output is correct
43 Correct 120 ms 33156 KB Output is correct
44 Correct 357 ms 47480 KB Output is correct
45 Correct 421 ms 50928 KB Output is correct
46 Correct 398 ms 44664 KB Output is correct
47 Correct 401 ms 44536 KB Output is correct
48 Correct 292 ms 45664 KB Output is correct
49 Correct 397 ms 59256 KB Output is correct
50 Correct 447 ms 58948 KB Output is correct
51 Correct 285 ms 49392 KB Output is correct
52 Correct 28 ms 24056 KB Output is correct
53 Correct 515 ms 46676 KB Output is correct
54 Correct 395 ms 45108 KB Output is correct
55 Correct 468 ms 48640 KB Output is correct
56 Correct 433 ms 46864 KB Output is correct
57 Incorrect 283 ms 45876 KB Output isn't correct
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 340 ms 58824 KB Output is correct
2 Correct 312 ms 49868 KB Output is correct
3 Correct 255 ms 46328 KB Output is correct
4 Correct 347 ms 56432 KB Output is correct
5 Correct 23 ms 24056 KB Output is correct
6 Correct 313 ms 48220 KB Output is correct
7 Correct 139 ms 38196 KB Output is correct
8 Correct 135 ms 34808 KB Output is correct
9 Correct 270 ms 45924 KB Output is correct
10 Correct 265 ms 49528 KB Output is correct
11 Correct 189 ms 43492 KB Output is correct
12 Correct 29 ms 24184 KB Output is correct
13 Correct 23 ms 24184 KB Output is correct
14 Correct 24 ms 24184 KB Output is correct
15 Correct 26 ms 24184 KB Output is correct
16 Correct 28 ms 24184 KB Output is correct
17 Correct 23 ms 24152 KB Output is correct
18 Correct 22 ms 24056 KB Output is correct
19 Correct 23 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 24 ms 24184 KB Output is correct
23 Correct 23 ms 24184 KB Output is correct
24 Correct 23 ms 24056 KB Output is correct
25 Correct 23 ms 24184 KB Output is correct
26 Correct 23 ms 24056 KB Output is correct
27 Correct 23 ms 24056 KB Output is correct
28 Correct 26 ms 24312 KB Output is correct
29 Correct 26 ms 24440 KB Output is correct
30 Correct 30 ms 24316 KB Output is correct
31 Correct 32 ms 24312 KB Output is correct
32 Correct 26 ms 24440 KB Output is correct
33 Correct 30 ms 24312 KB Output is correct
34 Correct 34 ms 24312 KB Output is correct
35 Correct 239 ms 47104 KB Output is correct
36 Correct 343 ms 55632 KB Output is correct
37 Correct 250 ms 45824 KB Output is correct
38 Correct 354 ms 59876 KB Output is correct
39 Correct 308 ms 46824 KB Output is correct
40 Correct 219 ms 44672 KB Output is correct
41 Correct 468 ms 48220 KB Output is correct
42 Correct 170 ms 42512 KB Output is correct
43 Correct 120 ms 33156 KB Output is correct
44 Correct 357 ms 47480 KB Output is correct
45 Correct 421 ms 50928 KB Output is correct
46 Correct 398 ms 44664 KB Output is correct
47 Correct 401 ms 44536 KB Output is correct
48 Correct 292 ms 45664 KB Output is correct
49 Correct 397 ms 59256 KB Output is correct
50 Correct 447 ms 58948 KB Output is correct
51 Correct 285 ms 49392 KB Output is correct
52 Correct 28 ms 24056 KB Output is correct
53 Correct 515 ms 46676 KB Output is correct
54 Correct 395 ms 45108 KB Output is correct
55 Correct 468 ms 48640 KB Output is correct
56 Correct 433 ms 46864 KB Output is correct
57 Correct 1367 ms 98492 KB Output is correct
58 Correct 2017 ms 167952 KB Output is correct
59 Correct 2292 ms 167748 KB Output is correct
60 Correct 1347 ms 120864 KB Output is correct
61 Correct 2939 ms 111028 KB Output is correct
62 Correct 2052 ms 104284 KB Output is correct
63 Correct 2533 ms 119784 KB Output is correct
64 Correct 2516 ms 114056 KB Output is correct
65 Incorrect 283 ms 45876 KB Output isn't correct
66 Halted 0 ms 0 KB -