Submission #246504

# Submission time Handle Problem Language Result Execution time Memory
246504 2020-07-09T13:24:33 Z red1108 Two Dishes (JOI19_dishes) C++17
8 / 100
457 ms 78708 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[3000100], lazy[3000100], flag[3000100]; // 구간 max, +lazy, fix

void fprop(int x, int l, int r){
	if(flag[x]==-1) return ;
	seg[x] = flag[x];lazy[x]=0;
	if(l!=r){
		flag[x*2]=flag[x];
		flag[x*2+1] = flag[x];
		lazy[x*2]=lazy[x*2+1]=0;
	}
	flag[x]=-1;
}
void prop(int x, int l, int r){
	if(flag[x]!=-1){
		fprop(x,l,r);
		return ;
	}
	if(lazy[x]==0) return ;
	int m = (l+r)/2;
	if(l!=r){
		fprop(x*2, l,m);
		fprop(x*2+1,m+1,r);
		lazy[x*2]+=lazy[x];
		lazy[x*2+1]+=lazy[x];
	}
	seg[x]+=lazy[x];
	lazy[x]=0;
	return ;
}
void add(int x, int l, int r,int s, int e, ll v){
	prop(x,l,r);
	if(r<s||e<l) return ;
	if(s<=l&&r<=e){
		lazy[x]+=v;
		prop(x,l,r);
		return ;
	}
	add(x*2, l, (l+r)/2, s, e, v);add(x*2+1, (l+r)/2+1, r, s, e, v);
	seg[x] = max(seg[x*2], seg[x*2+1]);
}
ll get_val(int x, int l, int r, int i){
	prop(x,l,r);
	if(l==r) return seg[x];
	int  m = (l+r)/2;
	if(i<=m) return get_val(x*2, l, m,i);
	else return get_val(x*2+1, m+1, r, i);
}
int get_left(int x, int l, int r, ll v){
	prop(x,l,r);
	if(l==r) return l;
	if(seg[x*2]>=v) return get_left(x*2, l,(l+r)/2, v);
	return get_left(x*2+1, (l+r)/2+1, r, v);
}
void gang_fix(int x, int l, int r, int s, int e, ll v){
	prop(x,l,r);
	if(r<s||e<l) return ;
	if(s<=l&&r<=e){
		flag[x] = v;
		prop(x,l,r);
		return ;
	}
	gang_fix(x*2,l,(l+r)/2,s,e,v);
	gang_fix(x*2+1,(l+r)/2+1,r,s,e,v);
	seg[x] = max(seg[x*2], seg[x*2+1]);
}
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,bsum+m+1, A[i].lim-asum[i])-bsum-1;
		ans+=A[i].cost;
		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,asum+n+1, B[i].lim-bsum[i])-asum-1;
		ad[j].eb(i,B[i].cost);
	}
	for(int i=1;i<=3000000;i++){
		flag[i]=-1;
	}
	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,m,j.se);
				continue;
			}
			else{
				ll t = get_val(1,0,m,j.fi-1);
				int ind = get_left(1,0,m,t-j.se);
				if(ind==m&&seg[1]<t-j.se){
					gang_fix(1,0,m,j.fi,m,t);
					continue;
				}
				if(j.fi<=ind-1) gang_fix(1,0,m,j.fi,ind-1,t);
				add(1,0,m,ind,m,j.se);
			}
		}
	}
	cout<<ans+seg[1];
}
# Verdict Execution time Memory Grader output
1 Correct 425 ms 77304 KB Output is correct
2 Correct 446 ms 78708 KB Output is correct
3 Correct 389 ms 77788 KB Output is correct
4 Correct 343 ms 70648 KB Output is correct
5 Correct 30 ms 47360 KB Output is correct
6 Correct 457 ms 77808 KB Output is correct
7 Correct 240 ms 64224 KB Output is correct
8 Correct 133 ms 59896 KB Output is correct
9 Correct 400 ms 77660 KB Output is correct
10 Correct 415 ms 77560 KB Output is correct
11 Correct 356 ms 77660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 38 ms 47356 KB Output is correct
3 Correct 32 ms 47360 KB Output is correct
4 Correct 31 ms 47360 KB Output is correct
5 Correct 31 ms 47360 KB Output is correct
6 Correct 32 ms 47360 KB Output is correct
7 Correct 31 ms 47360 KB Output is correct
8 Correct 30 ms 47360 KB Output is correct
9 Correct 31 ms 47360 KB Output is correct
10 Correct 31 ms 47360 KB Output is correct
11 Correct 32 ms 47360 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 29 ms 47360 KB Output is correct
14 Correct 32 ms 47360 KB Output is correct
15 Correct 30 ms 47360 KB Output is correct
16 Correct 30 ms 47360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 38 ms 47356 KB Output is correct
3 Correct 32 ms 47360 KB Output is correct
4 Correct 31 ms 47360 KB Output is correct
5 Correct 31 ms 47360 KB Output is correct
6 Correct 32 ms 47360 KB Output is correct
7 Correct 31 ms 47360 KB Output is correct
8 Correct 30 ms 47360 KB Output is correct
9 Correct 31 ms 47360 KB Output is correct
10 Correct 31 ms 47360 KB Output is correct
11 Correct 32 ms 47360 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 29 ms 47360 KB Output is correct
14 Correct 32 ms 47360 KB Output is correct
15 Correct 30 ms 47360 KB Output is correct
16 Correct 30 ms 47360 KB Output is correct
17 Correct 34 ms 47744 KB Output is correct
18 Correct 32 ms 47744 KB Output is correct
19 Incorrect 37 ms 47744 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 38 ms 47356 KB Output is correct
3 Correct 32 ms 47360 KB Output is correct
4 Correct 31 ms 47360 KB Output is correct
5 Correct 31 ms 47360 KB Output is correct
6 Correct 32 ms 47360 KB Output is correct
7 Correct 31 ms 47360 KB Output is correct
8 Correct 30 ms 47360 KB Output is correct
9 Correct 31 ms 47360 KB Output is correct
10 Correct 31 ms 47360 KB Output is correct
11 Correct 32 ms 47360 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 29 ms 47360 KB Output is correct
14 Correct 32 ms 47360 KB Output is correct
15 Correct 30 ms 47360 KB Output is correct
16 Correct 30 ms 47360 KB Output is correct
17 Correct 34 ms 47744 KB Output is correct
18 Correct 32 ms 47744 KB Output is correct
19 Incorrect 37 ms 47744 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 38 ms 47356 KB Output is correct
3 Correct 32 ms 47360 KB Output is correct
4 Correct 31 ms 47360 KB Output is correct
5 Correct 31 ms 47360 KB Output is correct
6 Correct 32 ms 47360 KB Output is correct
7 Correct 31 ms 47360 KB Output is correct
8 Correct 30 ms 47360 KB Output is correct
9 Correct 31 ms 47360 KB Output is correct
10 Correct 31 ms 47360 KB Output is correct
11 Correct 32 ms 47360 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 29 ms 47360 KB Output is correct
14 Correct 32 ms 47360 KB Output is correct
15 Correct 30 ms 47360 KB Output is correct
16 Correct 30 ms 47360 KB Output is correct
17 Correct 34 ms 47744 KB Output is correct
18 Correct 32 ms 47744 KB Output is correct
19 Incorrect 37 ms 47744 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 38 ms 47356 KB Output is correct
3 Correct 32 ms 47360 KB Output is correct
4 Correct 31 ms 47360 KB Output is correct
5 Correct 31 ms 47360 KB Output is correct
6 Correct 32 ms 47360 KB Output is correct
7 Correct 31 ms 47360 KB Output is correct
8 Correct 30 ms 47360 KB Output is correct
9 Correct 31 ms 47360 KB Output is correct
10 Correct 31 ms 47360 KB Output is correct
11 Correct 32 ms 47360 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 29 ms 47360 KB Output is correct
14 Correct 32 ms 47360 KB Output is correct
15 Correct 30 ms 47360 KB Output is correct
16 Correct 30 ms 47360 KB Output is correct
17 Correct 34 ms 47744 KB Output is correct
18 Correct 32 ms 47744 KB Output is correct
19 Incorrect 37 ms 47744 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 425 ms 77304 KB Output is correct
2 Correct 446 ms 78708 KB Output is correct
3 Correct 389 ms 77788 KB Output is correct
4 Correct 343 ms 70648 KB Output is correct
5 Correct 30 ms 47360 KB Output is correct
6 Correct 457 ms 77808 KB Output is correct
7 Correct 240 ms 64224 KB Output is correct
8 Correct 133 ms 59896 KB Output is correct
9 Correct 400 ms 77660 KB Output is correct
10 Correct 415 ms 77560 KB Output is correct
11 Correct 356 ms 77660 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 38 ms 47356 KB Output is correct
14 Correct 32 ms 47360 KB Output is correct
15 Correct 31 ms 47360 KB Output is correct
16 Correct 31 ms 47360 KB Output is correct
17 Correct 32 ms 47360 KB Output is correct
18 Correct 31 ms 47360 KB Output is correct
19 Correct 30 ms 47360 KB Output is correct
20 Correct 31 ms 47360 KB Output is correct
21 Correct 31 ms 47360 KB Output is correct
22 Correct 32 ms 47360 KB Output is correct
23 Correct 30 ms 47360 KB Output is correct
24 Correct 29 ms 47360 KB Output is correct
25 Correct 32 ms 47360 KB Output is correct
26 Correct 30 ms 47360 KB Output is correct
27 Correct 30 ms 47360 KB Output is correct
28 Correct 34 ms 47744 KB Output is correct
29 Correct 32 ms 47744 KB Output is correct
30 Incorrect 37 ms 47744 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 425 ms 77304 KB Output is correct
2 Correct 446 ms 78708 KB Output is correct
3 Correct 389 ms 77788 KB Output is correct
4 Correct 343 ms 70648 KB Output is correct
5 Correct 30 ms 47360 KB Output is correct
6 Correct 457 ms 77808 KB Output is correct
7 Correct 240 ms 64224 KB Output is correct
8 Correct 133 ms 59896 KB Output is correct
9 Correct 400 ms 77660 KB Output is correct
10 Correct 415 ms 77560 KB Output is correct
11 Correct 356 ms 77660 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 38 ms 47356 KB Output is correct
14 Correct 32 ms 47360 KB Output is correct
15 Correct 31 ms 47360 KB Output is correct
16 Correct 31 ms 47360 KB Output is correct
17 Correct 32 ms 47360 KB Output is correct
18 Correct 31 ms 47360 KB Output is correct
19 Correct 30 ms 47360 KB Output is correct
20 Correct 31 ms 47360 KB Output is correct
21 Correct 31 ms 47360 KB Output is correct
22 Correct 32 ms 47360 KB Output is correct
23 Correct 30 ms 47360 KB Output is correct
24 Correct 29 ms 47360 KB Output is correct
25 Correct 32 ms 47360 KB Output is correct
26 Correct 30 ms 47360 KB Output is correct
27 Correct 30 ms 47360 KB Output is correct
28 Correct 34 ms 47744 KB Output is correct
29 Correct 32 ms 47744 KB Output is correct
30 Incorrect 37 ms 47744 KB Output isn't correct
31 Halted 0 ms 0 KB -