Submission #907242

# Submission time Handle Problem Language Result Execution time Memory
907242 2024-01-15T10:03:40 Z MilosMilutinovic Two Dishes (JOI19_dishes) C++14
100 / 100
5985 ms 291328 KB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,m,a[1000005],p[1000005],b[1000005],q[1000005];
ll s[1000005],t[1000005],pa[1000005],pb[1000005],mx[8000005],inc[8000005],val[8000005];
bool tag[8000005];
vector<pii> qs[1000005];

void pushdown(int id){
	if(tag[id]){
		mx[id<<1]=val[id];
		mx[id<<1|1]=val[id];
		val[id<<1]=val[id];
		val[id<<1|1]=val[id];
		inc[id<<1]=0;
		inc[id<<1|1]=0;
		tag[id<<1]=true;
		tag[id<<1|1]=true;
		inc[id]=0;
		tag[id]=false;
	}else{
		mx[id<<1]+=inc[id];
		mx[id<<1|1]+=inc[id];
		if(tag[id<<1]) val[id<<1]+=inc[id];
		else inc[id<<1]+=inc[id];
		if(tag[id<<1|1]) val[id<<1|1]+=inc[id];
		else inc[id<<1|1]+=inc[id];
		inc[id]=0;
	}
}

void rangeadd(int id,int l,int r,int ql,int qr,ll v){
	if(l>r||ql>qr||l>qr||r<ql) return;
	if(ql<=l&&r<=qr){
		mx[id]+=v;
		if(tag[id]) val[id]+=v;
		else inc[id]+=v;
		pushdown(id);
		return;
	}
	pushdown(id);
	int mid=(l+r)/2;
	rangeadd(id<<1,l,mid,ql,qr,v);
	rangeadd(id<<1|1,mid+1,r,ql,qr,v);
	mx[id]=max(mx[id<<1],mx[id<<1|1]);
}

void rangeset(int id,int l,int r,int ql,int qr,ll v){
	if(l>r||ql>qr||l>qr||r<ql) return;
	if(ql<=l&&r<=qr){
		mx[id]=v;
		val[id]=v;
		tag[id]=true;
		inc[id]=0;
		pushdown(id);
		return;
	}
	pushdown(id);
	int mid=(l+r)/2;
	rangeset(id<<1,l,mid,ql,qr,v);
	rangeset(id<<1|1,mid+1,r,ql,qr,v);
	mx[id]=max(mx[id<<1],mx[id<<1|1]);
}

ll query(int id,int l,int r,int qi){
	if(l==r) return mx[id];
	pushdown(id);
	int mid=(l+r)/2;
	ll ret=0;
	if(qi<=mid) ret=query(id<<1,l,mid,qi);
	else ret=query(id<<1|1,mid+1,r,qi);
	mx[id]=max(mx[id<<1],mx[id<<1|1]);
	return ret;
}

int walk(int id,int l,int r,int qi,ll v){
	if(r<qi||mx[id]<=v) return -1;
	if(l==r) return (mx[id]>v?l:-1);
	pushdown(id);
	int mid=(l+r)/2;
	int ret=walk(id<<1,l,mid,qi,v);
	if(ret==-1) ret=walk(id<<1|1,mid+1,r,qi,v);
	mx[id]=max(mx[id<<1],mx[id<<1|1]);
	return ret;
}

int main() {
	n=readint(); m=readint();
	for(int i=1;i<=n;i++){
		a[i]=readint();
		s[i]=readint();
		p[i]=readint();
	}
	for(int i=1;i<=m;i++){
		b[i]=readint();
		t[i]=readint();
		q[i]=readint();
	}
	for(int i=1;i<=n;i++) pa[i]=pa[i-1]+a[i];
	for(int i=1;i<=m;i++) pb[i]=pb[i-1]+b[i];
	for(int i=1;i<=n;i++){
		if(s[i]<pa[i]) continue;
		int l=1,r=m,pos=0;
		while(l<=r){
			int mid=(l+r)/2;
			if(pa[i]+pb[mid]<=s[i]) pos=mid,l=mid+1;
			else r=mid-1;
		}
		qs[i].pb(mp(pos,p[i]));
	}
	ll res=0;
	for(int i=1;i<=m;i++){
		if(t[i]<pb[i]) continue;
		int l=1,r=n,pos=0;
		while(l<=r){
			int mid=(l+r)/2;
			if(pa[mid]+pb[i]<=t[i]) pos=mid,l=mid+1;
			else r=mid-1;
		}
		res+=q[i];
		qs[pos+1].pb(mp(i-1,-q[i]));
	}
	for(int i=0;i<=n;i++){
		sort(qs[i].begin(),qs[i].end());
		vector<int> xs(1,m);
		for(auto&p:qs[i]){
			rangeadd(1,0,m,0,p.first,p.second);
			xs.push_back(p.first);
		}
		sort(xs.begin(),xs.end());
		xs.erase(unique(xs.begin(),xs.end()),xs.end());
		for(int j=1;j<(int)xs.size();j++){
			ll vl=query(1,0,m,xs[j-1]);
			ll vr=query(1,0,m,xs[j]);
			int p=min(xs[j],walk(1,0,m,xs[j-1],vl)-1);
			if(p<0) p=xs[j];
			rangeset(1,0,m,xs[j-1],p,vl);
		}
	}
	printf("%lld\n",query(1,0,m,m)+res);
	return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:156:7: warning: unused variable 'vr' [-Wunused-variable]
  156 |    ll vr=query(1,0,m,xs[j]);
      |       ^~
# Verdict Execution time Memory Grader output
1 Correct 362 ms 87892 KB Output is correct
2 Correct 355 ms 92116 KB Output is correct
3 Correct 88 ms 69372 KB Output is correct
4 Correct 231 ms 80464 KB Output is correct
5 Correct 11 ms 41560 KB Output is correct
6 Correct 360 ms 91952 KB Output is correct
7 Correct 39 ms 66248 KB Output is correct
8 Correct 54 ms 54968 KB Output is correct
9 Correct 93 ms 69568 KB Output is correct
10 Correct 323 ms 88912 KB Output is correct
11 Correct 69 ms 69420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 41716 KB Output is correct
2 Correct 10 ms 37464 KB Output is correct
3 Correct 10 ms 41564 KB Output is correct
4 Correct 10 ms 41564 KB Output is correct
5 Correct 11 ms 41580 KB Output is correct
6 Correct 10 ms 41564 KB Output is correct
7 Correct 11 ms 41692 KB Output is correct
8 Correct 11 ms 41564 KB Output is correct
9 Correct 11 ms 41564 KB Output is correct
10 Correct 10 ms 41628 KB Output is correct
11 Correct 11 ms 41564 KB Output is correct
12 Correct 10 ms 41564 KB Output is correct
13 Correct 11 ms 41560 KB Output is correct
14 Correct 11 ms 43608 KB Output is correct
15 Correct 10 ms 41564 KB Output is correct
16 Correct 11 ms 41640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 41716 KB Output is correct
2 Correct 10 ms 37464 KB Output is correct
3 Correct 10 ms 41564 KB Output is correct
4 Correct 10 ms 41564 KB Output is correct
5 Correct 11 ms 41580 KB Output is correct
6 Correct 10 ms 41564 KB Output is correct
7 Correct 11 ms 41692 KB Output is correct
8 Correct 11 ms 41564 KB Output is correct
9 Correct 11 ms 41564 KB Output is correct
10 Correct 10 ms 41628 KB Output is correct
11 Correct 11 ms 41564 KB Output is correct
12 Correct 10 ms 41564 KB Output is correct
13 Correct 11 ms 41560 KB Output is correct
14 Correct 11 ms 43608 KB Output is correct
15 Correct 10 ms 41564 KB Output is correct
16 Correct 11 ms 41640 KB Output is correct
17 Correct 12 ms 41564 KB Output is correct
18 Correct 12 ms 41820 KB Output is correct
19 Correct 15 ms 41816 KB Output is correct
20 Correct 13 ms 41820 KB Output is correct
21 Correct 13 ms 41816 KB Output is correct
22 Correct 15 ms 41816 KB Output is correct
23 Correct 14 ms 41820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 41716 KB Output is correct
2 Correct 10 ms 37464 KB Output is correct
3 Correct 10 ms 41564 KB Output is correct
4 Correct 10 ms 41564 KB Output is correct
5 Correct 11 ms 41580 KB Output is correct
6 Correct 10 ms 41564 KB Output is correct
7 Correct 11 ms 41692 KB Output is correct
8 Correct 11 ms 41564 KB Output is correct
9 Correct 11 ms 41564 KB Output is correct
10 Correct 10 ms 41628 KB Output is correct
11 Correct 11 ms 41564 KB Output is correct
12 Correct 10 ms 41564 KB Output is correct
13 Correct 11 ms 41560 KB Output is correct
14 Correct 11 ms 43608 KB Output is correct
15 Correct 10 ms 41564 KB Output is correct
16 Correct 11 ms 41640 KB Output is correct
17 Correct 12 ms 41564 KB Output is correct
18 Correct 12 ms 41820 KB Output is correct
19 Correct 15 ms 41816 KB Output is correct
20 Correct 13 ms 41820 KB Output is correct
21 Correct 13 ms 41816 KB Output is correct
22 Correct 15 ms 41816 KB Output is correct
23 Correct 14 ms 41820 KB Output is correct
24 Correct 183 ms 76816 KB Output is correct
25 Correct 243 ms 89284 KB Output is correct
26 Correct 336 ms 89792 KB Output is correct
27 Correct 276 ms 89036 KB Output is correct
28 Correct 304 ms 89556 KB Output is correct
29 Correct 86 ms 69584 KB Output is correct
30 Correct 909 ms 90936 KB Output is correct
31 Correct 127 ms 78044 KB Output is correct
32 Correct 60 ms 55012 KB Output is correct
33 Correct 489 ms 87128 KB Output is correct
34 Correct 702 ms 91060 KB Output is correct
35 Correct 959 ms 91024 KB Output is correct
36 Correct 917 ms 90880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 41716 KB Output is correct
2 Correct 10 ms 37464 KB Output is correct
3 Correct 10 ms 41564 KB Output is correct
4 Correct 10 ms 41564 KB Output is correct
5 Correct 11 ms 41580 KB Output is correct
6 Correct 10 ms 41564 KB Output is correct
7 Correct 11 ms 41692 KB Output is correct
8 Correct 11 ms 41564 KB Output is correct
9 Correct 11 ms 41564 KB Output is correct
10 Correct 10 ms 41628 KB Output is correct
11 Correct 11 ms 41564 KB Output is correct
12 Correct 10 ms 41564 KB Output is correct
13 Correct 11 ms 41560 KB Output is correct
14 Correct 11 ms 43608 KB Output is correct
15 Correct 10 ms 41564 KB Output is correct
16 Correct 11 ms 41640 KB Output is correct
17 Correct 12 ms 41564 KB Output is correct
18 Correct 12 ms 41820 KB Output is correct
19 Correct 15 ms 41816 KB Output is correct
20 Correct 13 ms 41820 KB Output is correct
21 Correct 13 ms 41816 KB Output is correct
22 Correct 15 ms 41816 KB Output is correct
23 Correct 14 ms 41820 KB Output is correct
24 Correct 183 ms 76816 KB Output is correct
25 Correct 243 ms 89284 KB Output is correct
26 Correct 336 ms 89792 KB Output is correct
27 Correct 276 ms 89036 KB Output is correct
28 Correct 304 ms 89556 KB Output is correct
29 Correct 86 ms 69584 KB Output is correct
30 Correct 909 ms 90936 KB Output is correct
31 Correct 127 ms 78044 KB Output is correct
32 Correct 60 ms 55012 KB Output is correct
33 Correct 489 ms 87128 KB Output is correct
34 Correct 702 ms 91060 KB Output is correct
35 Correct 959 ms 91024 KB Output is correct
36 Correct 917 ms 90880 KB Output is correct
37 Correct 283 ms 89928 KB Output is correct
38 Correct 319 ms 88984 KB Output is correct
39 Correct 364 ms 89032 KB Output is correct
40 Correct 420 ms 88916 KB Output is correct
41 Correct 13 ms 41564 KB Output is correct
42 Correct 919 ms 90796 KB Output is correct
43 Correct 545 ms 87232 KB Output is correct
44 Correct 601 ms 92480 KB Output is correct
45 Correct 941 ms 91044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 41716 KB Output is correct
2 Correct 10 ms 37464 KB Output is correct
3 Correct 10 ms 41564 KB Output is correct
4 Correct 10 ms 41564 KB Output is correct
5 Correct 11 ms 41580 KB Output is correct
6 Correct 10 ms 41564 KB Output is correct
7 Correct 11 ms 41692 KB Output is correct
8 Correct 11 ms 41564 KB Output is correct
9 Correct 11 ms 41564 KB Output is correct
10 Correct 10 ms 41628 KB Output is correct
11 Correct 11 ms 41564 KB Output is correct
12 Correct 10 ms 41564 KB Output is correct
13 Correct 11 ms 41560 KB Output is correct
14 Correct 11 ms 43608 KB Output is correct
15 Correct 10 ms 41564 KB Output is correct
16 Correct 11 ms 41640 KB Output is correct
17 Correct 12 ms 41564 KB Output is correct
18 Correct 12 ms 41820 KB Output is correct
19 Correct 15 ms 41816 KB Output is correct
20 Correct 13 ms 41820 KB Output is correct
21 Correct 13 ms 41816 KB Output is correct
22 Correct 15 ms 41816 KB Output is correct
23 Correct 14 ms 41820 KB Output is correct
24 Correct 183 ms 76816 KB Output is correct
25 Correct 243 ms 89284 KB Output is correct
26 Correct 336 ms 89792 KB Output is correct
27 Correct 276 ms 89036 KB Output is correct
28 Correct 304 ms 89556 KB Output is correct
29 Correct 86 ms 69584 KB Output is correct
30 Correct 909 ms 90936 KB Output is correct
31 Correct 127 ms 78044 KB Output is correct
32 Correct 60 ms 55012 KB Output is correct
33 Correct 489 ms 87128 KB Output is correct
34 Correct 702 ms 91060 KB Output is correct
35 Correct 959 ms 91024 KB Output is correct
36 Correct 917 ms 90880 KB Output is correct
37 Correct 283 ms 89928 KB Output is correct
38 Correct 319 ms 88984 KB Output is correct
39 Correct 364 ms 89032 KB Output is correct
40 Correct 420 ms 88916 KB Output is correct
41 Correct 13 ms 41564 KB Output is correct
42 Correct 919 ms 90796 KB Output is correct
43 Correct 545 ms 87232 KB Output is correct
44 Correct 601 ms 92480 KB Output is correct
45 Correct 941 ms 91044 KB Output is correct
46 Correct 1426 ms 214956 KB Output is correct
47 Correct 1568 ms 206728 KB Output is correct
48 Correct 1804 ms 210816 KB Output is correct
49 Correct 2253 ms 210932 KB Output is correct
50 Correct 5743 ms 220756 KB Output is correct
51 Correct 2910 ms 267992 KB Output is correct
52 Correct 3658 ms 286652 KB Output is correct
53 Correct 5482 ms 258696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 87892 KB Output is correct
2 Correct 355 ms 92116 KB Output is correct
3 Correct 88 ms 69372 KB Output is correct
4 Correct 231 ms 80464 KB Output is correct
5 Correct 11 ms 41560 KB Output is correct
6 Correct 360 ms 91952 KB Output is correct
7 Correct 39 ms 66248 KB Output is correct
8 Correct 54 ms 54968 KB Output is correct
9 Correct 93 ms 69568 KB Output is correct
10 Correct 323 ms 88912 KB Output is correct
11 Correct 69 ms 69420 KB Output is correct
12 Correct 12 ms 41716 KB Output is correct
13 Correct 10 ms 37464 KB Output is correct
14 Correct 10 ms 41564 KB Output is correct
15 Correct 10 ms 41564 KB Output is correct
16 Correct 11 ms 41580 KB Output is correct
17 Correct 10 ms 41564 KB Output is correct
18 Correct 11 ms 41692 KB Output is correct
19 Correct 11 ms 41564 KB Output is correct
20 Correct 11 ms 41564 KB Output is correct
21 Correct 10 ms 41628 KB Output is correct
22 Correct 11 ms 41564 KB Output is correct
23 Correct 10 ms 41564 KB Output is correct
24 Correct 11 ms 41560 KB Output is correct
25 Correct 11 ms 43608 KB Output is correct
26 Correct 10 ms 41564 KB Output is correct
27 Correct 11 ms 41640 KB Output is correct
28 Correct 12 ms 41564 KB Output is correct
29 Correct 12 ms 41820 KB Output is correct
30 Correct 15 ms 41816 KB Output is correct
31 Correct 13 ms 41820 KB Output is correct
32 Correct 13 ms 41816 KB Output is correct
33 Correct 15 ms 41816 KB Output is correct
34 Correct 14 ms 41820 KB Output is correct
35 Correct 183 ms 76816 KB Output is correct
36 Correct 243 ms 89284 KB Output is correct
37 Correct 336 ms 89792 KB Output is correct
38 Correct 276 ms 89036 KB Output is correct
39 Correct 304 ms 89556 KB Output is correct
40 Correct 86 ms 69584 KB Output is correct
41 Correct 909 ms 90936 KB Output is correct
42 Correct 127 ms 78044 KB Output is correct
43 Correct 60 ms 55012 KB Output is correct
44 Correct 489 ms 87128 KB Output is correct
45 Correct 702 ms 91060 KB Output is correct
46 Correct 959 ms 91024 KB Output is correct
47 Correct 917 ms 90880 KB Output is correct
48 Correct 283 ms 89928 KB Output is correct
49 Correct 319 ms 88984 KB Output is correct
50 Correct 364 ms 89032 KB Output is correct
51 Correct 420 ms 88916 KB Output is correct
52 Correct 13 ms 41564 KB Output is correct
53 Correct 919 ms 90796 KB Output is correct
54 Correct 545 ms 87232 KB Output is correct
55 Correct 601 ms 92480 KB Output is correct
56 Correct 941 ms 91044 KB Output is correct
57 Correct 281 ms 89880 KB Output is correct
58 Correct 261 ms 88912 KB Output is correct
59 Correct 391 ms 88916 KB Output is correct
60 Correct 357 ms 89168 KB Output is correct
61 Correct 784 ms 91040 KB Output is correct
62 Correct 11 ms 41560 KB Output is correct
63 Correct 817 ms 90936 KB Output is correct
64 Correct 435 ms 87120 KB Output is correct
65 Correct 648 ms 90768 KB Output is correct
66 Correct 794 ms 90892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 87892 KB Output is correct
2 Correct 355 ms 92116 KB Output is correct
3 Correct 88 ms 69372 KB Output is correct
4 Correct 231 ms 80464 KB Output is correct
5 Correct 11 ms 41560 KB Output is correct
6 Correct 360 ms 91952 KB Output is correct
7 Correct 39 ms 66248 KB Output is correct
8 Correct 54 ms 54968 KB Output is correct
9 Correct 93 ms 69568 KB Output is correct
10 Correct 323 ms 88912 KB Output is correct
11 Correct 69 ms 69420 KB Output is correct
12 Correct 12 ms 41716 KB Output is correct
13 Correct 10 ms 37464 KB Output is correct
14 Correct 10 ms 41564 KB Output is correct
15 Correct 10 ms 41564 KB Output is correct
16 Correct 11 ms 41580 KB Output is correct
17 Correct 10 ms 41564 KB Output is correct
18 Correct 11 ms 41692 KB Output is correct
19 Correct 11 ms 41564 KB Output is correct
20 Correct 11 ms 41564 KB Output is correct
21 Correct 10 ms 41628 KB Output is correct
22 Correct 11 ms 41564 KB Output is correct
23 Correct 10 ms 41564 KB Output is correct
24 Correct 11 ms 41560 KB Output is correct
25 Correct 11 ms 43608 KB Output is correct
26 Correct 10 ms 41564 KB Output is correct
27 Correct 11 ms 41640 KB Output is correct
28 Correct 12 ms 41564 KB Output is correct
29 Correct 12 ms 41820 KB Output is correct
30 Correct 15 ms 41816 KB Output is correct
31 Correct 13 ms 41820 KB Output is correct
32 Correct 13 ms 41816 KB Output is correct
33 Correct 15 ms 41816 KB Output is correct
34 Correct 14 ms 41820 KB Output is correct
35 Correct 183 ms 76816 KB Output is correct
36 Correct 243 ms 89284 KB Output is correct
37 Correct 336 ms 89792 KB Output is correct
38 Correct 276 ms 89036 KB Output is correct
39 Correct 304 ms 89556 KB Output is correct
40 Correct 86 ms 69584 KB Output is correct
41 Correct 909 ms 90936 KB Output is correct
42 Correct 127 ms 78044 KB Output is correct
43 Correct 60 ms 55012 KB Output is correct
44 Correct 489 ms 87128 KB Output is correct
45 Correct 702 ms 91060 KB Output is correct
46 Correct 959 ms 91024 KB Output is correct
47 Correct 917 ms 90880 KB Output is correct
48 Correct 283 ms 89928 KB Output is correct
49 Correct 319 ms 88984 KB Output is correct
50 Correct 364 ms 89032 KB Output is correct
51 Correct 420 ms 88916 KB Output is correct
52 Correct 13 ms 41564 KB Output is correct
53 Correct 919 ms 90796 KB Output is correct
54 Correct 545 ms 87232 KB Output is correct
55 Correct 601 ms 92480 KB Output is correct
56 Correct 941 ms 91044 KB Output is correct
57 Correct 1426 ms 214956 KB Output is correct
58 Correct 1568 ms 206728 KB Output is correct
59 Correct 1804 ms 210816 KB Output is correct
60 Correct 2253 ms 210932 KB Output is correct
61 Correct 5743 ms 220756 KB Output is correct
62 Correct 2910 ms 267992 KB Output is correct
63 Correct 3658 ms 286652 KB Output is correct
64 Correct 5482 ms 258696 KB Output is correct
65 Correct 281 ms 89880 KB Output is correct
66 Correct 261 ms 88912 KB Output is correct
67 Correct 391 ms 88916 KB Output is correct
68 Correct 357 ms 89168 KB Output is correct
69 Correct 784 ms 91040 KB Output is correct
70 Correct 11 ms 41560 KB Output is correct
71 Correct 817 ms 90936 KB Output is correct
72 Correct 435 ms 87120 KB Output is correct
73 Correct 648 ms 90768 KB Output is correct
74 Correct 794 ms 90892 KB Output is correct
75 Correct 1524 ms 281344 KB Output is correct
76 Correct 1470 ms 282780 KB Output is correct
77 Correct 2104 ms 269644 KB Output is correct
78 Correct 1893 ms 269704 KB Output is correct
79 Correct 5730 ms 291328 KB Output is correct
80 Correct 2937 ms 268904 KB Output is correct
81 Correct 3927 ms 282360 KB Output is correct
82 Correct 5985 ms 257688 KB Output is correct
83 Correct 5546 ms 277948 KB Output is correct