답안 #892507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892507 2023-12-25T12:49:59 Z iskhakkutbilim Team Contest (JOI22_team) C++17
100 / 100
611 ms 27516 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 10736 KB Output is correct
2 Correct 3 ms 10736 KB Output is correct
3 Correct 4 ms 10704 KB Output is correct
4 Correct 4 ms 10736 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 4 ms 10736 KB Output is correct
7 Correct 4 ms 10732 KB Output is correct
8 Correct 4 ms 10736 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 5 ms 10736 KB Output is correct
11 Correct 4 ms 10736 KB Output is correct
12 Correct 4 ms 10664 KB Output is correct
13 Correct 4 ms 10736 KB Output is correct
14 Correct 4 ms 10872 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 11096 KB Output is correct
19 Correct 4 ms 10844 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 4 ms 10844 KB Output is correct
22 Correct 5 ms 10840 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 10736 KB Output is correct
2 Correct 3 ms 10736 KB Output is correct
3 Correct 4 ms 10704 KB Output is correct
4 Correct 4 ms 10736 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 4 ms 10736 KB Output is correct
7 Correct 4 ms 10732 KB Output is correct
8 Correct 4 ms 10736 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 5 ms 10736 KB Output is correct
11 Correct 4 ms 10736 KB Output is correct
12 Correct 4 ms 10664 KB Output is correct
13 Correct 4 ms 10736 KB Output is correct
14 Correct 4 ms 10872 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 11096 KB Output is correct
19 Correct 4 ms 10844 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 4 ms 10844 KB Output is correct
22 Correct 5 ms 10840 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 11100 KB Output is correct
27 Correct 14 ms 11144 KB Output is correct
28 Correct 14 ms 11100 KB Output is correct
29 Correct 13 ms 11100 KB Output is correct
30 Correct 11 ms 11100 KB Output is correct
31 Correct 13 ms 11100 KB Output is correct
32 Correct 11 ms 11096 KB Output is correct
33 Correct 9 ms 11100 KB Output is correct
34 Correct 12 ms 11100 KB Output is correct
35 Correct 5 ms 10844 KB Output is correct
36 Correct 6 ms 10844 KB Output is correct
37 Correct 13 ms 11096 KB Output is correct
38 Correct 16 ms 11264 KB Output is correct
39 Correct 6 ms 10992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10736 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 6 ms 10840 KB Output is correct
4 Correct 4 ms 10736 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 4 ms 10736 KB Output is correct
7 Correct 4 ms 10736 KB Output is correct
8 Correct 4 ms 10732 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10736 KB Output is correct
11 Correct 203 ms 26868 KB Output is correct
12 Correct 121 ms 19828 KB Output is correct
13 Correct 115 ms 21596 KB Output is correct
14 Correct 186 ms 27124 KB Output is correct
15 Correct 153 ms 27236 KB Output is correct
16 Correct 111 ms 26868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10736 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 6 ms 10840 KB Output is correct
4 Correct 4 ms 10736 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 4 ms 10736 KB Output is correct
7 Correct 4 ms 10736 KB Output is correct
8 Correct 4 ms 10732 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10736 KB Output is correct
11 Correct 203 ms 26868 KB Output is correct
12 Correct 121 ms 19828 KB Output is correct
13 Correct 115 ms 21596 KB Output is correct
14 Correct 186 ms 27124 KB Output is correct
15 Correct 153 ms 27236 KB Output is correct
16 Correct 111 ms 26868 KB Output is correct
17 Correct 4 ms 10736 KB Output is correct
18 Correct 4 ms 10736 KB Output is correct
19 Correct 4 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 233 ms 26508 KB Output is correct
23 Correct 202 ms 26044 KB Output is correct
24 Correct 158 ms 20452 KB Output is correct
25 Correct 212 ms 27060 KB Output is correct
26 Correct 159 ms 26292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10736 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 6 ms 10840 KB Output is correct
4 Correct 4 ms 10736 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 4 ms 10736 KB Output is correct
7 Correct 4 ms 10736 KB Output is correct
8 Correct 4 ms 10732 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10736 KB Output is correct
11 Correct 203 ms 26868 KB Output is correct
12 Correct 121 ms 19828 KB Output is correct
13 Correct 115 ms 21596 KB Output is correct
14 Correct 186 ms 27124 KB Output is correct
15 Correct 153 ms 27236 KB Output is correct
16 Correct 111 ms 26868 KB Output is correct
17 Correct 4 ms 10736 KB Output is correct
18 Correct 4 ms 10736 KB Output is correct
19 Correct 4 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 233 ms 26508 KB Output is correct
23 Correct 202 ms 26044 KB Output is correct
24 Correct 158 ms 20452 KB Output is correct
25 Correct 212 ms 27060 KB Output is correct
26 Correct 159 ms 26292 KB Output is correct
27 Correct 4 ms 10844 KB Output is correct
28 Correct 4 ms 10876 KB Output is correct
29 Correct 4 ms 10844 KB Output is correct
30 Correct 4 ms 10844 KB Output is correct
31 Correct 11 ms 11192 KB Output is correct
32 Correct 5 ms 10928 KB Output is correct
33 Correct 5 ms 10840 KB Output is correct
34 Correct 298 ms 26408 KB Output is correct
35 Correct 274 ms 25920 KB Output is correct
36 Correct 297 ms 26888 KB Output is correct
37 Correct 288 ms 26700 KB Output is correct
38 Correct 184 ms 25432 KB Output is correct
39 Correct 100 ms 19156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10736 KB Output is correct
2 Correct 4 ms 10736 KB Output is correct
3 Correct 6 ms 10840 KB Output is correct
4 Correct 4 ms 10736 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 4 ms 10736 KB Output is correct
7 Correct 4 ms 10736 KB Output is correct
8 Correct 4 ms 10732 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 4 ms 10736 KB Output is correct
11 Correct 203 ms 26868 KB Output is correct
12 Correct 121 ms 19828 KB Output is correct
13 Correct 115 ms 21596 KB Output is correct
14 Correct 186 ms 27124 KB Output is correct
15 Correct 153 ms 27236 KB Output is correct
16 Correct 111 ms 26868 KB Output is correct
17 Correct 4 ms 10736 KB Output is correct
18 Correct 4 ms 10736 KB Output is correct
19 Correct 4 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 233 ms 26508 KB Output is correct
23 Correct 202 ms 26044 KB Output is correct
24 Correct 158 ms 20452 KB Output is correct
25 Correct 212 ms 27060 KB Output is correct
26 Correct 159 ms 26292 KB Output is correct
27 Correct 4 ms 10844 KB Output is correct
28 Correct 4 ms 10876 KB Output is correct
29 Correct 4 ms 10844 KB Output is correct
30 Correct 4 ms 10844 KB Output is correct
31 Correct 11 ms 11192 KB Output is correct
32 Correct 5 ms 10928 KB Output is correct
33 Correct 5 ms 10840 KB Output is correct
34 Correct 298 ms 26408 KB Output is correct
35 Correct 274 ms 25920 KB Output is correct
36 Correct 297 ms 26888 KB Output is correct
37 Correct 288 ms 26700 KB Output is correct
38 Correct 184 ms 25432 KB Output is correct
39 Correct 100 ms 19156 KB Output is correct
40 Correct 10 ms 11100 KB Output is correct
41 Correct 13 ms 11200 KB Output is correct
42 Correct 8 ms 11100 KB Output is correct
43 Correct 11 ms 11200 KB Output is correct
44 Correct 419 ms 26740 KB Output is correct
45 Correct 390 ms 26096 KB Output is correct
46 Correct 411 ms 26328 KB Output is correct
47 Correct 388 ms 26164 KB Output is correct
48 Correct 221 ms 26904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10736 KB Output is correct
2 Correct 3 ms 10736 KB Output is correct
3 Correct 4 ms 10704 KB Output is correct
4 Correct 4 ms 10736 KB Output is correct
5 Correct 4 ms 10736 KB Output is correct
6 Correct 4 ms 10736 KB Output is correct
7 Correct 4 ms 10732 KB Output is correct
8 Correct 4 ms 10736 KB Output is correct
9 Correct 4 ms 10736 KB Output is correct
10 Correct 5 ms 10736 KB Output is correct
11 Correct 4 ms 10736 KB Output is correct
12 Correct 4 ms 10664 KB Output is correct
13 Correct 4 ms 10736 KB Output is correct
14 Correct 4 ms 10872 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 11096 KB Output is correct
19 Correct 4 ms 10844 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 4 ms 10844 KB Output is correct
22 Correct 5 ms 10840 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 11100 KB Output is correct
27 Correct 14 ms 11144 KB Output is correct
28 Correct 14 ms 11100 KB Output is correct
29 Correct 13 ms 11100 KB Output is correct
30 Correct 11 ms 11100 KB Output is correct
31 Correct 13 ms 11100 KB Output is correct
32 Correct 11 ms 11096 KB Output is correct
33 Correct 9 ms 11100 KB Output is correct
34 Correct 12 ms 11100 KB Output is correct
35 Correct 5 ms 10844 KB Output is correct
36 Correct 6 ms 10844 KB Output is correct
37 Correct 13 ms 11096 KB Output is correct
38 Correct 16 ms 11264 KB Output is correct
39 Correct 6 ms 10992 KB Output is correct
40 Correct 4 ms 10736 KB Output is correct
41 Correct 4 ms 10736 KB Output is correct
42 Correct 6 ms 10840 KB Output is correct
43 Correct 4 ms 10736 KB Output is correct
44 Correct 4 ms 10736 KB Output is correct
45 Correct 4 ms 10736 KB Output is correct
46 Correct 4 ms 10736 KB Output is correct
47 Correct 4 ms 10732 KB Output is correct
48 Correct 4 ms 10736 KB Output is correct
49 Correct 4 ms 10736 KB Output is correct
50 Correct 203 ms 26868 KB Output is correct
51 Correct 121 ms 19828 KB Output is correct
52 Correct 115 ms 21596 KB Output is correct
53 Correct 186 ms 27124 KB Output is correct
54 Correct 153 ms 27236 KB Output is correct
55 Correct 111 ms 26868 KB Output is correct
56 Correct 4 ms 10736 KB Output is correct
57 Correct 4 ms 10736 KB Output is correct
58 Correct 4 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 233 ms 26508 KB Output is correct
62 Correct 202 ms 26044 KB Output is correct
63 Correct 158 ms 20452 KB Output is correct
64 Correct 212 ms 27060 KB Output is correct
65 Correct 159 ms 26292 KB Output is correct
66 Correct 4 ms 10844 KB Output is correct
67 Correct 4 ms 10876 KB Output is correct
68 Correct 4 ms 10844 KB Output is correct
69 Correct 4 ms 10844 KB Output is correct
70 Correct 11 ms 11192 KB Output is correct
71 Correct 5 ms 10928 KB Output is correct
72 Correct 5 ms 10840 KB Output is correct
73 Correct 298 ms 26408 KB Output is correct
74 Correct 274 ms 25920 KB Output is correct
75 Correct 297 ms 26888 KB Output is correct
76 Correct 288 ms 26700 KB Output is correct
77 Correct 184 ms 25432 KB Output is correct
78 Correct 100 ms 19156 KB Output is correct
79 Correct 10 ms 11100 KB Output is correct
80 Correct 13 ms 11200 KB Output is correct
81 Correct 8 ms 11100 KB Output is correct
82 Correct 11 ms 11200 KB Output is correct
83 Correct 419 ms 26740 KB Output is correct
84 Correct 390 ms 26096 KB Output is correct
85 Correct 411 ms 26328 KB Output is correct
86 Correct 388 ms 26164 KB Output is correct
87 Correct 221 ms 26904 KB Output is correct
88 Correct 611 ms 27324 KB Output is correct
89 Correct 562 ms 27432 KB Output is correct
90 Correct 567 ms 26576 KB Output is correct
91 Correct 524 ms 26676 KB Output is correct
92 Correct 502 ms 27516 KB Output is correct
93 Correct 551 ms 26984 KB Output is correct
94 Correct 515 ms 26744 KB Output is correct
95 Correct 259 ms 25944 KB Output is correct
96 Correct 527 ms 27052 KB Output is correct
97 Correct 135 ms 26756 KB Output is correct
98 Correct 222 ms 27052 KB Output is correct
99 Correct 361 ms 26788 KB Output is correct