답안 #547550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547550 2022-04-10T23:25:03 Z inksamurai Team Contest (JOI22_team) C++17
100 / 100
484 ms 34628 KB
#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
typedef long long ll;
using pii=pair<int,int>;
using vi=vec(int);
void print(){cout<<"\n";}
template<class H,class ...T>
void print(const H&v,const T...u){cout<<v<<' ',print(u...);}
// e

const int inf=1e11;
using tpii=pair<int,pii>;
#define all(a) a.begin(),a.end()

const int nax=800011;

int nseg;
int seg[nax];

void build(int n){
	nseg=1;
	while(nseg<=n){
		nseg*=2;
	}
}

void upd(int pos,int val,int v,int l,int r){
	int m=(l+r)/2;
	if(l==r-1){
		// cout<<v<<" "<<val<<"\n";
		seg[v]=val;
		return;
	}
	if(pos<m){
		upd(pos,val,v*2+1,l,m);
	}else{
		upd(pos,val,v*2+2,m,r);
	}
	seg[v]=max(seg[v*2+1],seg[v*2+2]);
}

void upd(int pos,int val){
	upd(pos,val,0,0,nseg);
}

int prod(int v,int l,int r,int _l,int _r){
	if(l>=_r or r<=_l){
		return -inf;
	}
	if(_l<=l and r<=_r){
		// cout<<"\n";
		// cout<<l<<" "<<r<<" "<<seg[v]<<"\n";
		return seg[v];
	}
	int m=(l+r)>>1;
	return max(prod(v*2+1,l,m,_l,_r),prod(v*2+2,m,r,_l,_r));
}

int prod(int l,int r){
	return prod(0,0,nseg,l,r);
}


signed main(){
	ios::sync_with_stdio(0),
	cin.tie(0);
	int n;
	cin>>n;

	vec(tpii) a(n);
	for(int i=0;i<n;i++){
		cin>>a[i].fi>>a[i].se.fi>>a[i].se.se;
	}

	vi zs;
	rep(i,n){
		zs.pb(a[i].fi);
	}
	sort(zs.begin(),zs.end());
	rep(i,n){
		a[i].fi=lower_bound(all(zs),a[i].fi)-zs.begin();
	}

	build(n);

	vec(vec(pii)) qols(sz(zs)+11);

	rep(t,2){
		sort(all(a),[&](tpii l,tpii r){
			return l.se.fi<r.se.fi;
		});
		vec(multiset<int>) rbts(sz(zs));
		rep(i,sz(zs)){
			upd(i,-inf);
		}
		for(int i=0;i<n;i++){
			rbts[a[i].fi].insert(a[i].se.se);
		}
		for(int i=0;i<sz(zs);i++){
			int val=(sz(rbts[i])?*prev(rbts[i].end()):-inf);
			// cout<<val<<" ";
			upd(i,val);
		}
		// cout<<prod(0,4)<<"\n";
		for(int i=n-1;i>=0;i--){
			vec(tpii) delay;
			{
				pii p=a[i].se;
				// cout<<a[i].fi<<" "<<a[i].se.fi<<" "<<a[i].se.se<<"\n";
				int z=a[i].fi;
				delay.pb({z,p});
				rbts[z].erase(rbts[z].find(p.se));
				int val=(sz(rbts[z])?*prev(rbts[z].end()):-inf);
				upd(z,val);
				while(i-1>=0 and a[i-1].se.fi==p.fi){
					pii np=a[i-1].se;
					int nz=a[i-1].fi;
					// upd(a[i-1].fi,-inf);
					rbts[nz].erase(rbts[nz].find(np.se));
					int val=(sz(rbts[nz])?*prev(rbts[nz].end()):-inf);
					upd(nz,val);
					delay.pb({a[i-1].fi,np});
					i-=1;
				}
			}
			// int val=prod(0,a[i].fi);
			// // return maxY in Zs an Xs smaller than me
			for(auto tp:delay){
				int z=tp.fi;
				int x=tp.se.fi;
				int y=tp.se.se;

				int val=prod(0,z+1);
				
				// cout<<z<<" "<<x<<" "<<y<<"\n";
				// cout<<val<<"\n";

				if(val>y){
					// cout<<"ho\n";
					if(!t){
						qols[z+1].pb({x,val});
					}
					else{
						qols[z+1].pb({val,x});
					}
					// + 1 because p.se can't use this
				}
			}
		}
		rep(i,n){
			swap(a[i].se.se,a[i].se.fi);
		}
	}
	
	vec(pii) rbe(sz(zs)+11);
	pii fip={-inf,-inf};

	for(int i=0;i<sz(zs);i++){
		// cout<<zs[i]<<"\n";
		for(auto p:qols[i]){
			// cout<<p.fi<<" "<<p.se<<"\n";
			if(p.fi>fip.fi){
				fip=p;
			}else if(p.fi==fip.fi and p.se>fip.se){
				fip=p;
			}
		}
		rbe[i]=fip;		
	}

	int ans=-1;
	for(int i=0;i<n;i++){
		pii p=a[i].se;
		int z=a[i].fi;
		if(rbe[z].fi>p.fi and rbe[z].se>p.se){
			ans=max(ans,zs[a[i].fi]+rbe[z].fi+rbe[z].se);
		}
	}
	print(ans);
//	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 8 ms 1108 KB Output is correct
27 Correct 7 ms 1048 KB Output is correct
28 Correct 8 ms 1048 KB Output is correct
29 Correct 7 ms 1048 KB Output is correct
30 Correct 4 ms 852 KB Output is correct
31 Correct 8 ms 1176 KB Output is correct
32 Correct 7 ms 980 KB Output is correct
33 Correct 6 ms 1108 KB Output is correct
34 Correct 6 ms 980 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 6 ms 980 KB Output is correct
38 Correct 6 ms 980 KB Output is correct
39 Correct 4 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 298 ms 29732 KB Output is correct
12 Correct 175 ms 20008 KB Output is correct
13 Correct 191 ms 26596 KB Output is correct
14 Correct 272 ms 31656 KB Output is correct
15 Correct 247 ms 31668 KB Output is correct
16 Correct 250 ms 34600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 298 ms 29732 KB Output is correct
12 Correct 175 ms 20008 KB Output is correct
13 Correct 191 ms 26596 KB Output is correct
14 Correct 272 ms 31656 KB Output is correct
15 Correct 247 ms 31668 KB Output is correct
16 Correct 250 ms 34600 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 4 ms 724 KB Output is correct
22 Correct 352 ms 29960 KB Output is correct
23 Correct 298 ms 28628 KB Output is correct
24 Correct 217 ms 20932 KB Output is correct
25 Correct 312 ms 29564 KB Output is correct
26 Correct 262 ms 31772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 298 ms 29732 KB Output is correct
12 Correct 175 ms 20008 KB Output is correct
13 Correct 191 ms 26596 KB Output is correct
14 Correct 272 ms 31656 KB Output is correct
15 Correct 247 ms 31668 KB Output is correct
16 Correct 250 ms 34600 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 4 ms 724 KB Output is correct
22 Correct 352 ms 29960 KB Output is correct
23 Correct 298 ms 28628 KB Output is correct
24 Correct 217 ms 20932 KB Output is correct
25 Correct 312 ms 29564 KB Output is correct
26 Correct 262 ms 31772 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 7 ms 980 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 442 ms 29312 KB Output is correct
35 Correct 379 ms 27136 KB Output is correct
36 Correct 413 ms 30692 KB Output is correct
37 Correct 346 ms 27684 KB Output is correct
38 Correct 276 ms 31100 KB Output is correct
39 Correct 171 ms 19912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 298 ms 29732 KB Output is correct
12 Correct 175 ms 20008 KB Output is correct
13 Correct 191 ms 26596 KB Output is correct
14 Correct 272 ms 31656 KB Output is correct
15 Correct 247 ms 31668 KB Output is correct
16 Correct 250 ms 34600 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 4 ms 724 KB Output is correct
22 Correct 352 ms 29960 KB Output is correct
23 Correct 298 ms 28628 KB Output is correct
24 Correct 217 ms 20932 KB Output is correct
25 Correct 312 ms 29564 KB Output is correct
26 Correct 262 ms 31772 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 7 ms 980 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 442 ms 29312 KB Output is correct
35 Correct 379 ms 27136 KB Output is correct
36 Correct 413 ms 30692 KB Output is correct
37 Correct 346 ms 27684 KB Output is correct
38 Correct 276 ms 31100 KB Output is correct
39 Correct 171 ms 19912 KB Output is correct
40 Correct 7 ms 748 KB Output is correct
41 Correct 7 ms 1176 KB Output is correct
42 Correct 6 ms 980 KB Output is correct
43 Correct 7 ms 980 KB Output is correct
44 Correct 448 ms 28660 KB Output is correct
45 Correct 386 ms 27452 KB Output is correct
46 Correct 390 ms 27676 KB Output is correct
47 Correct 370 ms 27328 KB Output is correct
48 Correct 297 ms 31796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 8 ms 1108 KB Output is correct
27 Correct 7 ms 1048 KB Output is correct
28 Correct 8 ms 1048 KB Output is correct
29 Correct 7 ms 1048 KB Output is correct
30 Correct 4 ms 852 KB Output is correct
31 Correct 8 ms 1176 KB Output is correct
32 Correct 7 ms 980 KB Output is correct
33 Correct 6 ms 1108 KB Output is correct
34 Correct 6 ms 980 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 6 ms 980 KB Output is correct
38 Correct 6 ms 980 KB Output is correct
39 Correct 4 ms 724 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 298 ms 29732 KB Output is correct
51 Correct 175 ms 20008 KB Output is correct
52 Correct 191 ms 26596 KB Output is correct
53 Correct 272 ms 31656 KB Output is correct
54 Correct 247 ms 31668 KB Output is correct
55 Correct 250 ms 34600 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 4 ms 724 KB Output is correct
61 Correct 352 ms 29960 KB Output is correct
62 Correct 298 ms 28628 KB Output is correct
63 Correct 217 ms 20932 KB Output is correct
64 Correct 312 ms 29564 KB Output is correct
65 Correct 262 ms 31772 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 7 ms 980 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 2 ms 468 KB Output is correct
73 Correct 442 ms 29312 KB Output is correct
74 Correct 379 ms 27136 KB Output is correct
75 Correct 413 ms 30692 KB Output is correct
76 Correct 346 ms 27684 KB Output is correct
77 Correct 276 ms 31100 KB Output is correct
78 Correct 171 ms 19912 KB Output is correct
79 Correct 7 ms 748 KB Output is correct
80 Correct 7 ms 1176 KB Output is correct
81 Correct 6 ms 980 KB Output is correct
82 Correct 7 ms 980 KB Output is correct
83 Correct 448 ms 28660 KB Output is correct
84 Correct 386 ms 27452 KB Output is correct
85 Correct 390 ms 27676 KB Output is correct
86 Correct 370 ms 27328 KB Output is correct
87 Correct 297 ms 31796 KB Output is correct
88 Correct 434 ms 29724 KB Output is correct
89 Correct 411 ms 27492 KB Output is correct
90 Correct 484 ms 28952 KB Output is correct
91 Correct 374 ms 26252 KB Output is correct
92 Correct 456 ms 28060 KB Output is correct
93 Correct 405 ms 27164 KB Output is correct
94 Correct 387 ms 26552 KB Output is correct
95 Correct 299 ms 31732 KB Output is correct
96 Correct 259 ms 25004 KB Output is correct
97 Correct 278 ms 34628 KB Output is correct
98 Correct 230 ms 25024 KB Output is correct
99 Correct 260 ms 24908 KB Output is correct