답안 #246907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246907 2020-07-10T13:54:06 Z red1108 Two Dishes (JOI19_dishes) C++17
100 / 100
4435 ms 164236 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;

				if(seg[1]<=t){
					clr(1,0,m,j.fi,m);
					continue;
				}
				int 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+seg[1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 366 ms 55800 KB Output is correct
2 Correct 362 ms 54916 KB Output is correct
3 Correct 217 ms 41080 KB Output is correct
4 Correct 316 ms 49656 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 364 ms 52088 KB Output is correct
7 Correct 118 ms 33016 KB Output is correct
8 Correct 114 ms 33016 KB Output is correct
9 Correct 212 ms 41208 KB Output is correct
10 Correct 374 ms 53624 KB Output is correct
11 Correct 172 ms 39928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 20 ms 23840 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23680 KB Output is correct
5 Correct 18 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 23808 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 20 ms 23808 KB Output is correct
11 Correct 19 ms 23936 KB Output is correct
12 Correct 20 ms 23808 KB Output is correct
13 Correct 20 ms 23808 KB Output is correct
14 Correct 22 ms 23808 KB Output is correct
15 Correct 19 ms 23936 KB Output is correct
16 Correct 19 ms 23936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 20 ms 23840 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23680 KB Output is correct
5 Correct 18 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 23808 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 20 ms 23808 KB Output is correct
11 Correct 19 ms 23936 KB Output is correct
12 Correct 20 ms 23808 KB Output is correct
13 Correct 20 ms 23808 KB Output is correct
14 Correct 22 ms 23808 KB Output is correct
15 Correct 19 ms 23936 KB Output is correct
16 Correct 19 ms 23936 KB Output is correct
17 Correct 21 ms 24192 KB Output is correct
18 Correct 21 ms 24192 KB Output is correct
19 Correct 22 ms 24192 KB Output is correct
20 Correct 22 ms 24192 KB Output is correct
21 Correct 22 ms 24192 KB Output is correct
22 Correct 21 ms 24224 KB Output is correct
23 Correct 22 ms 24192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 20 ms 23840 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23680 KB Output is correct
5 Correct 18 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 23808 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 20 ms 23808 KB Output is correct
11 Correct 19 ms 23936 KB Output is correct
12 Correct 20 ms 23808 KB Output is correct
13 Correct 20 ms 23808 KB Output is correct
14 Correct 22 ms 23808 KB Output is correct
15 Correct 19 ms 23936 KB Output is correct
16 Correct 19 ms 23936 KB Output is correct
17 Correct 21 ms 24192 KB Output is correct
18 Correct 21 ms 24192 KB Output is correct
19 Correct 22 ms 24192 KB Output is correct
20 Correct 22 ms 24192 KB Output is correct
21 Correct 22 ms 24192 KB Output is correct
22 Correct 21 ms 24224 KB Output is correct
23 Correct 22 ms 24192 KB Output is correct
24 Correct 257 ms 47732 KB Output is correct
25 Correct 219 ms 48612 KB Output is correct
26 Correct 260 ms 52216 KB Output is correct
27 Correct 228 ms 51704 KB Output is correct
28 Correct 315 ms 48748 KB Output is correct
29 Correct 189 ms 41208 KB Output is correct
30 Correct 699 ms 57464 KB Output is correct
31 Correct 119 ms 38892 KB Output is correct
32 Correct 120 ms 36352 KB Output is correct
33 Correct 446 ms 51464 KB Output is correct
34 Correct 466 ms 54392 KB Output is correct
35 Correct 627 ms 55288 KB Output is correct
36 Correct 658 ms 54880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 20 ms 23840 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23680 KB Output is correct
5 Correct 18 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 23808 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 20 ms 23808 KB Output is correct
11 Correct 19 ms 23936 KB Output is correct
12 Correct 20 ms 23808 KB Output is correct
13 Correct 20 ms 23808 KB Output is correct
14 Correct 22 ms 23808 KB Output is correct
15 Correct 19 ms 23936 KB Output is correct
16 Correct 19 ms 23936 KB Output is correct
17 Correct 21 ms 24192 KB Output is correct
18 Correct 21 ms 24192 KB Output is correct
19 Correct 22 ms 24192 KB Output is correct
20 Correct 22 ms 24192 KB Output is correct
21 Correct 22 ms 24192 KB Output is correct
22 Correct 21 ms 24224 KB Output is correct
23 Correct 22 ms 24192 KB Output is correct
24 Correct 257 ms 47732 KB Output is correct
25 Correct 219 ms 48612 KB Output is correct
26 Correct 260 ms 52216 KB Output is correct
27 Correct 228 ms 51704 KB Output is correct
28 Correct 315 ms 48748 KB Output is correct
29 Correct 189 ms 41208 KB Output is correct
30 Correct 699 ms 57464 KB Output is correct
31 Correct 119 ms 38892 KB Output is correct
32 Correct 120 ms 36352 KB Output is correct
33 Correct 446 ms 51464 KB Output is correct
34 Correct 466 ms 54392 KB Output is correct
35 Correct 627 ms 55288 KB Output is correct
36 Correct 658 ms 54880 KB Output is correct
37 Correct 294 ms 52088 KB Output is correct
38 Correct 261 ms 51576 KB Output is correct
39 Correct 369 ms 55048 KB Output is correct
40 Correct 418 ms 55544 KB Output is correct
41 Correct 18 ms 23808 KB Output is correct
42 Correct 687 ms 57464 KB Output is correct
43 Correct 445 ms 51960 KB Output is correct
44 Correct 504 ms 55160 KB Output is correct
45 Correct 664 ms 56952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 20 ms 23840 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23680 KB Output is correct
5 Correct 18 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 23808 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 20 ms 23808 KB Output is correct
11 Correct 19 ms 23936 KB Output is correct
12 Correct 20 ms 23808 KB Output is correct
13 Correct 20 ms 23808 KB Output is correct
14 Correct 22 ms 23808 KB Output is correct
15 Correct 19 ms 23936 KB Output is correct
16 Correct 19 ms 23936 KB Output is correct
17 Correct 21 ms 24192 KB Output is correct
18 Correct 21 ms 24192 KB Output is correct
19 Correct 22 ms 24192 KB Output is correct
20 Correct 22 ms 24192 KB Output is correct
21 Correct 22 ms 24192 KB Output is correct
22 Correct 21 ms 24224 KB Output is correct
23 Correct 22 ms 24192 KB Output is correct
24 Correct 257 ms 47732 KB Output is correct
25 Correct 219 ms 48612 KB Output is correct
26 Correct 260 ms 52216 KB Output is correct
27 Correct 228 ms 51704 KB Output is correct
28 Correct 315 ms 48748 KB Output is correct
29 Correct 189 ms 41208 KB Output is correct
30 Correct 699 ms 57464 KB Output is correct
31 Correct 119 ms 38892 KB Output is correct
32 Correct 120 ms 36352 KB Output is correct
33 Correct 446 ms 51464 KB Output is correct
34 Correct 466 ms 54392 KB Output is correct
35 Correct 627 ms 55288 KB Output is correct
36 Correct 658 ms 54880 KB Output is correct
37 Correct 294 ms 52088 KB Output is correct
38 Correct 261 ms 51576 KB Output is correct
39 Correct 369 ms 55048 KB Output is correct
40 Correct 418 ms 55544 KB Output is correct
41 Correct 18 ms 23808 KB Output is correct
42 Correct 687 ms 57464 KB Output is correct
43 Correct 445 ms 51960 KB Output is correct
44 Correct 504 ms 55160 KB Output is correct
45 Correct 664 ms 56952 KB Output is correct
46 Correct 1449 ms 137336 KB Output is correct
47 Correct 1236 ms 135392 KB Output is correct
48 Correct 1851 ms 156556 KB Output is correct
49 Correct 2017 ms 157048 KB Output is correct
50 Correct 4292 ms 164236 KB Output is correct
51 Correct 2513 ms 129792 KB Output is correct
52 Correct 2618 ms 139964 KB Output is correct
53 Correct 3916 ms 161168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 366 ms 55800 KB Output is correct
2 Correct 362 ms 54916 KB Output is correct
3 Correct 217 ms 41080 KB Output is correct
4 Correct 316 ms 49656 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 364 ms 52088 KB Output is correct
7 Correct 118 ms 33016 KB Output is correct
8 Correct 114 ms 33016 KB Output is correct
9 Correct 212 ms 41208 KB Output is correct
10 Correct 374 ms 53624 KB Output is correct
11 Correct 172 ms 39928 KB Output is correct
12 Correct 19 ms 23808 KB Output is correct
13 Correct 20 ms 23840 KB Output is correct
14 Correct 19 ms 23808 KB Output is correct
15 Correct 19 ms 23680 KB Output is correct
16 Correct 18 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 23808 KB Output is correct
20 Correct 18 ms 23808 KB Output is correct
21 Correct 20 ms 23808 KB Output is correct
22 Correct 19 ms 23936 KB Output is correct
23 Correct 20 ms 23808 KB Output is correct
24 Correct 20 ms 23808 KB Output is correct
25 Correct 22 ms 23808 KB Output is correct
26 Correct 19 ms 23936 KB Output is correct
27 Correct 19 ms 23936 KB Output is correct
28 Correct 21 ms 24192 KB Output is correct
29 Correct 21 ms 24192 KB Output is correct
30 Correct 22 ms 24192 KB Output is correct
31 Correct 22 ms 24192 KB Output is correct
32 Correct 22 ms 24192 KB Output is correct
33 Correct 21 ms 24224 KB Output is correct
34 Correct 22 ms 24192 KB Output is correct
35 Correct 257 ms 47732 KB Output is correct
36 Correct 219 ms 48612 KB Output is correct
37 Correct 260 ms 52216 KB Output is correct
38 Correct 228 ms 51704 KB Output is correct
39 Correct 315 ms 48748 KB Output is correct
40 Correct 189 ms 41208 KB Output is correct
41 Correct 699 ms 57464 KB Output is correct
42 Correct 119 ms 38892 KB Output is correct
43 Correct 120 ms 36352 KB Output is correct
44 Correct 446 ms 51464 KB Output is correct
45 Correct 466 ms 54392 KB Output is correct
46 Correct 627 ms 55288 KB Output is correct
47 Correct 658 ms 54880 KB Output is correct
48 Correct 294 ms 52088 KB Output is correct
49 Correct 261 ms 51576 KB Output is correct
50 Correct 369 ms 55048 KB Output is correct
51 Correct 418 ms 55544 KB Output is correct
52 Correct 18 ms 23808 KB Output is correct
53 Correct 687 ms 57464 KB Output is correct
54 Correct 445 ms 51960 KB Output is correct
55 Correct 504 ms 55160 KB Output is correct
56 Correct 664 ms 56952 KB Output is correct
57 Correct 260 ms 53624 KB Output is correct
58 Correct 290 ms 54264 KB Output is correct
59 Correct 549 ms 57592 KB Output is correct
60 Correct 284 ms 56952 KB Output is correct
61 Correct 457 ms 59384 KB Output is correct
62 Correct 19 ms 23808 KB Output is correct
63 Correct 742 ms 59424 KB Output is correct
64 Correct 452 ms 53240 KB Output is correct
65 Correct 551 ms 56440 KB Output is correct
66 Correct 645 ms 57208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 366 ms 55800 KB Output is correct
2 Correct 362 ms 54916 KB Output is correct
3 Correct 217 ms 41080 KB Output is correct
4 Correct 316 ms 49656 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 364 ms 52088 KB Output is correct
7 Correct 118 ms 33016 KB Output is correct
8 Correct 114 ms 33016 KB Output is correct
9 Correct 212 ms 41208 KB Output is correct
10 Correct 374 ms 53624 KB Output is correct
11 Correct 172 ms 39928 KB Output is correct
12 Correct 19 ms 23808 KB Output is correct
13 Correct 20 ms 23840 KB Output is correct
14 Correct 19 ms 23808 KB Output is correct
15 Correct 19 ms 23680 KB Output is correct
16 Correct 18 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 23808 KB Output is correct
20 Correct 18 ms 23808 KB Output is correct
21 Correct 20 ms 23808 KB Output is correct
22 Correct 19 ms 23936 KB Output is correct
23 Correct 20 ms 23808 KB Output is correct
24 Correct 20 ms 23808 KB Output is correct
25 Correct 22 ms 23808 KB Output is correct
26 Correct 19 ms 23936 KB Output is correct
27 Correct 19 ms 23936 KB Output is correct
28 Correct 21 ms 24192 KB Output is correct
29 Correct 21 ms 24192 KB Output is correct
30 Correct 22 ms 24192 KB Output is correct
31 Correct 22 ms 24192 KB Output is correct
32 Correct 22 ms 24192 KB Output is correct
33 Correct 21 ms 24224 KB Output is correct
34 Correct 22 ms 24192 KB Output is correct
35 Correct 257 ms 47732 KB Output is correct
36 Correct 219 ms 48612 KB Output is correct
37 Correct 260 ms 52216 KB Output is correct
38 Correct 228 ms 51704 KB Output is correct
39 Correct 315 ms 48748 KB Output is correct
40 Correct 189 ms 41208 KB Output is correct
41 Correct 699 ms 57464 KB Output is correct
42 Correct 119 ms 38892 KB Output is correct
43 Correct 120 ms 36352 KB Output is correct
44 Correct 446 ms 51464 KB Output is correct
45 Correct 466 ms 54392 KB Output is correct
46 Correct 627 ms 55288 KB Output is correct
47 Correct 658 ms 54880 KB Output is correct
48 Correct 294 ms 52088 KB Output is correct
49 Correct 261 ms 51576 KB Output is correct
50 Correct 369 ms 55048 KB Output is correct
51 Correct 418 ms 55544 KB Output is correct
52 Correct 18 ms 23808 KB Output is correct
53 Correct 687 ms 57464 KB Output is correct
54 Correct 445 ms 51960 KB Output is correct
55 Correct 504 ms 55160 KB Output is correct
56 Correct 664 ms 56952 KB Output is correct
57 Correct 1449 ms 137336 KB Output is correct
58 Correct 1236 ms 135392 KB Output is correct
59 Correct 1851 ms 156556 KB Output is correct
60 Correct 2017 ms 157048 KB Output is correct
61 Correct 4292 ms 164236 KB Output is correct
62 Correct 2513 ms 129792 KB Output is correct
63 Correct 2618 ms 139964 KB Output is correct
64 Correct 3916 ms 161168 KB Output is correct
65 Correct 260 ms 53624 KB Output is correct
66 Correct 290 ms 54264 KB Output is correct
67 Correct 549 ms 57592 KB Output is correct
68 Correct 284 ms 56952 KB Output is correct
69 Correct 457 ms 59384 KB Output is correct
70 Correct 19 ms 23808 KB Output is correct
71 Correct 742 ms 59424 KB Output is correct
72 Correct 452 ms 53240 KB Output is correct
73 Correct 551 ms 56440 KB Output is correct
74 Correct 645 ms 57208 KB Output is correct
75 Correct 1218 ms 134648 KB Output is correct
76 Correct 1469 ms 136536 KB Output is correct
77 Correct 2847 ms 154680 KB Output is correct
78 Correct 1317 ms 150136 KB Output is correct
79 Correct 4435 ms 163408 KB Output is correct
80 Correct 2505 ms 129384 KB Output is correct
81 Correct 2979 ms 142096 KB Output is correct
82 Correct 4220 ms 162620 KB Output is correct
83 Correct 4265 ms 159044 KB Output is correct