답안 #887612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887612 2023-12-14T20:22:49 Z MinaRagy06 Team Contest (JOI22_team) C++17
100 / 100
653 ms 123564 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define md ((l + r) >> 1) 

const int inf = 1e9;
int y = -1, mncnt = 2, mxcnt = 2;
struct nodemn {
	int l, r, v;
	nodemn() {l = 0, r = 0, v = 1e9;}
} segmn[5'000'005];
struct nodemx {
	int l, r, v;
	nodemx() {l = 0, r = 0, v = -1e9;}
} segmx[5'000'005];
void updmn(int i, int l, int r, int x, int v) {
	if (l == r) {
		segmn[i].v = min(segmn[i].v, v);
		return;
	}
	if (x <= md) {
		if (!segmn[i].l) {
			segmn[i].l = mncnt++;
		}
		updmn(segmn[i].l, l, md, x, v);
	} else {
		if (!segmn[i].r) {
			segmn[i].r = mncnt++;
		}
		updmn(segmn[i].r, md + 1, r, x, v);
	}
	segmn[i].v = min(segmn[segmn[i].l].v, segmn[segmn[i].r].v);
}
void updmx(int i, int l, int r, int x, int v) {
	if (l == r) {
		segmx[i].v = max(segmx[i].v, v);
		return;
	}
	if (x <= md) {
		if (!segmx[i].l) {
			segmx[i].l = mxcnt++;
		}
		updmx(segmx[i].l, l, md, x, v);
	} else {
		if (!segmx[i].r) {
			segmx[i].r = mxcnt++;
		}
		updmx(segmx[i].r, md + 1, r, x, v);
	}
	segmx[i].v = max(segmx[segmx[i].l].v, segmx[segmx[i].r].v);
}
int getmn(int i, int l, int r, int s, int e) {
	if (i == 0 || r < s || e < l) {
		return 1e9;
	}
	if (s <= l && r <= e) {
		return segmn[i].v;
	}
	return min(getmn(segmn[i].l, l, md, s, e), getmn(segmn[i].r, md + 1, r, s, e));
}
int getmx(int i, int l, int r, int s, int e) {
	if (i == 0 || r < s || e < l) {
		return -1e9;
	}
	if (s <= l && r <= e) {
		return segmx[i].v;
	}
	return max(getmx(segmx[i].l, l, md, s, e), getmx(segmx[i].r, md + 1, r, s, e));
}
int get(int i, int l, int r, int s, int e, int k) {
	if (l == r) {
		return l;
	}
	if (md + 1 <= e && getmn(1, 0, 1e8, md + 1, min(r, e)) < k) {
		return get(segmn[i].r, md + 1, r, s, e, k);
	} else {
		return get(segmn[i].l, l, md, s, e, k);
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	array<int, 3> a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	sort(a, a + n);
	int ans = -1;
	int cur = 0;
	for (int i = 0; i < n; i++) {
		while (a[cur][0] < a[i][0]) {
			updmn(1, 0, 1e8, a[cur][1], a[cur][2]);
			updmx(1, 0, 1e8, a[cur][1], a[cur][2]);
			if (getmx(1, 0, 1e8, 0, a[cur][1] - 1) > a[cur][2]) {
				y = max(y, a[cur][1]);
			}
			if (a[cur][1] + 1 != int(1e8) && getmn(1, 0, 1e8, a[cur][1] + 1, 1e8) < a[cur][2]) {
				int newy = get(1, 0, 1e8, a[cur][1] + 1, 1e8, a[cur][2]);
				y = max(y, newy);
			}
			cur++;
		}
// 		while (a[cur][0] < a[i][0]) {
// 			mx[a[cur][1]] = max(mx[a[cur][1]], a[cur][2]);
// 			mn[a[cur][1]] = min(mn[a[cur][1]], a[cur][2]);
// 			for (int newy = 304; newy > a[cur][1]; newy--) {
// 				if (mn[newy] < a[cur][2]) {
// 					y = max(y, newy);
// 					break;
// 				}
// 			}
// 			for (int newy = 0; newy < a[cur][1]; newy++) {
// 				if (mx[newy] > a[cur][2]) {
// 					y = max(y, a[cur][1]);
// 					break;
// 				}
// 			}
// 			cur++;
// 		}
		if (y >= max(1, a[i][1] + 1)) {
			int z = getmx(1, 0, 1e8, 0, y - 1);
			if (a[i][2] < z) {
				ans = max(ans, a[i][0] + z + y);
			}
		}
	}
	cout << ans << '\n';
	return 0;
}
 
 
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 117848 KB Output is correct
2 Correct 21 ms 117816 KB Output is correct
3 Correct 21 ms 118036 KB Output is correct
4 Correct 21 ms 117852 KB Output is correct
5 Correct 21 ms 117820 KB Output is correct
6 Correct 22 ms 117852 KB Output is correct
7 Correct 22 ms 117840 KB Output is correct
8 Correct 21 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117760 KB Output is correct
11 Correct 21 ms 117820 KB Output is correct
12 Correct 21 ms 117852 KB Output is correct
13 Correct 22 ms 117864 KB Output is correct
14 Correct 22 ms 117852 KB Output is correct
15 Correct 22 ms 117852 KB Output is correct
16 Correct 22 ms 117768 KB Output is correct
17 Correct 23 ms 117856 KB Output is correct
18 Correct 22 ms 117820 KB Output is correct
19 Correct 22 ms 117844 KB Output is correct
20 Correct 21 ms 117852 KB Output is correct
21 Correct 23 ms 117852 KB Output is correct
22 Correct 21 ms 117844 KB Output is correct
23 Correct 21 ms 117848 KB Output is correct
24 Correct 21 ms 117844 KB Output is correct
25 Correct 21 ms 117768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 117848 KB Output is correct
2 Correct 21 ms 117816 KB Output is correct
3 Correct 21 ms 118036 KB Output is correct
4 Correct 21 ms 117852 KB Output is correct
5 Correct 21 ms 117820 KB Output is correct
6 Correct 22 ms 117852 KB Output is correct
7 Correct 22 ms 117840 KB Output is correct
8 Correct 21 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117760 KB Output is correct
11 Correct 21 ms 117820 KB Output is correct
12 Correct 21 ms 117852 KB Output is correct
13 Correct 22 ms 117864 KB Output is correct
14 Correct 22 ms 117852 KB Output is correct
15 Correct 22 ms 117852 KB Output is correct
16 Correct 22 ms 117768 KB Output is correct
17 Correct 23 ms 117856 KB Output is correct
18 Correct 22 ms 117820 KB Output is correct
19 Correct 22 ms 117844 KB Output is correct
20 Correct 21 ms 117852 KB Output is correct
21 Correct 23 ms 117852 KB Output is correct
22 Correct 21 ms 117844 KB Output is correct
23 Correct 21 ms 117848 KB Output is correct
24 Correct 21 ms 117844 KB Output is correct
25 Correct 21 ms 117768 KB Output is correct
26 Correct 36 ms 117840 KB Output is correct
27 Correct 35 ms 117860 KB Output is correct
28 Correct 37 ms 118016 KB Output is correct
29 Correct 29 ms 117840 KB Output is correct
30 Correct 28 ms 117844 KB Output is correct
31 Correct 34 ms 117840 KB Output is correct
32 Correct 29 ms 117960 KB Output is correct
33 Correct 23 ms 117852 KB Output is correct
34 Correct 27 ms 117848 KB Output is correct
35 Correct 22 ms 117820 KB Output is correct
36 Correct 23 ms 117844 KB Output is correct
37 Correct 24 ms 117796 KB Output is correct
38 Correct 25 ms 117848 KB Output is correct
39 Correct 27 ms 117852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 117848 KB Output is correct
2 Correct 21 ms 117852 KB Output is correct
3 Correct 21 ms 117852 KB Output is correct
4 Correct 21 ms 117740 KB Output is correct
5 Correct 21 ms 117776 KB Output is correct
6 Correct 21 ms 117852 KB Output is correct
7 Correct 22 ms 117840 KB Output is correct
8 Correct 21 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117780 KB Output is correct
11 Correct 277 ms 119608 KB Output is correct
12 Correct 154 ms 118864 KB Output is correct
13 Correct 129 ms 119296 KB Output is correct
14 Correct 157 ms 119376 KB Output is correct
15 Correct 78 ms 119624 KB Output is correct
16 Correct 47 ms 119388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 117848 KB Output is correct
2 Correct 21 ms 117852 KB Output is correct
3 Correct 21 ms 117852 KB Output is correct
4 Correct 21 ms 117740 KB Output is correct
5 Correct 21 ms 117776 KB Output is correct
6 Correct 21 ms 117852 KB Output is correct
7 Correct 22 ms 117840 KB Output is correct
8 Correct 21 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117780 KB Output is correct
11 Correct 277 ms 119608 KB Output is correct
12 Correct 154 ms 118864 KB Output is correct
13 Correct 129 ms 119296 KB Output is correct
14 Correct 157 ms 119376 KB Output is correct
15 Correct 78 ms 119624 KB Output is correct
16 Correct 47 ms 119388 KB Output is correct
17 Correct 21 ms 117852 KB Output is correct
18 Correct 22 ms 117852 KB Output is correct
19 Correct 21 ms 117840 KB Output is correct
20 Correct 21 ms 117852 KB Output is correct
21 Correct 27 ms 117852 KB Output is correct
22 Correct 456 ms 119636 KB Output is correct
23 Correct 400 ms 119384 KB Output is correct
24 Correct 222 ms 119124 KB Output is correct
25 Correct 251 ms 119388 KB Output is correct
26 Correct 76 ms 119388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 117848 KB Output is correct
2 Correct 21 ms 117852 KB Output is correct
3 Correct 21 ms 117852 KB Output is correct
4 Correct 21 ms 117740 KB Output is correct
5 Correct 21 ms 117776 KB Output is correct
6 Correct 21 ms 117852 KB Output is correct
7 Correct 22 ms 117840 KB Output is correct
8 Correct 21 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117780 KB Output is correct
11 Correct 277 ms 119608 KB Output is correct
12 Correct 154 ms 118864 KB Output is correct
13 Correct 129 ms 119296 KB Output is correct
14 Correct 157 ms 119376 KB Output is correct
15 Correct 78 ms 119624 KB Output is correct
16 Correct 47 ms 119388 KB Output is correct
17 Correct 21 ms 117852 KB Output is correct
18 Correct 22 ms 117852 KB Output is correct
19 Correct 21 ms 117840 KB Output is correct
20 Correct 21 ms 117852 KB Output is correct
21 Correct 27 ms 117852 KB Output is correct
22 Correct 456 ms 119636 KB Output is correct
23 Correct 400 ms 119384 KB Output is correct
24 Correct 222 ms 119124 KB Output is correct
25 Correct 251 ms 119388 KB Output is correct
26 Correct 76 ms 119388 KB Output is correct
27 Correct 22 ms 117852 KB Output is correct
28 Correct 22 ms 117824 KB Output is correct
29 Correct 22 ms 117852 KB Output is correct
30 Correct 22 ms 117740 KB Output is correct
31 Correct 28 ms 117820 KB Output is correct
32 Correct 21 ms 117700 KB Output is correct
33 Correct 22 ms 117852 KB Output is correct
34 Correct 525 ms 119636 KB Output is correct
35 Correct 397 ms 119444 KB Output is correct
36 Correct 459 ms 119860 KB Output is correct
37 Correct 284 ms 119388 KB Output is correct
38 Correct 92 ms 119568 KB Output is correct
39 Correct 38 ms 118840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 117848 KB Output is correct
2 Correct 21 ms 117852 KB Output is correct
3 Correct 21 ms 117852 KB Output is correct
4 Correct 21 ms 117740 KB Output is correct
5 Correct 21 ms 117776 KB Output is correct
6 Correct 21 ms 117852 KB Output is correct
7 Correct 22 ms 117840 KB Output is correct
8 Correct 21 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117780 KB Output is correct
11 Correct 277 ms 119608 KB Output is correct
12 Correct 154 ms 118864 KB Output is correct
13 Correct 129 ms 119296 KB Output is correct
14 Correct 157 ms 119376 KB Output is correct
15 Correct 78 ms 119624 KB Output is correct
16 Correct 47 ms 119388 KB Output is correct
17 Correct 21 ms 117852 KB Output is correct
18 Correct 22 ms 117852 KB Output is correct
19 Correct 21 ms 117840 KB Output is correct
20 Correct 21 ms 117852 KB Output is correct
21 Correct 27 ms 117852 KB Output is correct
22 Correct 456 ms 119636 KB Output is correct
23 Correct 400 ms 119384 KB Output is correct
24 Correct 222 ms 119124 KB Output is correct
25 Correct 251 ms 119388 KB Output is correct
26 Correct 76 ms 119388 KB Output is correct
27 Correct 22 ms 117852 KB Output is correct
28 Correct 22 ms 117824 KB Output is correct
29 Correct 22 ms 117852 KB Output is correct
30 Correct 22 ms 117740 KB Output is correct
31 Correct 28 ms 117820 KB Output is correct
32 Correct 21 ms 117700 KB Output is correct
33 Correct 22 ms 117852 KB Output is correct
34 Correct 525 ms 119636 KB Output is correct
35 Correct 397 ms 119444 KB Output is correct
36 Correct 459 ms 119860 KB Output is correct
37 Correct 284 ms 119388 KB Output is correct
38 Correct 92 ms 119568 KB Output is correct
39 Correct 38 ms 118840 KB Output is correct
40 Correct 28 ms 117852 KB Output is correct
41 Correct 36 ms 117868 KB Output is correct
42 Correct 25 ms 117852 KB Output is correct
43 Correct 24 ms 117840 KB Output is correct
44 Correct 538 ms 121684 KB Output is correct
45 Correct 311 ms 121736 KB Output is correct
46 Correct 378 ms 121424 KB Output is correct
47 Correct 291 ms 121756 KB Output is correct
48 Correct 84 ms 121424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 117848 KB Output is correct
2 Correct 21 ms 117816 KB Output is correct
3 Correct 21 ms 118036 KB Output is correct
4 Correct 21 ms 117852 KB Output is correct
5 Correct 21 ms 117820 KB Output is correct
6 Correct 22 ms 117852 KB Output is correct
7 Correct 22 ms 117840 KB Output is correct
8 Correct 21 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117760 KB Output is correct
11 Correct 21 ms 117820 KB Output is correct
12 Correct 21 ms 117852 KB Output is correct
13 Correct 22 ms 117864 KB Output is correct
14 Correct 22 ms 117852 KB Output is correct
15 Correct 22 ms 117852 KB Output is correct
16 Correct 22 ms 117768 KB Output is correct
17 Correct 23 ms 117856 KB Output is correct
18 Correct 22 ms 117820 KB Output is correct
19 Correct 22 ms 117844 KB Output is correct
20 Correct 21 ms 117852 KB Output is correct
21 Correct 23 ms 117852 KB Output is correct
22 Correct 21 ms 117844 KB Output is correct
23 Correct 21 ms 117848 KB Output is correct
24 Correct 21 ms 117844 KB Output is correct
25 Correct 21 ms 117768 KB Output is correct
26 Correct 36 ms 117840 KB Output is correct
27 Correct 35 ms 117860 KB Output is correct
28 Correct 37 ms 118016 KB Output is correct
29 Correct 29 ms 117840 KB Output is correct
30 Correct 28 ms 117844 KB Output is correct
31 Correct 34 ms 117840 KB Output is correct
32 Correct 29 ms 117960 KB Output is correct
33 Correct 23 ms 117852 KB Output is correct
34 Correct 27 ms 117848 KB Output is correct
35 Correct 22 ms 117820 KB Output is correct
36 Correct 23 ms 117844 KB Output is correct
37 Correct 24 ms 117796 KB Output is correct
38 Correct 25 ms 117848 KB Output is correct
39 Correct 27 ms 117852 KB Output is correct
40 Correct 21 ms 117848 KB Output is correct
41 Correct 21 ms 117852 KB Output is correct
42 Correct 21 ms 117852 KB Output is correct
43 Correct 21 ms 117740 KB Output is correct
44 Correct 21 ms 117776 KB Output is correct
45 Correct 21 ms 117852 KB Output is correct
46 Correct 22 ms 117840 KB Output is correct
47 Correct 21 ms 117852 KB Output is correct
48 Correct 21 ms 117852 KB Output is correct
49 Correct 21 ms 117780 KB Output is correct
50 Correct 277 ms 119608 KB Output is correct
51 Correct 154 ms 118864 KB Output is correct
52 Correct 129 ms 119296 KB Output is correct
53 Correct 157 ms 119376 KB Output is correct
54 Correct 78 ms 119624 KB Output is correct
55 Correct 47 ms 119388 KB Output is correct
56 Correct 21 ms 117852 KB Output is correct
57 Correct 22 ms 117852 KB Output is correct
58 Correct 21 ms 117840 KB Output is correct
59 Correct 21 ms 117852 KB Output is correct
60 Correct 27 ms 117852 KB Output is correct
61 Correct 456 ms 119636 KB Output is correct
62 Correct 400 ms 119384 KB Output is correct
63 Correct 222 ms 119124 KB Output is correct
64 Correct 251 ms 119388 KB Output is correct
65 Correct 76 ms 119388 KB Output is correct
66 Correct 22 ms 117852 KB Output is correct
67 Correct 22 ms 117824 KB Output is correct
68 Correct 22 ms 117852 KB Output is correct
69 Correct 22 ms 117740 KB Output is correct
70 Correct 28 ms 117820 KB Output is correct
71 Correct 21 ms 117700 KB Output is correct
72 Correct 22 ms 117852 KB Output is correct
73 Correct 525 ms 119636 KB Output is correct
74 Correct 397 ms 119444 KB Output is correct
75 Correct 459 ms 119860 KB Output is correct
76 Correct 284 ms 119388 KB Output is correct
77 Correct 92 ms 119568 KB Output is correct
78 Correct 38 ms 118840 KB Output is correct
79 Correct 28 ms 117852 KB Output is correct
80 Correct 36 ms 117868 KB Output is correct
81 Correct 25 ms 117852 KB Output is correct
82 Correct 24 ms 117840 KB Output is correct
83 Correct 538 ms 121684 KB Output is correct
84 Correct 311 ms 121736 KB Output is correct
85 Correct 378 ms 121424 KB Output is correct
86 Correct 291 ms 121756 KB Output is correct
87 Correct 84 ms 121424 KB Output is correct
88 Correct 653 ms 123476 KB Output is correct
89 Correct 490 ms 123520 KB Output is correct
90 Correct 615 ms 123520 KB Output is correct
91 Correct 347 ms 123308 KB Output is correct
92 Correct 498 ms 122192 KB Output is correct
93 Correct 374 ms 122380 KB Output is correct
94 Correct 321 ms 122432 KB Output is correct
95 Correct 91 ms 123392 KB Output is correct
96 Correct 195 ms 123472 KB Output is correct
97 Correct 63 ms 123564 KB Output is correct
98 Correct 154 ms 121936 KB Output is correct
99 Correct 168 ms 122132 KB Output is correct