Submission #246501

# Submission time Handle Problem Language Result Execution time Memory
246501 2020-07-09T13:21:04 Z red1108 Two Dishes (JOI19_dishes) C++17
5 / 100
524 ms 79088 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, ret;
	if(i<=m){
		prop(x*2+1, m+1, r);
		ret = get_val(x*2, l, m,i);
	}
	else{
		prop(x*2, l, m);
		ret = get_val(x*2+1, m+1, r, i);
	}
	seg[x] = max(seg[x*2], seg[x*2+1]);
	return ret;
}
int get_left(int x, int l, int r, ll v){
	prop(x,l,r);
	if(l==r) return l;
	int m = (l+r)/2, ret;

	if(seg[x*2]>=v){
		prop(x*2+1,m+1,r);
		ret = get_left(x*2, l,(l+r)/2, v);
	}
	else {
		prop(x*2,l,m);
		ret = get_left(x*2+1, (l+r)/2+1, r, v);
	}
	seg[x] = max(seg[x*2], seg[x*2+1]);
	return ret;
}
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 463 ms 78548 KB Output is correct
2 Correct 510 ms 79088 KB Output is correct
3 Correct 456 ms 78100 KB Output is correct
4 Correct 399 ms 71128 KB Output is correct
5 Correct 31 ms 47352 KB Output is correct
6 Correct 489 ms 78384 KB Output is correct
7 Correct 237 ms 64608 KB Output is correct
8 Correct 137 ms 60664 KB Output is correct
9 Correct 524 ms 78172 KB Output is correct
10 Correct 465 ms 78328 KB Output is correct
11 Correct 385 ms 78300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 34 ms 47360 KB Output is correct
3 Correct 30 ms 47352 KB Output is correct
4 Correct 30 ms 47352 KB Output is correct
5 Correct 31 ms 47360 KB Output is correct
6 Correct 31 ms 47360 KB Output is correct
7 Correct 32 ms 47360 KB Output is correct
8 Correct 30 ms 47352 KB Output is correct
9 Correct 29 ms 47360 KB Output is correct
10 Correct 30 ms 47404 KB Output is correct
11 Correct 38 ms 47360 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 30 ms 47352 KB Output is correct
14 Correct 29 ms 47360 KB Output is correct
15 Incorrect 29 ms 47360 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 34 ms 47360 KB Output is correct
3 Correct 30 ms 47352 KB Output is correct
4 Correct 30 ms 47352 KB Output is correct
5 Correct 31 ms 47360 KB Output is correct
6 Correct 31 ms 47360 KB Output is correct
7 Correct 32 ms 47360 KB Output is correct
8 Correct 30 ms 47352 KB Output is correct
9 Correct 29 ms 47360 KB Output is correct
10 Correct 30 ms 47404 KB Output is correct
11 Correct 38 ms 47360 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 30 ms 47352 KB Output is correct
14 Correct 29 ms 47360 KB Output is correct
15 Incorrect 29 ms 47360 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 34 ms 47360 KB Output is correct
3 Correct 30 ms 47352 KB Output is correct
4 Correct 30 ms 47352 KB Output is correct
5 Correct 31 ms 47360 KB Output is correct
6 Correct 31 ms 47360 KB Output is correct
7 Correct 32 ms 47360 KB Output is correct
8 Correct 30 ms 47352 KB Output is correct
9 Correct 29 ms 47360 KB Output is correct
10 Correct 30 ms 47404 KB Output is correct
11 Correct 38 ms 47360 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 30 ms 47352 KB Output is correct
14 Correct 29 ms 47360 KB Output is correct
15 Incorrect 29 ms 47360 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 34 ms 47360 KB Output is correct
3 Correct 30 ms 47352 KB Output is correct
4 Correct 30 ms 47352 KB Output is correct
5 Correct 31 ms 47360 KB Output is correct
6 Correct 31 ms 47360 KB Output is correct
7 Correct 32 ms 47360 KB Output is correct
8 Correct 30 ms 47352 KB Output is correct
9 Correct 29 ms 47360 KB Output is correct
10 Correct 30 ms 47404 KB Output is correct
11 Correct 38 ms 47360 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 30 ms 47352 KB Output is correct
14 Correct 29 ms 47360 KB Output is correct
15 Incorrect 29 ms 47360 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 34 ms 47360 KB Output is correct
3 Correct 30 ms 47352 KB Output is correct
4 Correct 30 ms 47352 KB Output is correct
5 Correct 31 ms 47360 KB Output is correct
6 Correct 31 ms 47360 KB Output is correct
7 Correct 32 ms 47360 KB Output is correct
8 Correct 30 ms 47352 KB Output is correct
9 Correct 29 ms 47360 KB Output is correct
10 Correct 30 ms 47404 KB Output is correct
11 Correct 38 ms 47360 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 30 ms 47352 KB Output is correct
14 Correct 29 ms 47360 KB Output is correct
15 Incorrect 29 ms 47360 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 463 ms 78548 KB Output is correct
2 Correct 510 ms 79088 KB Output is correct
3 Correct 456 ms 78100 KB Output is correct
4 Correct 399 ms 71128 KB Output is correct
5 Correct 31 ms 47352 KB Output is correct
6 Correct 489 ms 78384 KB Output is correct
7 Correct 237 ms 64608 KB Output is correct
8 Correct 137 ms 60664 KB Output is correct
9 Correct 524 ms 78172 KB Output is correct
10 Correct 465 ms 78328 KB Output is correct
11 Correct 385 ms 78300 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 34 ms 47360 KB Output is correct
14 Correct 30 ms 47352 KB Output is correct
15 Correct 30 ms 47352 KB Output is correct
16 Correct 31 ms 47360 KB Output is correct
17 Correct 31 ms 47360 KB Output is correct
18 Correct 32 ms 47360 KB Output is correct
19 Correct 30 ms 47352 KB Output is correct
20 Correct 29 ms 47360 KB Output is correct
21 Correct 30 ms 47404 KB Output is correct
22 Correct 38 ms 47360 KB Output is correct
23 Correct 30 ms 47360 KB Output is correct
24 Correct 30 ms 47352 KB Output is correct
25 Correct 29 ms 47360 KB Output is correct
26 Incorrect 29 ms 47360 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 463 ms 78548 KB Output is correct
2 Correct 510 ms 79088 KB Output is correct
3 Correct 456 ms 78100 KB Output is correct
4 Correct 399 ms 71128 KB Output is correct
5 Correct 31 ms 47352 KB Output is correct
6 Correct 489 ms 78384 KB Output is correct
7 Correct 237 ms 64608 KB Output is correct
8 Correct 137 ms 60664 KB Output is correct
9 Correct 524 ms 78172 KB Output is correct
10 Correct 465 ms 78328 KB Output is correct
11 Correct 385 ms 78300 KB Output is correct
12 Correct 30 ms 47360 KB Output is correct
13 Correct 34 ms 47360 KB Output is correct
14 Correct 30 ms 47352 KB Output is correct
15 Correct 30 ms 47352 KB Output is correct
16 Correct 31 ms 47360 KB Output is correct
17 Correct 31 ms 47360 KB Output is correct
18 Correct 32 ms 47360 KB Output is correct
19 Correct 30 ms 47352 KB Output is correct
20 Correct 29 ms 47360 KB Output is correct
21 Correct 30 ms 47404 KB Output is correct
22 Correct 38 ms 47360 KB Output is correct
23 Correct 30 ms 47360 KB Output is correct
24 Correct 30 ms 47352 KB Output is correct
25 Correct 29 ms 47360 KB Output is correct
26 Incorrect 29 ms 47360 KB Output isn't correct
27 Halted 0 ms 0 KB -