답안 #892301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892301 2023-12-25T07:01:14 Z vjudge1 Team Contest (JOI22_team) C++17
100 / 100
596 ms 31352 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int mod = 998244353;
const int N = 2e5;




struct ST{
	vector<int > tree;
	int n;
	
	ST(int sz){
		n = N;
		tree.resize(4 * n, -1);
	};
	
	int merge(int A, int B){
		return max(A, B);
		/*vector<int> v = {A.ff, A.ss, B.ff, B.ss};
		sort(all(v));
		return {v[3], v[2]};
		* */
	}
	
	void update(int pos, int x, int v, int vl, int vr){
		if(vl == vr){
			tree[v] = max(tree[v], x);
		}else{
			int mid =(vl + vr)>>1;
			if(mid >= pos) update(pos, x, v<<1, vl, mid);
			else update(pos, x, v<<1|1, mid+1, vr);
			tree[v] = merge(tree[v<<1], tree[v<<1|1]);
		}
	};
	
	int get_max(int l, int r, int v, int vl, int vr){
		if(l > vr or vl > r) return -1;
		if(l <= vl and r >= vr) return tree[v];
		int mid = (vl + vr)>>1;
		return merge(get_max(l, r, v<<1, vl, mid), get_max(l, r, v<<1|1, mid+1, vr));
	}
};





int n;
int cX[N+10], cY[N+10], cZ[N+10];
void compr(auto &x, auto &y, auto &z){
	vector<int> vec;
	for(int i = 0;i < n; i++) vec.push_back(x[i]);
	sort(all(vec));
	vec.erase(unique(all(vec)), vec.end());
	
	for(int i = 0;i < n; i++){
		int it = lower_bound(all(vec), x[i]) - vec.begin() + 1;
		cX[it] = x[i];
		x[i] = it;
	}
	vec.clear();
	for(int i = 0;i < n; i++) vec.push_back(y[i]);
	sort(all(vec));
	vec.erase(unique(all(vec)), vec.end());
	
	for(int i = 0;i < n; i++){
		int it = lower_bound(all(vec), y[i]) - vec.begin() + 1;
		cY[it] = y[i];
		y[i] = it;
	}
	vec.clear();
	for(int i = 0;i < n; i++) vec.push_back(z[i]);
	sort(all(vec));
	vec.erase(unique(all(vec)), vec.end());
	for(int i = 0;i < n; i++){
		int it = lower_bound(all(vec), z[i]) - vec.begin() + 1;
		cZ[it] = z[i];
		z[i] = it;
	}
}






signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	vector<int> x(n), y(n), z(n);
	for(int i = 0;i < n; i++){
		cin >> x[i] >> y[i] >> z[i];
	}
	auto get=[&](auto x, auto y, auto z){
		compr(x, y, z);
		vector<int> p(n);
		int res = -1;
		iota(all(p), 0);
		sort(all(p), [&](int i, int j){
			return x[i] < x[j];
		});
		ST seg(N);
		auto chmax = [&](auto &A, auto B){
			if(B.ff + B.ss > A.ff + A.ss) A = B;
			else if(B.ff + B.ss == A.ff + A.ss && A.ff < B.ff){
				A = B;
			}
		};
		for(int i : p){
			//cout << x[i] << " " <<  y[i] << " " << z[i] << '\n';
			//cout << cX[x[i]] << ' ' << cY[y[i]] << ' ' << cZ[z[i]] << '\n';
		}
		vector<pair<int, int>> pref;
		for(int i : p){
		//	cout << cX[x[i]] << ' ' << cY[y[i]] << ' ' << cZ[z[i]] << "   =   ";
			pair<int, int> cur = {INT_MIN, INT_MIN};
			if(pref.empty() == false) cur = pref.back();
			int Z = seg.get_max(1, y[i]-1, 1, 1, N);
			if(Z > z[i]){
				chmax(cur, make_pair(cY[y[i]], cZ[Z]));
			}
			pref.push_back(cur);
		//	cout << cur.ff << ' ' << cur.ss << '\n';
			seg.update(y[i], z[i], 1, 1, N);
		}
		for(int i = 0;i < n; ){
		//	cout << i+1 << " = ";
			int j = i;
			for(j = i; j <n && x[p[i]] == x[p[j]]; j++){
				if(i == 0){
					continue;
				}
				int fnY = pref[i-1].ff;
				int fnZ = pref[i-1].ss;
				if(fnY > cY[y[p[j]]] && fnZ > cZ[z[p[j]]]){
					res = max(res, cX[x[p[j]]] + fnY + fnZ);
				}
			}
		//	cout << j << '\n';
			i = j;
		}
		return res;
	};
	int ALL = -1;
	ALL = max(get(x, y, z), ALL);
	 ALL = max(get(x, z, y), ALL);
	ALL = max(get(z, x, y), ALL);
	ALL = max(get(z, y, z), ALL);
	cout << ALL;
	return 0;
}

Compilation message

team.cpp:56:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   56 | void compr(auto &x, auto &y, auto &z){
      |            ^~~~
team.cpp:56:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   56 | void compr(auto &x, auto &y, auto &z){
      |                     ^~~~
team.cpp:56:30: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   56 | void compr(auto &x, auto &y, auto &z){
      |                              ^~~~
team.cpp: In instantiation of 'main()::<lambda(auto:26, auto:27, auto:28)> [with auto:26 = std::vector<long long int>; auto:27 = std::vector<long long int>; auto:28 = std::vector<long long int>]':
team.cpp:152:23:   required from here
team.cpp:116:11: warning: unused variable 'i' [-Wunused-variable]
  116 |   for(int i : p){
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10732 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 3 ms 10736 KB Output is correct
4 Correct 4 ms 10736 KB Output is correct
5 Correct 3 ms 10736 KB Output is correct
6 Correct 4 ms 10736 KB Output is correct
7 Correct 4 ms 10708 KB Output is correct
8 Correct 4 ms 10736 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10840 KB Output is correct
11 Correct 4 ms 10736 KB Output is correct
12 Correct 4 ms 10736 KB Output is correct
13 Correct 4 ms 10736 KB Output is correct
14 Correct 4 ms 10844 KB Output is correct
15 Correct 4 ms 10844 KB Output is correct
16 Correct 4 ms 10844 KB Output is correct
17 Correct 4 ms 10844 KB Output is correct
18 Correct 4 ms 10844 KB Output is correct
19 Correct 4 ms 10840 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 4 ms 10844 KB Output is correct
22 Correct 4 ms 10844 KB Output is correct
23 Correct 4 ms 10844 KB Output is correct
24 Correct 4 ms 10844 KB Output is correct
25 Correct 4 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10732 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 3 ms 10736 KB Output is correct
4 Correct 4 ms 10736 KB Output is correct
5 Correct 3 ms 10736 KB Output is correct
6 Correct 4 ms 10736 KB Output is correct
7 Correct 4 ms 10708 KB Output is correct
8 Correct 4 ms 10736 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10840 KB Output is correct
11 Correct 4 ms 10736 KB Output is correct
12 Correct 4 ms 10736 KB Output is correct
13 Correct 4 ms 10736 KB Output is correct
14 Correct 4 ms 10844 KB Output is correct
15 Correct 4 ms 10844 KB Output is correct
16 Correct 4 ms 10844 KB Output is correct
17 Correct 4 ms 10844 KB Output is correct
18 Correct 4 ms 10844 KB Output is correct
19 Correct 4 ms 10840 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 4 ms 10844 KB Output is correct
22 Correct 4 ms 10844 KB Output is correct
23 Correct 4 ms 10844 KB Output is correct
24 Correct 4 ms 10844 KB Output is correct
25 Correct 4 ms 10844 KB Output is correct
26 Correct 14 ms 11096 KB Output is correct
27 Correct 15 ms 11248 KB Output is correct
28 Correct 13 ms 11248 KB Output is correct
29 Correct 13 ms 11248 KB Output is correct
30 Correct 10 ms 11116 KB Output is correct
31 Correct 14 ms 11244 KB Output is correct
32 Correct 11 ms 11100 KB Output is correct
33 Correct 10 ms 11248 KB Output is correct
34 Correct 13 ms 11248 KB Output is correct
35 Correct 5 ms 10844 KB Output is correct
36 Correct 5 ms 10844 KB Output is correct
37 Correct 9 ms 11452 KB Output is correct
38 Correct 11 ms 11228 KB Output is correct
39 Correct 7 ms 10988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10736 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 3 ms 10736 KB Output is correct
4 Correct 4 ms 10732 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 3 ms 10736 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 3 ms 10736 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10736 KB Output is correct
11 Correct 184 ms 26692 KB Output is correct
12 Correct 121 ms 19956 KB Output is correct
13 Correct 111 ms 21576 KB Output is correct
14 Correct 182 ms 27104 KB Output is correct
15 Correct 150 ms 26376 KB Output is correct
16 Correct 111 ms 26852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10736 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 3 ms 10736 KB Output is correct
4 Correct 4 ms 10732 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 3 ms 10736 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 3 ms 10736 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10736 KB Output is correct
11 Correct 184 ms 26692 KB Output is correct
12 Correct 121 ms 19956 KB Output is correct
13 Correct 111 ms 21576 KB Output is correct
14 Correct 182 ms 27104 KB Output is correct
15 Correct 150 ms 26376 KB Output is correct
16 Correct 111 ms 26852 KB Output is correct
17 Correct 3 ms 10736 KB Output is correct
18 Correct 4 ms 10736 KB Output is correct
19 Correct 3 ms 10736 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 6 ms 10992 KB Output is correct
22 Correct 226 ms 28088 KB Output is correct
23 Correct 206 ms 27868 KB Output is correct
24 Correct 157 ms 21292 KB Output is correct
25 Correct 212 ms 28212 KB Output is correct
26 Correct 160 ms 27592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10736 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 3 ms 10736 KB Output is correct
4 Correct 4 ms 10732 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 3 ms 10736 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 3 ms 10736 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10736 KB Output is correct
11 Correct 184 ms 26692 KB Output is correct
12 Correct 121 ms 19956 KB Output is correct
13 Correct 111 ms 21576 KB Output is correct
14 Correct 182 ms 27104 KB Output is correct
15 Correct 150 ms 26376 KB Output is correct
16 Correct 111 ms 26852 KB Output is correct
17 Correct 3 ms 10736 KB Output is correct
18 Correct 4 ms 10736 KB Output is correct
19 Correct 3 ms 10736 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 6 ms 10992 KB Output is correct
22 Correct 226 ms 28088 KB Output is correct
23 Correct 206 ms 27868 KB Output is correct
24 Correct 157 ms 21292 KB Output is correct
25 Correct 212 ms 28212 KB Output is correct
26 Correct 160 ms 27592 KB Output is correct
27 Correct 4 ms 10840 KB Output is correct
28 Correct 4 ms 10844 KB Output is correct
29 Correct 4 ms 10836 KB Output is correct
30 Correct 4 ms 10844 KB Output is correct
31 Correct 11 ms 11236 KB Output is correct
32 Correct 5 ms 10844 KB Output is correct
33 Correct 5 ms 10816 KB Output is correct
34 Correct 294 ms 27492 KB Output is correct
35 Correct 276 ms 27688 KB Output is correct
36 Correct 295 ms 27952 KB Output is correct
37 Correct 303 ms 27584 KB Output is correct
38 Correct 184 ms 27972 KB Output is correct
39 Correct 101 ms 20140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10736 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 3 ms 10736 KB Output is correct
4 Correct 4 ms 10732 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 3 ms 10736 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 3 ms 10736 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10736 KB Output is correct
11 Correct 184 ms 26692 KB Output is correct
12 Correct 121 ms 19956 KB Output is correct
13 Correct 111 ms 21576 KB Output is correct
14 Correct 182 ms 27104 KB Output is correct
15 Correct 150 ms 26376 KB Output is correct
16 Correct 111 ms 26852 KB Output is correct
17 Correct 3 ms 10736 KB Output is correct
18 Correct 4 ms 10736 KB Output is correct
19 Correct 3 ms 10736 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 6 ms 10992 KB Output is correct
22 Correct 226 ms 28088 KB Output is correct
23 Correct 206 ms 27868 KB Output is correct
24 Correct 157 ms 21292 KB Output is correct
25 Correct 212 ms 28212 KB Output is correct
26 Correct 160 ms 27592 KB Output is correct
27 Correct 4 ms 10840 KB Output is correct
28 Correct 4 ms 10844 KB Output is correct
29 Correct 4 ms 10836 KB Output is correct
30 Correct 4 ms 10844 KB Output is correct
31 Correct 11 ms 11236 KB Output is correct
32 Correct 5 ms 10844 KB Output is correct
33 Correct 5 ms 10816 KB Output is correct
34 Correct 294 ms 27492 KB Output is correct
35 Correct 276 ms 27688 KB Output is correct
36 Correct 295 ms 27952 KB Output is correct
37 Correct 303 ms 27584 KB Output is correct
38 Correct 184 ms 27972 KB Output is correct
39 Correct 101 ms 20140 KB Output is correct
40 Correct 10 ms 11096 KB Output is correct
41 Correct 13 ms 11248 KB Output is correct
42 Correct 9 ms 11248 KB Output is correct
43 Correct 13 ms 11168 KB Output is correct
44 Correct 407 ms 28504 KB Output is correct
45 Correct 399 ms 29428 KB Output is correct
46 Correct 410 ms 27956 KB Output is correct
47 Correct 401 ms 29232 KB Output is correct
48 Correct 221 ms 27824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10732 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 3 ms 10736 KB Output is correct
4 Correct 4 ms 10736 KB Output is correct
5 Correct 3 ms 10736 KB Output is correct
6 Correct 4 ms 10736 KB Output is correct
7 Correct 4 ms 10708 KB Output is correct
8 Correct 4 ms 10736 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10840 KB Output is correct
11 Correct 4 ms 10736 KB Output is correct
12 Correct 4 ms 10736 KB Output is correct
13 Correct 4 ms 10736 KB Output is correct
14 Correct 4 ms 10844 KB Output is correct
15 Correct 4 ms 10844 KB Output is correct
16 Correct 4 ms 10844 KB Output is correct
17 Correct 4 ms 10844 KB Output is correct
18 Correct 4 ms 10844 KB Output is correct
19 Correct 4 ms 10840 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 4 ms 10844 KB Output is correct
22 Correct 4 ms 10844 KB Output is correct
23 Correct 4 ms 10844 KB Output is correct
24 Correct 4 ms 10844 KB Output is correct
25 Correct 4 ms 10844 KB Output is correct
26 Correct 14 ms 11096 KB Output is correct
27 Correct 15 ms 11248 KB Output is correct
28 Correct 13 ms 11248 KB Output is correct
29 Correct 13 ms 11248 KB Output is correct
30 Correct 10 ms 11116 KB Output is correct
31 Correct 14 ms 11244 KB Output is correct
32 Correct 11 ms 11100 KB Output is correct
33 Correct 10 ms 11248 KB Output is correct
34 Correct 13 ms 11248 KB Output is correct
35 Correct 5 ms 10844 KB Output is correct
36 Correct 5 ms 10844 KB Output is correct
37 Correct 9 ms 11452 KB Output is correct
38 Correct 11 ms 11228 KB Output is correct
39 Correct 7 ms 10988 KB Output is correct
40 Correct 5 ms 10736 KB Output is correct
41 Correct 4 ms 10736 KB Output is correct
42 Correct 3 ms 10736 KB Output is correct
43 Correct 4 ms 10732 KB Output is correct
44 Correct 4 ms 10736 KB Output is correct
45 Correct 3 ms 10736 KB Output is correct
46 Correct 3 ms 10844 KB Output is correct
47 Correct 3 ms 10736 KB Output is correct
48 Correct 4 ms 10736 KB Output is correct
49 Correct 4 ms 10736 KB Output is correct
50 Correct 184 ms 26692 KB Output is correct
51 Correct 121 ms 19956 KB Output is correct
52 Correct 111 ms 21576 KB Output is correct
53 Correct 182 ms 27104 KB Output is correct
54 Correct 150 ms 26376 KB Output is correct
55 Correct 111 ms 26852 KB Output is correct
56 Correct 3 ms 10736 KB Output is correct
57 Correct 4 ms 10736 KB Output is correct
58 Correct 3 ms 10736 KB Output is correct
59 Correct 4 ms 10844 KB Output is correct
60 Correct 6 ms 10992 KB Output is correct
61 Correct 226 ms 28088 KB Output is correct
62 Correct 206 ms 27868 KB Output is correct
63 Correct 157 ms 21292 KB Output is correct
64 Correct 212 ms 28212 KB Output is correct
65 Correct 160 ms 27592 KB Output is correct
66 Correct 4 ms 10840 KB Output is correct
67 Correct 4 ms 10844 KB Output is correct
68 Correct 4 ms 10836 KB Output is correct
69 Correct 4 ms 10844 KB Output is correct
70 Correct 11 ms 11236 KB Output is correct
71 Correct 5 ms 10844 KB Output is correct
72 Correct 5 ms 10816 KB Output is correct
73 Correct 294 ms 27492 KB Output is correct
74 Correct 276 ms 27688 KB Output is correct
75 Correct 295 ms 27952 KB Output is correct
76 Correct 303 ms 27584 KB Output is correct
77 Correct 184 ms 27972 KB Output is correct
78 Correct 101 ms 20140 KB Output is correct
79 Correct 10 ms 11096 KB Output is correct
80 Correct 13 ms 11248 KB Output is correct
81 Correct 9 ms 11248 KB Output is correct
82 Correct 13 ms 11168 KB Output is correct
83 Correct 407 ms 28504 KB Output is correct
84 Correct 399 ms 29428 KB Output is correct
85 Correct 410 ms 27956 KB Output is correct
86 Correct 401 ms 29232 KB Output is correct
87 Correct 221 ms 27824 KB Output is correct
88 Correct 596 ms 31352 KB Output is correct
89 Correct 550 ms 30512 KB Output is correct
90 Correct 579 ms 31044 KB Output is correct
91 Correct 552 ms 30808 KB Output is correct
92 Correct 496 ms 29380 KB Output is correct
93 Correct 540 ms 28976 KB Output is correct
94 Correct 513 ms 30024 KB Output is correct
95 Correct 264 ms 30936 KB Output is correct
96 Correct 520 ms 31164 KB Output is correct
97 Correct 124 ms 30632 KB Output is correct
98 Correct 217 ms 30352 KB Output is correct
99 Correct 359 ms 29512 KB Output is correct