Submission #123412

# Submission time Handle Problem Language Result Execution time Memory
123412 2019-07-01T12:08:56 Z sebinkim Two Dishes (JOI19_dishes) C++14
74 / 100
3544 ms 167604 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)
{
	if(p < 0 || p > m) 1 / 0;
	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{
				if(X.find(t) == X.end()){
					query(2, t, Q1[t]);
				}
				else{
					x = F.getval(t) - F.getval(t - 1);
					if(x <= Q1[t]){
						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 'void query(ll, ll, ll)':
dishes.cpp:44:23: warning: division by zero [-Wdiv-by-zero]
  if(p < 0 || p > m) 1 / 0;
                     ~~^~~
dishes.cpp:44:23: warning: statement has no effect [-Wunused-value]
dishes.cpp: In function 'int main()':
dishes.cpp:77:8: warning: unused variable 'k' [-Wunused-variable]
  ll i, k, x;
        ^
dishes.cpp:79: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:82: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:91: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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 362 ms 58656 KB Output is correct
2 Correct 333 ms 50344 KB Output is correct
3 Correct 368 ms 46180 KB Output is correct
4 Correct 369 ms 56340 KB Output is correct
5 Correct 23 ms 24184 KB Output is correct
6 Correct 336 ms 49264 KB Output is correct
7 Correct 139 ms 38372 KB Output is correct
8 Correct 135 ms 35080 KB Output is correct
9 Correct 264 ms 46436 KB Output is correct
10 Correct 295 ms 49528 KB Output is correct
11 Correct 189 ms 43460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24056 KB Output is correct
2 Correct 23 ms 24184 KB Output is correct
3 Correct 23 ms 24184 KB Output is correct
4 Correct 24 ms 24056 KB Output is correct
5 Correct 23 ms 24184 KB Output is correct
6 Correct 23 ms 24056 KB Output is correct
7 Correct 24 ms 24312 KB Output is correct
8 Correct 23 ms 24056 KB Output is correct
9 Correct 24 ms 24184 KB Output is correct
10 Correct 24 ms 24056 KB Output is correct
11 Correct 24 ms 24184 KB Output is correct
12 Correct 24 ms 24184 KB Output is correct
13 Correct 23 ms 24184 KB Output is correct
14 Correct 23 ms 24184 KB Output is correct
15 Correct 24 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 24056 KB Output is correct
2 Correct 23 ms 24184 KB Output is correct
3 Correct 23 ms 24184 KB Output is correct
4 Correct 24 ms 24056 KB Output is correct
5 Correct 23 ms 24184 KB Output is correct
6 Correct 23 ms 24056 KB Output is correct
7 Correct 24 ms 24312 KB Output is correct
8 Correct 23 ms 24056 KB Output is correct
9 Correct 24 ms 24184 KB Output is correct
10 Correct 24 ms 24056 KB Output is correct
11 Correct 24 ms 24184 KB Output is correct
12 Correct 24 ms 24184 KB Output is correct
13 Correct 23 ms 24184 KB Output is correct
14 Correct 23 ms 24184 KB Output is correct
15 Correct 24 ms 24184 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 31 ms 24312 KB Output is correct
18 Correct 25 ms 24440 KB Output is correct
19 Correct 28 ms 24444 KB Output is correct
20 Correct 26 ms 24312 KB Output is correct
21 Correct 27 ms 24440 KB Output is correct
22 Correct 27 ms 24440 KB Output is correct
23 Correct 26 ms 24312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24056 KB Output is correct
2 Correct 23 ms 24184 KB Output is correct
3 Correct 23 ms 24184 KB Output is correct
4 Correct 24 ms 24056 KB Output is correct
5 Correct 23 ms 24184 KB Output is correct
6 Correct 23 ms 24056 KB Output is correct
7 Correct 24 ms 24312 KB Output is correct
8 Correct 23 ms 24056 KB Output is correct
9 Correct 24 ms 24184 KB Output is correct
10 Correct 24 ms 24056 KB Output is correct
11 Correct 24 ms 24184 KB Output is correct
12 Correct 24 ms 24184 KB Output is correct
13 Correct 23 ms 24184 KB Output is correct
14 Correct 23 ms 24184 KB Output is correct
15 Correct 24 ms 24184 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 31 ms 24312 KB Output is correct
18 Correct 25 ms 24440 KB Output is correct
19 Correct 28 ms 24444 KB Output is correct
20 Correct 26 ms 24312 KB Output is correct
21 Correct 27 ms 24440 KB Output is correct
22 Correct 27 ms 24440 KB Output is correct
23 Correct 26 ms 24312 KB Output is correct
24 Correct 266 ms 46492 KB Output is correct
25 Correct 331 ms 56368 KB Output is correct
26 Correct 379 ms 57044 KB Output is correct
27 Correct 352 ms 61688 KB Output is correct
28 Correct 348 ms 48816 KB Output is correct
29 Correct 225 ms 46436 KB Output is correct
30 Correct 562 ms 50488 KB Output is correct
31 Correct 182 ms 42896 KB Output is correct
32 Correct 127 ms 33528 KB Output is correct
33 Correct 400 ms 48948 KB Output is correct
34 Correct 468 ms 52344 KB Output is correct
35 Correct 478 ms 45100 KB Output is correct
36 Correct 479 ms 45120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24056 KB Output is correct
2 Correct 23 ms 24184 KB Output is correct
3 Correct 23 ms 24184 KB Output is correct
4 Correct 24 ms 24056 KB Output is correct
5 Correct 23 ms 24184 KB Output is correct
6 Correct 23 ms 24056 KB Output is correct
7 Correct 24 ms 24312 KB Output is correct
8 Correct 23 ms 24056 KB Output is correct
9 Correct 24 ms 24184 KB Output is correct
10 Correct 24 ms 24056 KB Output is correct
11 Correct 24 ms 24184 KB Output is correct
12 Correct 24 ms 24184 KB Output is correct
13 Correct 23 ms 24184 KB Output is correct
14 Correct 23 ms 24184 KB Output is correct
15 Correct 24 ms 24184 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 31 ms 24312 KB Output is correct
18 Correct 25 ms 24440 KB Output is correct
19 Correct 28 ms 24444 KB Output is correct
20 Correct 26 ms 24312 KB Output is correct
21 Correct 27 ms 24440 KB Output is correct
22 Correct 27 ms 24440 KB Output is correct
23 Correct 26 ms 24312 KB Output is correct
24 Correct 266 ms 46492 KB Output is correct
25 Correct 331 ms 56368 KB Output is correct
26 Correct 379 ms 57044 KB Output is correct
27 Correct 352 ms 61688 KB Output is correct
28 Correct 348 ms 48816 KB Output is correct
29 Correct 225 ms 46436 KB Output is correct
30 Correct 562 ms 50488 KB Output is correct
31 Correct 182 ms 42896 KB Output is correct
32 Correct 127 ms 33528 KB Output is correct
33 Correct 400 ms 48948 KB Output is correct
34 Correct 468 ms 52344 KB Output is correct
35 Correct 478 ms 45100 KB Output is correct
36 Correct 479 ms 45120 KB Output is correct
37 Correct 313 ms 50712 KB Output is correct
38 Correct 397 ms 64672 KB Output is correct
39 Correct 469 ms 62456 KB Output is correct
40 Correct 309 ms 52856 KB Output is correct
41 Correct 23 ms 24184 KB Output is correct
42 Correct 664 ms 54136 KB Output is correct
43 Correct 442 ms 52716 KB Output is correct
44 Correct 514 ms 56408 KB Output is correct
45 Correct 555 ms 48376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24056 KB Output is correct
2 Correct 23 ms 24184 KB Output is correct
3 Correct 23 ms 24184 KB Output is correct
4 Correct 24 ms 24056 KB Output is correct
5 Correct 23 ms 24184 KB Output is correct
6 Correct 23 ms 24056 KB Output is correct
7 Correct 24 ms 24312 KB Output is correct
8 Correct 23 ms 24056 KB Output is correct
9 Correct 24 ms 24184 KB Output is correct
10 Correct 24 ms 24056 KB Output is correct
11 Correct 24 ms 24184 KB Output is correct
12 Correct 24 ms 24184 KB Output is correct
13 Correct 23 ms 24184 KB Output is correct
14 Correct 23 ms 24184 KB Output is correct
15 Correct 24 ms 24184 KB Output is correct
16 Correct 23 ms 24056 KB Output is correct
17 Correct 31 ms 24312 KB Output is correct
18 Correct 25 ms 24440 KB Output is correct
19 Correct 28 ms 24444 KB Output is correct
20 Correct 26 ms 24312 KB Output is correct
21 Correct 27 ms 24440 KB Output is correct
22 Correct 27 ms 24440 KB Output is correct
23 Correct 26 ms 24312 KB Output is correct
24 Correct 266 ms 46492 KB Output is correct
25 Correct 331 ms 56368 KB Output is correct
26 Correct 379 ms 57044 KB Output is correct
27 Correct 352 ms 61688 KB Output is correct
28 Correct 348 ms 48816 KB Output is correct
29 Correct 225 ms 46436 KB Output is correct
30 Correct 562 ms 50488 KB Output is correct
31 Correct 182 ms 42896 KB Output is correct
32 Correct 127 ms 33528 KB Output is correct
33 Correct 400 ms 48948 KB Output is correct
34 Correct 468 ms 52344 KB Output is correct
35 Correct 478 ms 45100 KB Output is correct
36 Correct 479 ms 45120 KB Output is correct
37 Correct 313 ms 50712 KB Output is correct
38 Correct 397 ms 64672 KB Output is correct
39 Correct 469 ms 62456 KB Output is correct
40 Correct 309 ms 52856 KB Output is correct
41 Correct 23 ms 24184 KB Output is correct
42 Correct 664 ms 54136 KB Output is correct
43 Correct 442 ms 52716 KB Output is correct
44 Correct 514 ms 56408 KB Output is correct
45 Correct 555 ms 48376 KB Output is correct
46 Correct 1545 ms 98924 KB Output is correct
47 Correct 2021 ms 167604 KB Output is correct
48 Correct 2546 ms 167248 KB Output is correct
49 Correct 1485 ms 120224 KB Output is correct
50 Correct 3544 ms 110496 KB Output is correct
51 Correct 2323 ms 103644 KB Output is correct
52 Correct 2937 ms 119188 KB Output is correct
53 Correct 3132 ms 118416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 58656 KB Output is correct
2 Correct 333 ms 50344 KB Output is correct
3 Correct 368 ms 46180 KB Output is correct
4 Correct 369 ms 56340 KB Output is correct
5 Correct 23 ms 24184 KB Output is correct
6 Correct 336 ms 49264 KB Output is correct
7 Correct 139 ms 38372 KB Output is correct
8 Correct 135 ms 35080 KB Output is correct
9 Correct 264 ms 46436 KB Output is correct
10 Correct 295 ms 49528 KB Output is correct
11 Correct 189 ms 43460 KB Output is correct
12 Correct 23 ms 24056 KB Output is correct
13 Correct 23 ms 24184 KB Output is correct
14 Correct 23 ms 24184 KB Output is correct
15 Correct 24 ms 24056 KB Output is correct
16 Correct 23 ms 24184 KB Output is correct
17 Correct 23 ms 24056 KB Output is correct
18 Correct 24 ms 24312 KB Output is correct
19 Correct 23 ms 24056 KB Output is correct
20 Correct 24 ms 24184 KB Output is correct
21 Correct 24 ms 24056 KB Output is correct
22 Correct 24 ms 24184 KB Output is correct
23 Correct 24 ms 24184 KB Output is correct
24 Correct 23 ms 24184 KB Output is correct
25 Correct 23 ms 24184 KB Output is correct
26 Correct 24 ms 24184 KB Output is correct
27 Correct 23 ms 24056 KB Output is correct
28 Correct 31 ms 24312 KB Output is correct
29 Correct 25 ms 24440 KB Output is correct
30 Correct 28 ms 24444 KB Output is correct
31 Correct 26 ms 24312 KB Output is correct
32 Correct 27 ms 24440 KB Output is correct
33 Correct 27 ms 24440 KB Output is correct
34 Correct 26 ms 24312 KB Output is correct
35 Correct 266 ms 46492 KB Output is correct
36 Correct 331 ms 56368 KB Output is correct
37 Correct 379 ms 57044 KB Output is correct
38 Correct 352 ms 61688 KB Output is correct
39 Correct 348 ms 48816 KB Output is correct
40 Correct 225 ms 46436 KB Output is correct
41 Correct 562 ms 50488 KB Output is correct
42 Correct 182 ms 42896 KB Output is correct
43 Correct 127 ms 33528 KB Output is correct
44 Correct 400 ms 48948 KB Output is correct
45 Correct 468 ms 52344 KB Output is correct
46 Correct 478 ms 45100 KB Output is correct
47 Correct 479 ms 45120 KB Output is correct
48 Correct 313 ms 50712 KB Output is correct
49 Correct 397 ms 64672 KB Output is correct
50 Correct 469 ms 62456 KB Output is correct
51 Correct 309 ms 52856 KB Output is correct
52 Correct 23 ms 24184 KB Output is correct
53 Correct 664 ms 54136 KB Output is correct
54 Correct 442 ms 52716 KB Output is correct
55 Correct 514 ms 56408 KB Output is correct
56 Correct 555 ms 48376 KB Output is correct
57 Correct 436 ms 59772 KB Output is correct
58 Correct 480 ms 66724 KB Output is correct
59 Incorrect 327 ms 54484 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 362 ms 58656 KB Output is correct
2 Correct 333 ms 50344 KB Output is correct
3 Correct 368 ms 46180 KB Output is correct
4 Correct 369 ms 56340 KB Output is correct
5 Correct 23 ms 24184 KB Output is correct
6 Correct 336 ms 49264 KB Output is correct
7 Correct 139 ms 38372 KB Output is correct
8 Correct 135 ms 35080 KB Output is correct
9 Correct 264 ms 46436 KB Output is correct
10 Correct 295 ms 49528 KB Output is correct
11 Correct 189 ms 43460 KB Output is correct
12 Correct 23 ms 24056 KB Output is correct
13 Correct 23 ms 24184 KB Output is correct
14 Correct 23 ms 24184 KB Output is correct
15 Correct 24 ms 24056 KB Output is correct
16 Correct 23 ms 24184 KB Output is correct
17 Correct 23 ms 24056 KB Output is correct
18 Correct 24 ms 24312 KB Output is correct
19 Correct 23 ms 24056 KB Output is correct
20 Correct 24 ms 24184 KB Output is correct
21 Correct 24 ms 24056 KB Output is correct
22 Correct 24 ms 24184 KB Output is correct
23 Correct 24 ms 24184 KB Output is correct
24 Correct 23 ms 24184 KB Output is correct
25 Correct 23 ms 24184 KB Output is correct
26 Correct 24 ms 24184 KB Output is correct
27 Correct 23 ms 24056 KB Output is correct
28 Correct 31 ms 24312 KB Output is correct
29 Correct 25 ms 24440 KB Output is correct
30 Correct 28 ms 24444 KB Output is correct
31 Correct 26 ms 24312 KB Output is correct
32 Correct 27 ms 24440 KB Output is correct
33 Correct 27 ms 24440 KB Output is correct
34 Correct 26 ms 24312 KB Output is correct
35 Correct 266 ms 46492 KB Output is correct
36 Correct 331 ms 56368 KB Output is correct
37 Correct 379 ms 57044 KB Output is correct
38 Correct 352 ms 61688 KB Output is correct
39 Correct 348 ms 48816 KB Output is correct
40 Correct 225 ms 46436 KB Output is correct
41 Correct 562 ms 50488 KB Output is correct
42 Correct 182 ms 42896 KB Output is correct
43 Correct 127 ms 33528 KB Output is correct
44 Correct 400 ms 48948 KB Output is correct
45 Correct 468 ms 52344 KB Output is correct
46 Correct 478 ms 45100 KB Output is correct
47 Correct 479 ms 45120 KB Output is correct
48 Correct 313 ms 50712 KB Output is correct
49 Correct 397 ms 64672 KB Output is correct
50 Correct 469 ms 62456 KB Output is correct
51 Correct 309 ms 52856 KB Output is correct
52 Correct 23 ms 24184 KB Output is correct
53 Correct 664 ms 54136 KB Output is correct
54 Correct 442 ms 52716 KB Output is correct
55 Correct 514 ms 56408 KB Output is correct
56 Correct 555 ms 48376 KB Output is correct
57 Correct 1545 ms 98924 KB Output is correct
58 Correct 2021 ms 167604 KB Output is correct
59 Correct 2546 ms 167248 KB Output is correct
60 Correct 1485 ms 120224 KB Output is correct
61 Correct 3544 ms 110496 KB Output is correct
62 Correct 2323 ms 103644 KB Output is correct
63 Correct 2937 ms 119188 KB Output is correct
64 Correct 3132 ms 118416 KB Output is correct
65 Correct 436 ms 59772 KB Output is correct
66 Correct 480 ms 66724 KB Output is correct
67 Incorrect 327 ms 54484 KB Output isn't correct
68 Halted 0 ms 0 KB -