Submission #887617

# Submission time Handle Problem Language Result Execution time Memory
887617 2023-12-14T20:34:55 Z MinaRagy06 Team Contest (JOI22_team) C++17
100 / 100
315 ms 119720 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 && segmn[segmn[i].r].v < 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;
}
 
 
# Verdict Execution time Memory Grader output
1 Correct 22 ms 117840 KB Output is correct
2 Correct 21 ms 117812 KB Output is correct
3 Correct 21 ms 117848 KB Output is correct
4 Correct 21 ms 117828 KB Output is correct
5 Correct 22 ms 118064 KB Output is correct
6 Correct 22 ms 117756 KB Output is correct
7 Correct 21 ms 117852 KB Output is correct
8 Correct 21 ms 117852 KB Output is correct
9 Correct 22 ms 117852 KB Output is correct
10 Correct 22 ms 117784 KB Output is correct
11 Correct 22 ms 117688 KB Output is correct
12 Correct 24 ms 117840 KB Output is correct
13 Correct 22 ms 117852 KB Output is correct
14 Correct 22 ms 117728 KB Output is correct
15 Correct 22 ms 117852 KB Output is correct
16 Correct 22 ms 117852 KB Output is correct
17 Correct 22 ms 117776 KB Output is correct
18 Correct 21 ms 117848 KB Output is correct
19 Correct 21 ms 117852 KB Output is correct
20 Correct 21 ms 117848 KB Output is correct
21 Correct 22 ms 117740 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 117840 KB Output is correct
25 Correct 21 ms 117840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 117840 KB Output is correct
2 Correct 21 ms 117812 KB Output is correct
3 Correct 21 ms 117848 KB Output is correct
4 Correct 21 ms 117828 KB Output is correct
5 Correct 22 ms 118064 KB Output is correct
6 Correct 22 ms 117756 KB Output is correct
7 Correct 21 ms 117852 KB Output is correct
8 Correct 21 ms 117852 KB Output is correct
9 Correct 22 ms 117852 KB Output is correct
10 Correct 22 ms 117784 KB Output is correct
11 Correct 22 ms 117688 KB Output is correct
12 Correct 24 ms 117840 KB Output is correct
13 Correct 22 ms 117852 KB Output is correct
14 Correct 22 ms 117728 KB Output is correct
15 Correct 22 ms 117852 KB Output is correct
16 Correct 22 ms 117852 KB Output is correct
17 Correct 22 ms 117776 KB Output is correct
18 Correct 21 ms 117848 KB Output is correct
19 Correct 21 ms 117852 KB Output is correct
20 Correct 21 ms 117848 KB Output is correct
21 Correct 22 ms 117740 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 117840 KB Output is correct
25 Correct 21 ms 117840 KB Output is correct
26 Correct 31 ms 118232 KB Output is correct
27 Correct 31 ms 117776 KB Output is correct
28 Correct 28 ms 117788 KB Output is correct
29 Correct 26 ms 117844 KB Output is correct
30 Correct 24 ms 117852 KB Output is correct
31 Correct 26 ms 117768 KB Output is correct
32 Correct 26 ms 117852 KB Output is correct
33 Correct 23 ms 117852 KB Output is correct
34 Correct 26 ms 117780 KB Output is correct
35 Correct 22 ms 117840 KB Output is correct
36 Correct 22 ms 117852 KB Output is correct
37 Correct 25 ms 117852 KB Output is correct
38 Correct 25 ms 117852 KB Output is correct
39 Correct 23 ms 117852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 117824 KB Output is correct
2 Correct 21 ms 117844 KB Output is correct
3 Correct 22 ms 117852 KB Output is correct
4 Correct 21 ms 117844 KB Output is correct
5 Correct 21 ms 117852 KB Output is correct
6 Correct 21 ms 117852 KB Output is correct
7 Correct 21 ms 117824 KB Output is correct
8 Correct 22 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117852 KB Output is correct
11 Correct 151 ms 119584 KB Output is correct
12 Correct 106 ms 118872 KB Output is correct
13 Correct 123 ms 119132 KB Output is correct
14 Correct 131 ms 119604 KB Output is correct
15 Correct 74 ms 119388 KB Output is correct
16 Correct 47 ms 119376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 117824 KB Output is correct
2 Correct 21 ms 117844 KB Output is correct
3 Correct 22 ms 117852 KB Output is correct
4 Correct 21 ms 117844 KB Output is correct
5 Correct 21 ms 117852 KB Output is correct
6 Correct 21 ms 117852 KB Output is correct
7 Correct 21 ms 117824 KB Output is correct
8 Correct 22 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117852 KB Output is correct
11 Correct 151 ms 119584 KB Output is correct
12 Correct 106 ms 118872 KB Output is correct
13 Correct 123 ms 119132 KB Output is correct
14 Correct 131 ms 119604 KB Output is correct
15 Correct 74 ms 119388 KB Output is correct
16 Correct 47 ms 119376 KB Output is correct
17 Correct 22 ms 117828 KB Output is correct
18 Correct 21 ms 117840 KB Output is correct
19 Correct 21 ms 117772 KB Output is correct
20 Correct 21 ms 117756 KB Output is correct
21 Correct 23 ms 117852 KB Output is correct
22 Correct 184 ms 119380 KB Output is correct
23 Correct 172 ms 119564 KB Output is correct
24 Correct 130 ms 119128 KB Output is correct
25 Correct 155 ms 119384 KB Output is correct
26 Correct 78 ms 119376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 117824 KB Output is correct
2 Correct 21 ms 117844 KB Output is correct
3 Correct 22 ms 117852 KB Output is correct
4 Correct 21 ms 117844 KB Output is correct
5 Correct 21 ms 117852 KB Output is correct
6 Correct 21 ms 117852 KB Output is correct
7 Correct 21 ms 117824 KB Output is correct
8 Correct 22 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117852 KB Output is correct
11 Correct 151 ms 119584 KB Output is correct
12 Correct 106 ms 118872 KB Output is correct
13 Correct 123 ms 119132 KB Output is correct
14 Correct 131 ms 119604 KB Output is correct
15 Correct 74 ms 119388 KB Output is correct
16 Correct 47 ms 119376 KB Output is correct
17 Correct 22 ms 117828 KB Output is correct
18 Correct 21 ms 117840 KB Output is correct
19 Correct 21 ms 117772 KB Output is correct
20 Correct 21 ms 117756 KB Output is correct
21 Correct 23 ms 117852 KB Output is correct
22 Correct 184 ms 119380 KB Output is correct
23 Correct 172 ms 119564 KB Output is correct
24 Correct 130 ms 119128 KB Output is correct
25 Correct 155 ms 119384 KB Output is correct
26 Correct 78 ms 119376 KB Output is correct
27 Correct 21 ms 117852 KB Output is correct
28 Correct 21 ms 117784 KB Output is correct
29 Correct 21 ms 117848 KB Output is correct
30 Correct 21 ms 118104 KB Output is correct
31 Correct 24 ms 117848 KB Output is correct
32 Correct 22 ms 117852 KB Output is correct
33 Correct 22 ms 117712 KB Output is correct
34 Correct 186 ms 119528 KB Output is correct
35 Correct 167 ms 119444 KB Output is correct
36 Correct 184 ms 119608 KB Output is correct
37 Correct 170 ms 119380 KB Output is correct
38 Correct 78 ms 119380 KB Output is correct
39 Correct 39 ms 118772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 117824 KB Output is correct
2 Correct 21 ms 117844 KB Output is correct
3 Correct 22 ms 117852 KB Output is correct
4 Correct 21 ms 117844 KB Output is correct
5 Correct 21 ms 117852 KB Output is correct
6 Correct 21 ms 117852 KB Output is correct
7 Correct 21 ms 117824 KB Output is correct
8 Correct 22 ms 117852 KB Output is correct
9 Correct 21 ms 117852 KB Output is correct
10 Correct 21 ms 117852 KB Output is correct
11 Correct 151 ms 119584 KB Output is correct
12 Correct 106 ms 118872 KB Output is correct
13 Correct 123 ms 119132 KB Output is correct
14 Correct 131 ms 119604 KB Output is correct
15 Correct 74 ms 119388 KB Output is correct
16 Correct 47 ms 119376 KB Output is correct
17 Correct 22 ms 117828 KB Output is correct
18 Correct 21 ms 117840 KB Output is correct
19 Correct 21 ms 117772 KB Output is correct
20 Correct 21 ms 117756 KB Output is correct
21 Correct 23 ms 117852 KB Output is correct
22 Correct 184 ms 119380 KB Output is correct
23 Correct 172 ms 119564 KB Output is correct
24 Correct 130 ms 119128 KB Output is correct
25 Correct 155 ms 119384 KB Output is correct
26 Correct 78 ms 119376 KB Output is correct
27 Correct 21 ms 117852 KB Output is correct
28 Correct 21 ms 117784 KB Output is correct
29 Correct 21 ms 117848 KB Output is correct
30 Correct 21 ms 118104 KB Output is correct
31 Correct 24 ms 117848 KB Output is correct
32 Correct 22 ms 117852 KB Output is correct
33 Correct 22 ms 117712 KB Output is correct
34 Correct 186 ms 119528 KB Output is correct
35 Correct 167 ms 119444 KB Output is correct
36 Correct 184 ms 119608 KB Output is correct
37 Correct 170 ms 119380 KB Output is correct
38 Correct 78 ms 119380 KB Output is correct
39 Correct 39 ms 118772 KB Output is correct
40 Correct 25 ms 117840 KB Output is correct
41 Correct 26 ms 117848 KB Output is correct
42 Correct 25 ms 117844 KB Output is correct
43 Correct 25 ms 117844 KB Output is correct
44 Correct 205 ms 119612 KB Output is correct
45 Correct 187 ms 119636 KB Output is correct
46 Correct 189 ms 119376 KB Output is correct
47 Correct 178 ms 119384 KB Output is correct
48 Correct 82 ms 119388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 117840 KB Output is correct
2 Correct 21 ms 117812 KB Output is correct
3 Correct 21 ms 117848 KB Output is correct
4 Correct 21 ms 117828 KB Output is correct
5 Correct 22 ms 118064 KB Output is correct
6 Correct 22 ms 117756 KB Output is correct
7 Correct 21 ms 117852 KB Output is correct
8 Correct 21 ms 117852 KB Output is correct
9 Correct 22 ms 117852 KB Output is correct
10 Correct 22 ms 117784 KB Output is correct
11 Correct 22 ms 117688 KB Output is correct
12 Correct 24 ms 117840 KB Output is correct
13 Correct 22 ms 117852 KB Output is correct
14 Correct 22 ms 117728 KB Output is correct
15 Correct 22 ms 117852 KB Output is correct
16 Correct 22 ms 117852 KB Output is correct
17 Correct 22 ms 117776 KB Output is correct
18 Correct 21 ms 117848 KB Output is correct
19 Correct 21 ms 117852 KB Output is correct
20 Correct 21 ms 117848 KB Output is correct
21 Correct 22 ms 117740 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 117840 KB Output is correct
25 Correct 21 ms 117840 KB Output is correct
26 Correct 31 ms 118232 KB Output is correct
27 Correct 31 ms 117776 KB Output is correct
28 Correct 28 ms 117788 KB Output is correct
29 Correct 26 ms 117844 KB Output is correct
30 Correct 24 ms 117852 KB Output is correct
31 Correct 26 ms 117768 KB Output is correct
32 Correct 26 ms 117852 KB Output is correct
33 Correct 23 ms 117852 KB Output is correct
34 Correct 26 ms 117780 KB Output is correct
35 Correct 22 ms 117840 KB Output is correct
36 Correct 22 ms 117852 KB Output is correct
37 Correct 25 ms 117852 KB Output is correct
38 Correct 25 ms 117852 KB Output is correct
39 Correct 23 ms 117852 KB Output is correct
40 Correct 21 ms 117824 KB Output is correct
41 Correct 21 ms 117844 KB Output is correct
42 Correct 22 ms 117852 KB Output is correct
43 Correct 21 ms 117844 KB Output is correct
44 Correct 21 ms 117852 KB Output is correct
45 Correct 21 ms 117852 KB Output is correct
46 Correct 21 ms 117824 KB Output is correct
47 Correct 22 ms 117852 KB Output is correct
48 Correct 21 ms 117852 KB Output is correct
49 Correct 21 ms 117852 KB Output is correct
50 Correct 151 ms 119584 KB Output is correct
51 Correct 106 ms 118872 KB Output is correct
52 Correct 123 ms 119132 KB Output is correct
53 Correct 131 ms 119604 KB Output is correct
54 Correct 74 ms 119388 KB Output is correct
55 Correct 47 ms 119376 KB Output is correct
56 Correct 22 ms 117828 KB Output is correct
57 Correct 21 ms 117840 KB Output is correct
58 Correct 21 ms 117772 KB Output is correct
59 Correct 21 ms 117756 KB Output is correct
60 Correct 23 ms 117852 KB Output is correct
61 Correct 184 ms 119380 KB Output is correct
62 Correct 172 ms 119564 KB Output is correct
63 Correct 130 ms 119128 KB Output is correct
64 Correct 155 ms 119384 KB Output is correct
65 Correct 78 ms 119376 KB Output is correct
66 Correct 21 ms 117852 KB Output is correct
67 Correct 21 ms 117784 KB Output is correct
68 Correct 21 ms 117848 KB Output is correct
69 Correct 21 ms 118104 KB Output is correct
70 Correct 24 ms 117848 KB Output is correct
71 Correct 22 ms 117852 KB Output is correct
72 Correct 22 ms 117712 KB Output is correct
73 Correct 186 ms 119528 KB Output is correct
74 Correct 167 ms 119444 KB Output is correct
75 Correct 184 ms 119608 KB Output is correct
76 Correct 170 ms 119380 KB Output is correct
77 Correct 78 ms 119380 KB Output is correct
78 Correct 39 ms 118772 KB Output is correct
79 Correct 25 ms 117840 KB Output is correct
80 Correct 26 ms 117848 KB Output is correct
81 Correct 25 ms 117844 KB Output is correct
82 Correct 25 ms 117844 KB Output is correct
83 Correct 205 ms 119612 KB Output is correct
84 Correct 187 ms 119636 KB Output is correct
85 Correct 189 ms 119376 KB Output is correct
86 Correct 178 ms 119384 KB Output is correct
87 Correct 82 ms 119388 KB Output is correct
88 Correct 304 ms 119720 KB Output is correct
89 Correct 250 ms 119616 KB Output is correct
90 Correct 315 ms 119604 KB Output is correct
91 Correct 244 ms 119552 KB Output is correct
92 Correct 212 ms 119388 KB Output is correct
93 Correct 227 ms 119612 KB Output is correct
94 Correct 203 ms 119380 KB Output is correct
95 Correct 89 ms 119616 KB Output is correct
96 Correct 191 ms 119388 KB Output is correct
97 Correct 61 ms 119388 KB Output is correct
98 Correct 152 ms 119376 KB Output is correct
99 Correct 190 ms 119388 KB Output is correct