답안 #246906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246906 2020-07-10T13:51:47 Z red1108 Two Dishes (JOI19_dishes) C++17
100 / 100
4645 ms 213004 KB
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define fopen freopen("input.txt", "r", stdin)
#define eb emplace_back
#define em emplace
#define prec(a) cout<<fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()
typedef long long ll;typedef long double ld;typedef unsigned long long ul;typedef unsigned int ui;typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
const ll INF = 2e18;
const int inf = 2e9;
template<class T>
void pr(T t) {cerr << t << " ";}
template<class T, class ...Args>
void pr(T a, Args ...args) {cerr << a << " ";pr(args...);}
template<class ...Args>
void prl(Args ...args) {pr(args...);cerr << endl;}


int n, m;
struct In{
	ll ti, lim, cost;
}A[1000100], B[1000100];
ll ans;
vector<pll> ad[1000100];
ll asum[1000100],bsum[1000100];
ll seg[4000100];
bool flag[4000100];
void prop(int x, int l, int r){
	if(!flag[x]) return ;
	if(l!=r) flag[x*2]=flag[x*2+1]=true;
	seg[x] = flag[x] = 0;
	return ;
}
ll get(int x, int l, int r, int s, int e){
	prop(x, l, r);
	if(r<s||e<l||s>e) return 0;
	if(s<=l&&r<=e) return seg[x];
	return get(x*2, l, (l+r)/2, s, e)+get(x*2+1, (l+r)/2+1,r,s,e);
}
void clr(int x, int l, int r, int s, int e){
	prop(x, l, r);
	if(r<s||e<l||s>e) return ;
	if(s<=l&&r<=e){
		flag[x]=true;
		prop(x,l,r);
		return ;
	}
	clr(x*2, l, (l+r)/2, s, e);clr(x*2+1, (l+r)/2+1,r,s,e);
	seg[x]=seg[x*2]+seg[x*2+1];
}
void add(int x, int l, int r, int i, ll v){
	prop(x,l,r);
	if(r<i||i<l) return ;
	if(l==r){
		seg[x]+=v;return ;
	}
	int m = (l+r)/2;
	if(i<=m) add(x*2, l, m, i, v);
	else add(x*2+1, m+1,r,i,v);
	seg[x] = seg[x*2]*(1-flag[x*2])+seg[x*2+1]*(1-flag[x*2+1]);
}
int get_left(int x, int l, int r, ll v){
	prop(x,l,r);
	if(l==r) return l;
	ll t = (flag[x*2]?0:seg[x*2]);
	if(t>v) return get_left(x*2, l,(l+r)/2, v);
	return get_left(x*2+1, (l+r)/2+1, r, v-t);
}
int main(){
	fastio;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>A[i].ti>>A[i].lim>>A[i].cost;
		asum[i]=asum[i-1]+A[i].ti;
	}
	for(int i=1;i<=m;i++){
		cin>>B[i].ti>>B[i].lim>>B[i].cost;
		bsum[i]=bsum[i-1]+B[i].ti;
	}
	for(int i=1;i<=n;i++){
		if(asum[i]>A[i].lim) continue;
		int j = upper_bound(bsum+1,bsum+m+1, A[i].lim-asum[i])-bsum-1;
		ans+=A[i].cost;
		if(j!=m) ad[i-1].eb(j+1, -A[i].cost);
	}
	for(int i=1;i<=m;i++){
		if(bsum[i]>B[i].lim) continue;
		int j = upper_bound(asum+1,asum+n+1, B[i].lim-bsum[i])-asum-1;
		if(j!=n) ad[j].eb(i,B[i].cost);
		else ans+=B[i].cost;
	}
	for(int i=0;i<=n;i++){
		sort(all(ad[i]), [](pll &a,pll &b){
			return a.se>b.se;
		});
		for(auto j:ad[i]){
			if(j.se>=0){
				add(1,0,m,j.fi,j.se);
				continue;
			}
			else{
				ll t = get(1,0,m,0,j.fi-1)-j.se;
				int ind=m+1;
				if(get(1, 0, m, 0, m)>t) ind=get_left(1, 0, m, t);
				ll v=get(1, 0, m, 0, ind)-get(1, 0, m, ind,ind)-t;
				clr(1, 0, m, j.fi, ind-1);
				add(1, 0, m, ind, v);
			}
		}
	}
	cout<<ans+get(1,0,m,0,m);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 50488 KB Output is correct
2 Correct 352 ms 49912 KB Output is correct
3 Correct 202 ms 36472 KB Output is correct
4 Correct 313 ms 44852 KB Output is correct
5 Correct 18 ms 23936 KB Output is correct
6 Correct 370 ms 47352 KB Output is correct
7 Correct 108 ms 30200 KB Output is correct
8 Correct 113 ms 30072 KB Output is correct
9 Correct 216 ms 36344 KB Output is correct
10 Correct 378 ms 50528 KB Output is correct
11 Correct 168 ms 36320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 20 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23936 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 18 ms 23936 KB Output is correct
9 Correct 19 ms 23936 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 20 ms 23936 KB Output is correct
12 Correct 20 ms 23808 KB Output is correct
13 Correct 18 ms 23808 KB Output is correct
14 Correct 19 ms 23808 KB Output is correct
15 Correct 21 ms 23808 KB Output is correct
16 Correct 19 ms 23936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 20 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23936 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 18 ms 23936 KB Output is correct
9 Correct 19 ms 23936 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 20 ms 23936 KB Output is correct
12 Correct 20 ms 23808 KB Output is correct
13 Correct 18 ms 23808 KB Output is correct
14 Correct 19 ms 23808 KB Output is correct
15 Correct 21 ms 23808 KB Output is correct
16 Correct 19 ms 23936 KB Output is correct
17 Correct 21 ms 24064 KB Output is correct
18 Correct 21 ms 24064 KB Output is correct
19 Correct 23 ms 24192 KB Output is correct
20 Correct 22 ms 24064 KB Output is correct
21 Correct 26 ms 24064 KB Output is correct
22 Correct 22 ms 24192 KB Output is correct
23 Correct 25 ms 24192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 20 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23936 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 18 ms 23936 KB Output is correct
9 Correct 19 ms 23936 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 20 ms 23936 KB Output is correct
12 Correct 20 ms 23808 KB Output is correct
13 Correct 18 ms 23808 KB Output is correct
14 Correct 19 ms 23808 KB Output is correct
15 Correct 21 ms 23808 KB Output is correct
16 Correct 19 ms 23936 KB Output is correct
17 Correct 21 ms 24064 KB Output is correct
18 Correct 21 ms 24064 KB Output is correct
19 Correct 23 ms 24192 KB Output is correct
20 Correct 22 ms 24064 KB Output is correct
21 Correct 26 ms 24064 KB Output is correct
22 Correct 22 ms 24192 KB Output is correct
23 Correct 25 ms 24192 KB Output is correct
24 Correct 249 ms 42704 KB Output is correct
25 Correct 236 ms 43744 KB Output is correct
26 Correct 283 ms 47308 KB Output is correct
27 Correct 228 ms 46840 KB Output is correct
28 Correct 336 ms 44024 KB Output is correct
29 Correct 184 ms 36344 KB Output is correct
30 Correct 691 ms 52600 KB Output is correct
31 Correct 123 ms 35948 KB Output is correct
32 Correct 110 ms 33276 KB Output is correct
33 Correct 423 ms 46556 KB Output is correct
34 Correct 471 ms 49400 KB Output is correct
35 Correct 647 ms 52856 KB Output is correct
36 Correct 633 ms 52272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 20 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23936 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 18 ms 23936 KB Output is correct
9 Correct 19 ms 23936 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 20 ms 23936 KB Output is correct
12 Correct 20 ms 23808 KB Output is correct
13 Correct 18 ms 23808 KB Output is correct
14 Correct 19 ms 23808 KB Output is correct
15 Correct 21 ms 23808 KB Output is correct
16 Correct 19 ms 23936 KB Output is correct
17 Correct 21 ms 24064 KB Output is correct
18 Correct 21 ms 24064 KB Output is correct
19 Correct 23 ms 24192 KB Output is correct
20 Correct 22 ms 24064 KB Output is correct
21 Correct 26 ms 24064 KB Output is correct
22 Correct 22 ms 24192 KB Output is correct
23 Correct 25 ms 24192 KB Output is correct
24 Correct 249 ms 42704 KB Output is correct
25 Correct 236 ms 43744 KB Output is correct
26 Correct 283 ms 47308 KB Output is correct
27 Correct 228 ms 46840 KB Output is correct
28 Correct 336 ms 44024 KB Output is correct
29 Correct 184 ms 36344 KB Output is correct
30 Correct 691 ms 52600 KB Output is correct
31 Correct 123 ms 35948 KB Output is correct
32 Correct 110 ms 33276 KB Output is correct
33 Correct 423 ms 46556 KB Output is correct
34 Correct 471 ms 49400 KB Output is correct
35 Correct 647 ms 52856 KB Output is correct
36 Correct 633 ms 52272 KB Output is correct
37 Correct 297 ms 47200 KB Output is correct
38 Correct 260 ms 46844 KB Output is correct
39 Correct 365 ms 50168 KB Output is correct
40 Correct 409 ms 50424 KB Output is correct
41 Correct 18 ms 23808 KB Output is correct
42 Correct 704 ms 52472 KB Output is correct
43 Correct 457 ms 46456 KB Output is correct
44 Correct 508 ms 49400 KB Output is correct
45 Correct 670 ms 52728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 20 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23936 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 18 ms 23936 KB Output is correct
9 Correct 19 ms 23936 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 20 ms 23936 KB Output is correct
12 Correct 20 ms 23808 KB Output is correct
13 Correct 18 ms 23808 KB Output is correct
14 Correct 19 ms 23808 KB Output is correct
15 Correct 21 ms 23808 KB Output is correct
16 Correct 19 ms 23936 KB Output is correct
17 Correct 21 ms 24064 KB Output is correct
18 Correct 21 ms 24064 KB Output is correct
19 Correct 23 ms 24192 KB Output is correct
20 Correct 22 ms 24064 KB Output is correct
21 Correct 26 ms 24064 KB Output is correct
22 Correct 22 ms 24192 KB Output is correct
23 Correct 25 ms 24192 KB Output is correct
24 Correct 249 ms 42704 KB Output is correct
25 Correct 236 ms 43744 KB Output is correct
26 Correct 283 ms 47308 KB Output is correct
27 Correct 228 ms 46840 KB Output is correct
28 Correct 336 ms 44024 KB Output is correct
29 Correct 184 ms 36344 KB Output is correct
30 Correct 691 ms 52600 KB Output is correct
31 Correct 123 ms 35948 KB Output is correct
32 Correct 110 ms 33276 KB Output is correct
33 Correct 423 ms 46556 KB Output is correct
34 Correct 471 ms 49400 KB Output is correct
35 Correct 647 ms 52856 KB Output is correct
36 Correct 633 ms 52272 KB Output is correct
37 Correct 297 ms 47200 KB Output is correct
38 Correct 260 ms 46844 KB Output is correct
39 Correct 365 ms 50168 KB Output is correct
40 Correct 409 ms 50424 KB Output is correct
41 Correct 18 ms 23808 KB Output is correct
42 Correct 704 ms 52472 KB Output is correct
43 Correct 457 ms 46456 KB Output is correct
44 Correct 508 ms 49400 KB Output is correct
45 Correct 670 ms 52728 KB Output is correct
46 Correct 1476 ms 136444 KB Output is correct
47 Correct 1175 ms 134136 KB Output is correct
48 Correct 1890 ms 151356 KB Output is correct
49 Correct 2182 ms 152148 KB Output is correct
50 Correct 4355 ms 163356 KB Output is correct
51 Correct 2495 ms 179040 KB Output is correct
52 Correct 2846 ms 188216 KB Output is correct
53 Correct 3953 ms 199604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 50488 KB Output is correct
2 Correct 352 ms 49912 KB Output is correct
3 Correct 202 ms 36472 KB Output is correct
4 Correct 313 ms 44852 KB Output is correct
5 Correct 18 ms 23936 KB Output is correct
6 Correct 370 ms 47352 KB Output is correct
7 Correct 108 ms 30200 KB Output is correct
8 Correct 113 ms 30072 KB Output is correct
9 Correct 216 ms 36344 KB Output is correct
10 Correct 378 ms 50528 KB Output is correct
11 Correct 168 ms 36320 KB Output is correct
12 Correct 19 ms 23936 KB Output is correct
13 Correct 20 ms 23808 KB Output is correct
14 Correct 19 ms 23808 KB Output is correct
15 Correct 19 ms 23936 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 19 ms 23808 KB Output is correct
18 Correct 18 ms 23808 KB Output is correct
19 Correct 18 ms 23936 KB Output is correct
20 Correct 19 ms 23936 KB Output is correct
21 Correct 18 ms 23808 KB Output is correct
22 Correct 20 ms 23936 KB Output is correct
23 Correct 20 ms 23808 KB Output is correct
24 Correct 18 ms 23808 KB Output is correct
25 Correct 19 ms 23808 KB Output is correct
26 Correct 21 ms 23808 KB Output is correct
27 Correct 19 ms 23936 KB Output is correct
28 Correct 21 ms 24064 KB Output is correct
29 Correct 21 ms 24064 KB Output is correct
30 Correct 23 ms 24192 KB Output is correct
31 Correct 22 ms 24064 KB Output is correct
32 Correct 26 ms 24064 KB Output is correct
33 Correct 22 ms 24192 KB Output is correct
34 Correct 25 ms 24192 KB Output is correct
35 Correct 249 ms 42704 KB Output is correct
36 Correct 236 ms 43744 KB Output is correct
37 Correct 283 ms 47308 KB Output is correct
38 Correct 228 ms 46840 KB Output is correct
39 Correct 336 ms 44024 KB Output is correct
40 Correct 184 ms 36344 KB Output is correct
41 Correct 691 ms 52600 KB Output is correct
42 Correct 123 ms 35948 KB Output is correct
43 Correct 110 ms 33276 KB Output is correct
44 Correct 423 ms 46556 KB Output is correct
45 Correct 471 ms 49400 KB Output is correct
46 Correct 647 ms 52856 KB Output is correct
47 Correct 633 ms 52272 KB Output is correct
48 Correct 297 ms 47200 KB Output is correct
49 Correct 260 ms 46844 KB Output is correct
50 Correct 365 ms 50168 KB Output is correct
51 Correct 409 ms 50424 KB Output is correct
52 Correct 18 ms 23808 KB Output is correct
53 Correct 704 ms 52472 KB Output is correct
54 Correct 457 ms 46456 KB Output is correct
55 Correct 508 ms 49400 KB Output is correct
56 Correct 670 ms 52728 KB Output is correct
57 Correct 252 ms 46840 KB Output is correct
58 Correct 313 ms 47352 KB Output is correct
59 Correct 553 ms 50452 KB Output is correct
60 Correct 302 ms 50028 KB Output is correct
61 Correct 475 ms 52420 KB Output is correct
62 Correct 19 ms 23936 KB Output is correct
63 Correct 698 ms 52472 KB Output is correct
64 Correct 432 ms 46368 KB Output is correct
65 Correct 559 ms 49628 KB Output is correct
66 Correct 647 ms 52216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 50488 KB Output is correct
2 Correct 352 ms 49912 KB Output is correct
3 Correct 202 ms 36472 KB Output is correct
4 Correct 313 ms 44852 KB Output is correct
5 Correct 18 ms 23936 KB Output is correct
6 Correct 370 ms 47352 KB Output is correct
7 Correct 108 ms 30200 KB Output is correct
8 Correct 113 ms 30072 KB Output is correct
9 Correct 216 ms 36344 KB Output is correct
10 Correct 378 ms 50528 KB Output is correct
11 Correct 168 ms 36320 KB Output is correct
12 Correct 19 ms 23936 KB Output is correct
13 Correct 20 ms 23808 KB Output is correct
14 Correct 19 ms 23808 KB Output is correct
15 Correct 19 ms 23936 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 19 ms 23808 KB Output is correct
18 Correct 18 ms 23808 KB Output is correct
19 Correct 18 ms 23936 KB Output is correct
20 Correct 19 ms 23936 KB Output is correct
21 Correct 18 ms 23808 KB Output is correct
22 Correct 20 ms 23936 KB Output is correct
23 Correct 20 ms 23808 KB Output is correct
24 Correct 18 ms 23808 KB Output is correct
25 Correct 19 ms 23808 KB Output is correct
26 Correct 21 ms 23808 KB Output is correct
27 Correct 19 ms 23936 KB Output is correct
28 Correct 21 ms 24064 KB Output is correct
29 Correct 21 ms 24064 KB Output is correct
30 Correct 23 ms 24192 KB Output is correct
31 Correct 22 ms 24064 KB Output is correct
32 Correct 26 ms 24064 KB Output is correct
33 Correct 22 ms 24192 KB Output is correct
34 Correct 25 ms 24192 KB Output is correct
35 Correct 249 ms 42704 KB Output is correct
36 Correct 236 ms 43744 KB Output is correct
37 Correct 283 ms 47308 KB Output is correct
38 Correct 228 ms 46840 KB Output is correct
39 Correct 336 ms 44024 KB Output is correct
40 Correct 184 ms 36344 KB Output is correct
41 Correct 691 ms 52600 KB Output is correct
42 Correct 123 ms 35948 KB Output is correct
43 Correct 110 ms 33276 KB Output is correct
44 Correct 423 ms 46556 KB Output is correct
45 Correct 471 ms 49400 KB Output is correct
46 Correct 647 ms 52856 KB Output is correct
47 Correct 633 ms 52272 KB Output is correct
48 Correct 297 ms 47200 KB Output is correct
49 Correct 260 ms 46844 KB Output is correct
50 Correct 365 ms 50168 KB Output is correct
51 Correct 409 ms 50424 KB Output is correct
52 Correct 18 ms 23808 KB Output is correct
53 Correct 704 ms 52472 KB Output is correct
54 Correct 457 ms 46456 KB Output is correct
55 Correct 508 ms 49400 KB Output is correct
56 Correct 670 ms 52728 KB Output is correct
57 Correct 1476 ms 136444 KB Output is correct
58 Correct 1175 ms 134136 KB Output is correct
59 Correct 1890 ms 151356 KB Output is correct
60 Correct 2182 ms 152148 KB Output is correct
61 Correct 4355 ms 163356 KB Output is correct
62 Correct 2495 ms 179040 KB Output is correct
63 Correct 2846 ms 188216 KB Output is correct
64 Correct 3953 ms 199604 KB Output is correct
65 Correct 252 ms 46840 KB Output is correct
66 Correct 313 ms 47352 KB Output is correct
67 Correct 553 ms 50452 KB Output is correct
68 Correct 302 ms 50028 KB Output is correct
69 Correct 475 ms 52420 KB Output is correct
70 Correct 19 ms 23936 KB Output is correct
71 Correct 698 ms 52472 KB Output is correct
72 Correct 432 ms 46368 KB Output is correct
73 Correct 559 ms 49628 KB Output is correct
74 Correct 647 ms 52216 KB Output is correct
75 Correct 1258 ms 187068 KB Output is correct
76 Correct 1517 ms 188820 KB Output is correct
77 Correct 2900 ms 199400 KB Output is correct
78 Correct 1392 ms 192012 KB Output is correct
79 Correct 4645 ms 213004 KB Output is correct
80 Correct 2533 ms 176284 KB Output is correct
81 Correct 3137 ms 188080 KB Output is correct
82 Correct 4213 ms 201024 KB Output is correct
83 Correct 4155 ms 198556 KB Output is correct