Submission #709642

# Submission time Handle Problem Language Result Execution time Memory
709642 2023-03-14T05:29:43 Z alvingogo Two Dishes (JOI19_dishes) C++14
74 / 100
5885 ms 335748 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
#define int long long
using namespace std;

const int inf=1e18;
struct ST{
	vector<pair<int,int> > st;
	void init(int x){
		st.resize(4*x);
	}
	void upd(int v,int x){
		st[v].fs+=x;
		st[v].sc+=x;
	}
	void pudo(int v){
		upd(2*v+1,st[v].sc);
		upd(2*v+2,st[v].sc);
		st[v].sc=0;
	}
	void pull(int v){
		st[v].fs=max(st[2*v+1].fs,st[2*v+2].fs);
	}
	void update(int v,int L,int R,int l,int r,int k){
		if(L==l && r==R){
			upd(v,k);
			return;
		}
		int m=(L+R)/2;
		pudo(v);
		if(r<=m){
			update(2*v+1,L,m,l,r,k);
		}
		else if(l>m){
			update(2*v+2,m+1,R,l,r,k);
		}
		else{
			update(2*v+1,L,m,l,m,k);
			update(2*v+2,m+1,R,m+1,r,k);
		}
		pull(v);
	}
	int query(int v,int L,int R,int l,int r){
		if(L==l && r==R){
			return st[v].fs;
		}
		pudo(v);
		int m=(L+R)/2;
		if(r<=m){
			return query(2*v+1,L,m,l,r);
		}
		else if(l>m){
			return query(2*v+2,m+1,R,l,r);
		}
		else{
			return max(query(2*v+1,L,m,l,m),query(2*v+2,m+1,R,m+1,r));
		}
	}
}st;

struct BIT{
	int n;
	vector<int> bt;
	void init(int x){
		n=x;
		bt.resize(n+1);
	}
	void update(int x,int y){
		for(;x>0;x-=(x&-x)){
			bt[x]+=y;
		}
	}
	int query(int x){
		int ans=0;
		for(;x<=n;x+=(x&-x)){
			ans+=bt[x];
		}
		return ans;
	}
}bt,bt2;


bool cmp(pair<int,int> a,pair<int,int> b){
	return a.sc!=b.sc?a.sc<b.sc:a.fs<b.fs;
}
signed main(){
    AquA;
	int n,m;
	cin >> n >> m;
	vector<int> a(n+1),b(m+1),s(n+1),t(m+1),p(n+1),q(m+1);
	for(int i=1;i<=n;i++){
		cin >> a[i] >> s[i] >> p[i];
		a[i]+=a[i-1];
	}
	for(int j=1;j<=m;j++){
		cin >> b[j] >> t[j] >> q[j];
		b[j]+=b[j-1];
	}
	vector<pair<int,int> > gg;
	vector<int> oka(n+1),okb(m+1);
	vector<pair<int,int> > to;
	vector<int> vis(n+1);
	for(int i=1;i<=n;i++){
		oka[i]=upper_bound(b.begin(),b.end(),s[i]-a[i])-b.begin()-1;
		to.push_back({oka[i],i});
	}
	int y=0;
	for(int i=1;i<=m;i++){
		okb[i]=upper_bound(a.begin(),a.end(),t[i]-b[i])-a.begin()-1;
		if(okb[i]==n+1){
			y+=q[i];
		}
		else{
			to.push_back({i-1,okb[i]+1});
		}
	}
	/*
	for(int i=1;i<=n;i++){
		cout << oka[i] << " ";
	}
	cout << "\n";
	for(int j=1;j<=m;j++){
		cout << okb[j] << " ";
	}
	cout << "\n";
	*/
	sort(to.begin(),to.end());
	to.erase(unique(to.begin(),to.end()),to.end());
	gg=to;
	sort(gg.begin(),gg.end(),cmp);
	n=gg.size();
	vector<int> newp(n+1);
	for(auto h:gg){
		//cout << h.fs << " " << h.sc << endl;
	}
	for(auto &h:to){
		if(h.fs<0){
			continue;
		}
		int flag=-1;
		if(!vis[h.sc] && h.fs==oka[h.sc]){
			vis[h.sc]=1;
			flag=h.sc;
		}
		h.sc=lower_bound(gg.begin(),gg.end(),h,cmp)-gg.begin()+1;
		if(flag>=0){
			newp[h.sc]=p[flag];
		}
	}
	st.init(n+1);
	bt.init(n);
	bt2.init(n);
	st.update(0,0,n,1,n,-inf);
	for(int i=1;i<=n;i++){
		if(newp[i]){
			//cout << i << "f" << newp[i] << "\n";
			st.update(0,0,n,0,i-1,newp[i]);
			bt.update(i,newp[i]);
		}
	}
	for(auto h:to){
		//cout << h.fs << " " << h.sc << "\n";
	}
	
	//cout << "\n";
	int l=0;
	while(l<(int)to.size() && to[l].fs<0){
		l++;
	}
	vector<int> dp(n+1);
	for(int i=1;i<=m;i++){
		if(okb[i]>=0){
			okb[i]=lower_bound(gg.begin(),gg.end(),pair<int,int>(-inf,okb[i]+1),cmp)-gg.begin();
			//cout << okb[i] << "\n";
		}
	}
	for(int i=0;i<=m;i++){
		if(i>0 && okb[i]>=0){
			st.update(0,0,n,0,okb[i],q[i]);
			bt2.update(okb[i],q[i]);
		}
		while(l<(int)to.size() && to[l].fs==i){
			int x=to[l].sc;
			dp[x]=st.query(0,0,n,0,x-1)-bt.query(x+1);
			//cout << x << " " << dp[x] << endl;
			st.update(0,0,n,x,x,dp[x]+inf-bt2.query(x));
			st.update(0,0,n,0,x-1,-newp[x]);
			bt.update(x,-newp[x]);
			l++;
		}
	}
	cout << st.query(0,0,n,0,n) << "\n";
    return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:137:11: warning: variable 'h' set but not used [-Wunused-but-set-variable]
  137 |  for(auto h:gg){
      |           ^
dishes.cpp:165:11: warning: variable 'h' set but not used [-Wunused-but-set-variable]
  165 |  for(auto h:to){
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 444 ms 53936 KB Output is correct
2 Correct 458 ms 53228 KB Output is correct
3 Correct 451 ms 67104 KB Output is correct
4 Correct 387 ms 53100 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 494 ms 53972 KB Output is correct
7 Correct 264 ms 34928 KB Output is correct
8 Correct 257 ms 36556 KB Output is correct
9 Correct 459 ms 66992 KB Output is correct
10 Correct 377 ms 45488 KB Output is correct
11 Correct 420 ms 67516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 4 ms 1024 KB Output is correct
18 Correct 4 ms 1108 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 5 ms 980 KB Output is correct
21 Correct 6 ms 1028 KB Output is correct
22 Correct 6 ms 976 KB Output is correct
23 Correct 5 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 4 ms 1024 KB Output is correct
18 Correct 4 ms 1108 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 5 ms 980 KB Output is correct
21 Correct 6 ms 1028 KB Output is correct
22 Correct 6 ms 976 KB Output is correct
23 Correct 5 ms 964 KB Output is correct
24 Correct 473 ms 67284 KB Output is correct
25 Correct 432 ms 67092 KB Output is correct
26 Correct 514 ms 67032 KB Output is correct
27 Correct 450 ms 67096 KB Output is correct
28 Correct 616 ms 67124 KB Output is correct
29 Correct 422 ms 66716 KB Output is correct
30 Correct 861 ms 66964 KB Output is correct
31 Correct 256 ms 32828 KB Output is correct
32 Correct 246 ms 34756 KB Output is correct
33 Correct 639 ms 66120 KB Output is correct
34 Correct 795 ms 65488 KB Output is correct
35 Correct 832 ms 65712 KB Output is correct
36 Correct 842 ms 65592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 4 ms 1024 KB Output is correct
18 Correct 4 ms 1108 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 5 ms 980 KB Output is correct
21 Correct 6 ms 1028 KB Output is correct
22 Correct 6 ms 976 KB Output is correct
23 Correct 5 ms 964 KB Output is correct
24 Correct 473 ms 67284 KB Output is correct
25 Correct 432 ms 67092 KB Output is correct
26 Correct 514 ms 67032 KB Output is correct
27 Correct 450 ms 67096 KB Output is correct
28 Correct 616 ms 67124 KB Output is correct
29 Correct 422 ms 66716 KB Output is correct
30 Correct 861 ms 66964 KB Output is correct
31 Correct 256 ms 32828 KB Output is correct
32 Correct 246 ms 34756 KB Output is correct
33 Correct 639 ms 66120 KB Output is correct
34 Correct 795 ms 65488 KB Output is correct
35 Correct 832 ms 65712 KB Output is correct
36 Correct 842 ms 65592 KB Output is correct
37 Correct 544 ms 66204 KB Output is correct
38 Correct 486 ms 66108 KB Output is correct
39 Correct 396 ms 44356 KB Output is correct
40 Correct 372 ms 44112 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 945 ms 66112 KB Output is correct
43 Correct 624 ms 65092 KB Output is correct
44 Correct 812 ms 64544 KB Output is correct
45 Correct 881 ms 66544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 4 ms 1024 KB Output is correct
18 Correct 4 ms 1108 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 5 ms 980 KB Output is correct
21 Correct 6 ms 1028 KB Output is correct
22 Correct 6 ms 976 KB Output is correct
23 Correct 5 ms 964 KB Output is correct
24 Correct 473 ms 67284 KB Output is correct
25 Correct 432 ms 67092 KB Output is correct
26 Correct 514 ms 67032 KB Output is correct
27 Correct 450 ms 67096 KB Output is correct
28 Correct 616 ms 67124 KB Output is correct
29 Correct 422 ms 66716 KB Output is correct
30 Correct 861 ms 66964 KB Output is correct
31 Correct 256 ms 32828 KB Output is correct
32 Correct 246 ms 34756 KB Output is correct
33 Correct 639 ms 66120 KB Output is correct
34 Correct 795 ms 65488 KB Output is correct
35 Correct 832 ms 65712 KB Output is correct
36 Correct 842 ms 65592 KB Output is correct
37 Correct 544 ms 66204 KB Output is correct
38 Correct 486 ms 66108 KB Output is correct
39 Correct 396 ms 44356 KB Output is correct
40 Correct 372 ms 44112 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 945 ms 66112 KB Output is correct
43 Correct 624 ms 65092 KB Output is correct
44 Correct 812 ms 64544 KB Output is correct
45 Correct 881 ms 66544 KB Output is correct
46 Correct 3043 ms 324708 KB Output is correct
47 Correct 2573 ms 323892 KB Output is correct
48 Correct 2009 ms 227376 KB Output is correct
49 Correct 2004 ms 220612 KB Output is correct
50 Correct 5885 ms 323772 KB Output is correct
51 Correct 3811 ms 321484 KB Output is correct
52 Correct 4619 ms 305344 KB Output is correct
53 Correct 5632 ms 335748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 444 ms 53936 KB Output is correct
2 Correct 458 ms 53228 KB Output is correct
3 Correct 451 ms 67104 KB Output is correct
4 Correct 387 ms 53100 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 494 ms 53972 KB Output is correct
7 Correct 264 ms 34928 KB Output is correct
8 Correct 257 ms 36556 KB Output is correct
9 Correct 459 ms 66992 KB Output is correct
10 Correct 377 ms 45488 KB Output is correct
11 Correct 420 ms 67516 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 4 ms 1024 KB Output is correct
29 Correct 4 ms 1108 KB Output is correct
30 Correct 6 ms 980 KB Output is correct
31 Correct 5 ms 980 KB Output is correct
32 Correct 6 ms 1028 KB Output is correct
33 Correct 6 ms 976 KB Output is correct
34 Correct 5 ms 964 KB Output is correct
35 Correct 473 ms 67284 KB Output is correct
36 Correct 432 ms 67092 KB Output is correct
37 Correct 514 ms 67032 KB Output is correct
38 Correct 450 ms 67096 KB Output is correct
39 Correct 616 ms 67124 KB Output is correct
40 Correct 422 ms 66716 KB Output is correct
41 Correct 861 ms 66964 KB Output is correct
42 Correct 256 ms 32828 KB Output is correct
43 Correct 246 ms 34756 KB Output is correct
44 Correct 639 ms 66120 KB Output is correct
45 Correct 795 ms 65488 KB Output is correct
46 Correct 832 ms 65712 KB Output is correct
47 Correct 842 ms 65592 KB Output is correct
48 Correct 544 ms 66204 KB Output is correct
49 Correct 486 ms 66108 KB Output is correct
50 Correct 396 ms 44356 KB Output is correct
51 Correct 372 ms 44112 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 945 ms 66112 KB Output is correct
54 Correct 624 ms 65092 KB Output is correct
55 Correct 812 ms 64544 KB Output is correct
56 Correct 881 ms 66544 KB Output is correct
57 Incorrect 542 ms 65132 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 444 ms 53936 KB Output is correct
2 Correct 458 ms 53228 KB Output is correct
3 Correct 451 ms 67104 KB Output is correct
4 Correct 387 ms 53100 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 494 ms 53972 KB Output is correct
7 Correct 264 ms 34928 KB Output is correct
8 Correct 257 ms 36556 KB Output is correct
9 Correct 459 ms 66992 KB Output is correct
10 Correct 377 ms 45488 KB Output is correct
11 Correct 420 ms 67516 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 4 ms 1024 KB Output is correct
29 Correct 4 ms 1108 KB Output is correct
30 Correct 6 ms 980 KB Output is correct
31 Correct 5 ms 980 KB Output is correct
32 Correct 6 ms 1028 KB Output is correct
33 Correct 6 ms 976 KB Output is correct
34 Correct 5 ms 964 KB Output is correct
35 Correct 473 ms 67284 KB Output is correct
36 Correct 432 ms 67092 KB Output is correct
37 Correct 514 ms 67032 KB Output is correct
38 Correct 450 ms 67096 KB Output is correct
39 Correct 616 ms 67124 KB Output is correct
40 Correct 422 ms 66716 KB Output is correct
41 Correct 861 ms 66964 KB Output is correct
42 Correct 256 ms 32828 KB Output is correct
43 Correct 246 ms 34756 KB Output is correct
44 Correct 639 ms 66120 KB Output is correct
45 Correct 795 ms 65488 KB Output is correct
46 Correct 832 ms 65712 KB Output is correct
47 Correct 842 ms 65592 KB Output is correct
48 Correct 544 ms 66204 KB Output is correct
49 Correct 486 ms 66108 KB Output is correct
50 Correct 396 ms 44356 KB Output is correct
51 Correct 372 ms 44112 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 945 ms 66112 KB Output is correct
54 Correct 624 ms 65092 KB Output is correct
55 Correct 812 ms 64544 KB Output is correct
56 Correct 881 ms 66544 KB Output is correct
57 Correct 3043 ms 324708 KB Output is correct
58 Correct 2573 ms 323892 KB Output is correct
59 Correct 2009 ms 227376 KB Output is correct
60 Correct 2004 ms 220612 KB Output is correct
61 Correct 5885 ms 323772 KB Output is correct
62 Correct 3811 ms 321484 KB Output is correct
63 Correct 4619 ms 305344 KB Output is correct
64 Correct 5632 ms 335748 KB Output is correct
65 Incorrect 542 ms 65132 KB Output isn't correct
66 Halted 0 ms 0 KB -