답안 #709845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709845 2023-03-14T16:49:56 Z alvingogo Two Dishes (JOI19_dishes) C++14
100 / 100
6622 ms 376264 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;
	//freopen("07-10.txt","r",stdin);
	//freopen("ans.txt","w",stdout);
	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+2);
	for(int i=1;i<=n;i++){
		oka[i]=upper_bound(b.begin(),b.end(),s[i]-a[i])-b.begin()-1;
		if(oka[i]<0){
			p[i]=0;
			continue;
		}
		to.push_back({oka[i],i});
	}
	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]<0){
			q[i]=0;
			continue;
		}
		if(okb[i]>=n){
		}
		else{
			to.push_back({i-1,okb[i]+1});
		}
	}
	/*
	for(int i=1;i<=n;i++){
		cout << oka[i] << " ";
	}
	cout << "\n";
	for(int i=1;i<=n;i++){
		cout << okb[i] << " ";
	}
	cout << "\n";
	*/
	to.push_back({m,n+1});
	sort(to.begin(),to.end(),[&](pair<int,int> a,pair<int,int> b){
		return a<b;
	});
	to.erase(unique(to.begin(),to.end()),to.end());
	gg=to;
	sort(gg.begin(),gg.end(),cmp);
	int sz=gg.size();
	vector<int> newp(sz+1);
	st.init(sz+1);
	bt.init(sz);
	bt2.init(sz);
	st.update(0,0,sz,1,sz,-inf);
	vector<int> vis2(sz+1,0);
	vector<int> pu(n+1);
	for(int i=1;i<=n;i++){
		if(oka[i]>=0){
			int u=lower_bound(gg.begin(),gg.end(),pair<int,int>(-inf,i),cmp)-gg.begin()+1;
			st.update(0,0,sz,0,u-1,p[i]);
			bt.update(u,p[i]);
			pu[i]=u;
		}
	}
	for(auto &h:to){
		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];
			vis2[h.sc]=pu[flag];
		}
	}
	int l=0;
	vector<int> dp(sz+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();
		}
	}
	for(int i=0;i<=m;i++){
		if(i>0 && okb[i]>=0){
			st.update(0,0,sz,0,okb[i],q[i]);
			bt2.update(okb[i],q[i]);
		}
		int lst=0;
		while(l<(int)to.size() && to[l].fs==i){
			int x=to[l].sc;
			dp[x]=st.query(0,0,sz,lst,x-1)-bt.query(x+1);
			st.update(0,0,sz,x,x,dp[x]+inf-bt2.query(x));
			if(vis2[x]){
				st.update(0,0,sz,0,vis2[x]-1,-newp[x]);
				bt.update(vis2[x],-newp[x]);
			}
			l++;
			lst=x;
		}
	}
	cout << dp[sz] << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 63408 KB Output is correct
2 Correct 490 ms 64712 KB Output is correct
3 Correct 389 ms 55952 KB Output is correct
4 Correct 365 ms 48012 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 466 ms 62396 KB Output is correct
7 Correct 85 ms 13328 KB Output is correct
8 Correct 248 ms 43196 KB Output is correct
9 Correct 363 ms 56976 KB Output is correct
10 Correct 447 ms 53164 KB Output is correct
11 Correct 331 ms 50380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 316 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 316 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 3 ms 788 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 6 ms 1096 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 5 ms 980 KB Output is correct
22 Correct 5 ms 972 KB Output is correct
23 Correct 5 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 316 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 3 ms 788 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 6 ms 1096 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 5 ms 980 KB Output is correct
22 Correct 5 ms 972 KB Output is correct
23 Correct 5 ms 980 KB Output is correct
24 Correct 325 ms 53148 KB Output is correct
25 Correct 392 ms 66380 KB Output is correct
26 Correct 375 ms 53264 KB Output is correct
27 Correct 420 ms 66628 KB Output is correct
28 Correct 521 ms 56768 KB Output is correct
29 Correct 351 ms 53984 KB Output is correct
30 Correct 958 ms 78404 KB Output is correct
31 Correct 148 ms 25032 KB Output is correct
32 Correct 272 ms 41576 KB Output is correct
33 Correct 485 ms 52120 KB Output is correct
34 Correct 832 ms 74116 KB Output is correct
35 Correct 889 ms 72752 KB Output is correct
36 Correct 913 ms 71260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 316 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 3 ms 788 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 6 ms 1096 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 5 ms 980 KB Output is correct
22 Correct 5 ms 972 KB Output is correct
23 Correct 5 ms 980 KB Output is correct
24 Correct 325 ms 53148 KB Output is correct
25 Correct 392 ms 66380 KB Output is correct
26 Correct 375 ms 53264 KB Output is correct
27 Correct 420 ms 66628 KB Output is correct
28 Correct 521 ms 56768 KB Output is correct
29 Correct 351 ms 53984 KB Output is correct
30 Correct 958 ms 78404 KB Output is correct
31 Correct 148 ms 25032 KB Output is correct
32 Correct 272 ms 41576 KB Output is correct
33 Correct 485 ms 52120 KB Output is correct
34 Correct 832 ms 74116 KB Output is correct
35 Correct 889 ms 72752 KB Output is correct
36 Correct 913 ms 71260 KB Output is correct
37 Correct 446 ms 56268 KB Output is correct
38 Correct 467 ms 69584 KB Output is correct
39 Correct 467 ms 56752 KB Output is correct
40 Correct 488 ms 56808 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 966 ms 81472 KB Output is correct
43 Correct 521 ms 54896 KB Output is correct
44 Correct 866 ms 76804 KB Output is correct
45 Correct 901 ms 75764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 316 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 3 ms 788 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 6 ms 1096 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 5 ms 980 KB Output is correct
22 Correct 5 ms 972 KB Output is correct
23 Correct 5 ms 980 KB Output is correct
24 Correct 325 ms 53148 KB Output is correct
25 Correct 392 ms 66380 KB Output is correct
26 Correct 375 ms 53264 KB Output is correct
27 Correct 420 ms 66628 KB Output is correct
28 Correct 521 ms 56768 KB Output is correct
29 Correct 351 ms 53984 KB Output is correct
30 Correct 958 ms 78404 KB Output is correct
31 Correct 148 ms 25032 KB Output is correct
32 Correct 272 ms 41576 KB Output is correct
33 Correct 485 ms 52120 KB Output is correct
34 Correct 832 ms 74116 KB Output is correct
35 Correct 889 ms 72752 KB Output is correct
36 Correct 913 ms 71260 KB Output is correct
37 Correct 446 ms 56268 KB Output is correct
38 Correct 467 ms 69584 KB Output is correct
39 Correct 467 ms 56752 KB Output is correct
40 Correct 488 ms 56808 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 966 ms 81472 KB Output is correct
43 Correct 521 ms 54896 KB Output is correct
44 Correct 866 ms 76804 KB Output is correct
45 Correct 901 ms 75764 KB Output is correct
46 Correct 2383 ms 235564 KB Output is correct
47 Correct 2550 ms 310856 KB Output is correct
48 Correct 2488 ms 250832 KB Output is correct
49 Correct 2482 ms 253416 KB Output is correct
50 Correct 6537 ms 376264 KB Output is correct
51 Correct 3083 ms 223356 KB Output is correct
52 Correct 4693 ms 334156 KB Output is correct
53 Correct 5906 ms 352408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 63408 KB Output is correct
2 Correct 490 ms 64712 KB Output is correct
3 Correct 389 ms 55952 KB Output is correct
4 Correct 365 ms 48012 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 466 ms 62396 KB Output is correct
7 Correct 85 ms 13328 KB Output is correct
8 Correct 248 ms 43196 KB Output is correct
9 Correct 363 ms 56976 KB Output is correct
10 Correct 447 ms 53164 KB Output is correct
11 Correct 331 ms 50380 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 316 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 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 3 ms 788 KB Output is correct
29 Correct 4 ms 980 KB Output is correct
30 Correct 6 ms 1096 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 5 ms 980 KB Output is correct
33 Correct 5 ms 972 KB Output is correct
34 Correct 5 ms 980 KB Output is correct
35 Correct 325 ms 53148 KB Output is correct
36 Correct 392 ms 66380 KB Output is correct
37 Correct 375 ms 53264 KB Output is correct
38 Correct 420 ms 66628 KB Output is correct
39 Correct 521 ms 56768 KB Output is correct
40 Correct 351 ms 53984 KB Output is correct
41 Correct 958 ms 78404 KB Output is correct
42 Correct 148 ms 25032 KB Output is correct
43 Correct 272 ms 41576 KB Output is correct
44 Correct 485 ms 52120 KB Output is correct
45 Correct 832 ms 74116 KB Output is correct
46 Correct 889 ms 72752 KB Output is correct
47 Correct 913 ms 71260 KB Output is correct
48 Correct 446 ms 56268 KB Output is correct
49 Correct 467 ms 69584 KB Output is correct
50 Correct 467 ms 56752 KB Output is correct
51 Correct 488 ms 56808 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 966 ms 81472 KB Output is correct
54 Correct 521 ms 54896 KB Output is correct
55 Correct 866 ms 76804 KB Output is correct
56 Correct 901 ms 75764 KB Output is correct
57 Correct 385 ms 56652 KB Output is correct
58 Correct 457 ms 70084 KB Output is correct
59 Correct 488 ms 57668 KB Output is correct
60 Correct 477 ms 57692 KB Output is correct
61 Correct 1033 ms 79900 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1002 ms 81624 KB Output is correct
64 Correct 526 ms 50444 KB Output is correct
65 Correct 829 ms 68956 KB Output is correct
66 Correct 930 ms 74488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 63408 KB Output is correct
2 Correct 490 ms 64712 KB Output is correct
3 Correct 389 ms 55952 KB Output is correct
4 Correct 365 ms 48012 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 466 ms 62396 KB Output is correct
7 Correct 85 ms 13328 KB Output is correct
8 Correct 248 ms 43196 KB Output is correct
9 Correct 363 ms 56976 KB Output is correct
10 Correct 447 ms 53164 KB Output is correct
11 Correct 331 ms 50380 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 316 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 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 3 ms 788 KB Output is correct
29 Correct 4 ms 980 KB Output is correct
30 Correct 6 ms 1096 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 5 ms 980 KB Output is correct
33 Correct 5 ms 972 KB Output is correct
34 Correct 5 ms 980 KB Output is correct
35 Correct 325 ms 53148 KB Output is correct
36 Correct 392 ms 66380 KB Output is correct
37 Correct 375 ms 53264 KB Output is correct
38 Correct 420 ms 66628 KB Output is correct
39 Correct 521 ms 56768 KB Output is correct
40 Correct 351 ms 53984 KB Output is correct
41 Correct 958 ms 78404 KB Output is correct
42 Correct 148 ms 25032 KB Output is correct
43 Correct 272 ms 41576 KB Output is correct
44 Correct 485 ms 52120 KB Output is correct
45 Correct 832 ms 74116 KB Output is correct
46 Correct 889 ms 72752 KB Output is correct
47 Correct 913 ms 71260 KB Output is correct
48 Correct 446 ms 56268 KB Output is correct
49 Correct 467 ms 69584 KB Output is correct
50 Correct 467 ms 56752 KB Output is correct
51 Correct 488 ms 56808 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 966 ms 81472 KB Output is correct
54 Correct 521 ms 54896 KB Output is correct
55 Correct 866 ms 76804 KB Output is correct
56 Correct 901 ms 75764 KB Output is correct
57 Correct 2383 ms 235564 KB Output is correct
58 Correct 2550 ms 310856 KB Output is correct
59 Correct 2488 ms 250832 KB Output is correct
60 Correct 2482 ms 253416 KB Output is correct
61 Correct 6537 ms 376264 KB Output is correct
62 Correct 3083 ms 223356 KB Output is correct
63 Correct 4693 ms 334156 KB Output is correct
64 Correct 5906 ms 352408 KB Output is correct
65 Correct 385 ms 56652 KB Output is correct
66 Correct 457 ms 70084 KB Output is correct
67 Correct 488 ms 57668 KB Output is correct
68 Correct 477 ms 57692 KB Output is correct
69 Correct 1033 ms 79900 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1002 ms 81624 KB Output is correct
72 Correct 526 ms 50444 KB Output is correct
73 Correct 829 ms 68956 KB Output is correct
74 Correct 930 ms 74488 KB Output is correct
75 Correct 1966 ms 226484 KB Output is correct
76 Correct 2331 ms 292676 KB Output is correct
77 Correct 2508 ms 239744 KB Output is correct
78 Correct 2531 ms 238844 KB Output is correct
79 Correct 6487 ms 354212 KB Output is correct
80 Correct 3233 ms 214616 KB Output is correct
81 Correct 5295 ms 288644 KB Output is correct
82 Correct 6622 ms 345200 KB Output is correct
83 Correct 6400 ms 332964 KB Output is correct