Submission #887620

# Submission time Handle Problem Language Result Execution time Memory
887620 2023-12-14T20:38:15 Z MinaRagy06 Team Contest (JOI22_team) C++17
100 / 100
279 ms 96340 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
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[4'000'005];
struct nodemx {
	int l, r, v;
	nodemx() {l = 0, r = 0, v = -1e9;}
} segmx[4'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++;
		}
		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 94296 KB Output is correct
2 Correct 22 ms 94296 KB Output is correct
3 Correct 22 ms 94124 KB Output is correct
4 Correct 22 ms 94288 KB Output is correct
5 Correct 23 ms 94300 KB Output is correct
6 Correct 22 ms 94296 KB Output is correct
7 Correct 22 ms 94300 KB Output is correct
8 Correct 23 ms 94300 KB Output is correct
9 Correct 22 ms 94344 KB Output is correct
10 Correct 22 ms 94300 KB Output is correct
11 Correct 23 ms 94348 KB Output is correct
12 Correct 23 ms 94204 KB Output is correct
13 Correct 22 ms 94300 KB Output is correct
14 Correct 23 ms 94292 KB Output is correct
15 Correct 23 ms 94300 KB Output is correct
16 Correct 23 ms 94332 KB Output is correct
17 Correct 23 ms 94300 KB Output is correct
18 Correct 22 ms 94296 KB Output is correct
19 Correct 23 ms 94300 KB Output is correct
20 Correct 22 ms 94296 KB Output is correct
21 Correct 22 ms 94300 KB Output is correct
22 Correct 22 ms 94292 KB Output is correct
23 Correct 22 ms 94200 KB Output is correct
24 Correct 22 ms 94288 KB Output is correct
25 Correct 22 ms 94292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 94296 KB Output is correct
2 Correct 22 ms 94296 KB Output is correct
3 Correct 22 ms 94124 KB Output is correct
4 Correct 22 ms 94288 KB Output is correct
5 Correct 23 ms 94300 KB Output is correct
6 Correct 22 ms 94296 KB Output is correct
7 Correct 22 ms 94300 KB Output is correct
8 Correct 23 ms 94300 KB Output is correct
9 Correct 22 ms 94344 KB Output is correct
10 Correct 22 ms 94300 KB Output is correct
11 Correct 23 ms 94348 KB Output is correct
12 Correct 23 ms 94204 KB Output is correct
13 Correct 22 ms 94300 KB Output is correct
14 Correct 23 ms 94292 KB Output is correct
15 Correct 23 ms 94300 KB Output is correct
16 Correct 23 ms 94332 KB Output is correct
17 Correct 23 ms 94300 KB Output is correct
18 Correct 22 ms 94296 KB Output is correct
19 Correct 23 ms 94300 KB Output is correct
20 Correct 22 ms 94296 KB Output is correct
21 Correct 22 ms 94300 KB Output is correct
22 Correct 22 ms 94292 KB Output is correct
23 Correct 22 ms 94200 KB Output is correct
24 Correct 22 ms 94288 KB Output is correct
25 Correct 22 ms 94292 KB Output is correct
26 Correct 28 ms 94540 KB Output is correct
27 Correct 28 ms 94408 KB Output is correct
28 Correct 28 ms 94192 KB Output is correct
29 Correct 26 ms 94300 KB Output is correct
30 Correct 25 ms 94332 KB Output is correct
31 Correct 27 ms 94300 KB Output is correct
32 Correct 25 ms 94300 KB Output is correct
33 Correct 24 ms 94288 KB Output is correct
34 Correct 26 ms 94300 KB Output is correct
35 Correct 24 ms 94280 KB Output is correct
36 Correct 23 ms 94212 KB Output is correct
37 Correct 26 ms 94300 KB Output is correct
38 Correct 26 ms 94332 KB Output is correct
39 Correct 24 ms 94300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 94320 KB Output is correct
2 Correct 22 ms 94292 KB Output is correct
3 Correct 22 ms 94300 KB Output is correct
4 Correct 22 ms 94288 KB Output is correct
5 Correct 23 ms 94332 KB Output is correct
6 Correct 22 ms 94300 KB Output is correct
7 Correct 22 ms 94296 KB Output is correct
8 Correct 22 ms 94300 KB Output is correct
9 Correct 22 ms 94300 KB Output is correct
10 Correct 22 ms 94300 KB Output is correct
11 Correct 135 ms 96124 KB Output is correct
12 Correct 97 ms 95320 KB Output is correct
13 Correct 110 ms 95836 KB Output is correct
14 Correct 116 ms 96080 KB Output is correct
15 Correct 71 ms 96088 KB Output is correct
16 Correct 50 ms 96080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 94320 KB Output is correct
2 Correct 22 ms 94292 KB Output is correct
3 Correct 22 ms 94300 KB Output is correct
4 Correct 22 ms 94288 KB Output is correct
5 Correct 23 ms 94332 KB Output is correct
6 Correct 22 ms 94300 KB Output is correct
7 Correct 22 ms 94296 KB Output is correct
8 Correct 22 ms 94300 KB Output is correct
9 Correct 22 ms 94300 KB Output is correct
10 Correct 22 ms 94300 KB Output is correct
11 Correct 135 ms 96124 KB Output is correct
12 Correct 97 ms 95320 KB Output is correct
13 Correct 110 ms 95836 KB Output is correct
14 Correct 116 ms 96080 KB Output is correct
15 Correct 71 ms 96088 KB Output is correct
16 Correct 50 ms 96080 KB Output is correct
17 Correct 22 ms 94308 KB Output is correct
18 Correct 23 ms 94292 KB Output is correct
19 Correct 22 ms 94288 KB Output is correct
20 Correct 25 ms 94316 KB Output is correct
21 Correct 24 ms 94300 KB Output is correct
22 Correct 164 ms 96092 KB Output is correct
23 Correct 154 ms 96088 KB Output is correct
24 Correct 114 ms 95768 KB Output is correct
25 Correct 140 ms 96120 KB Output is correct
26 Correct 71 ms 96088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 94320 KB Output is correct
2 Correct 22 ms 94292 KB Output is correct
3 Correct 22 ms 94300 KB Output is correct
4 Correct 22 ms 94288 KB Output is correct
5 Correct 23 ms 94332 KB Output is correct
6 Correct 22 ms 94300 KB Output is correct
7 Correct 22 ms 94296 KB Output is correct
8 Correct 22 ms 94300 KB Output is correct
9 Correct 22 ms 94300 KB Output is correct
10 Correct 22 ms 94300 KB Output is correct
11 Correct 135 ms 96124 KB Output is correct
12 Correct 97 ms 95320 KB Output is correct
13 Correct 110 ms 95836 KB Output is correct
14 Correct 116 ms 96080 KB Output is correct
15 Correct 71 ms 96088 KB Output is correct
16 Correct 50 ms 96080 KB Output is correct
17 Correct 22 ms 94308 KB Output is correct
18 Correct 23 ms 94292 KB Output is correct
19 Correct 22 ms 94288 KB Output is correct
20 Correct 25 ms 94316 KB Output is correct
21 Correct 24 ms 94300 KB Output is correct
22 Correct 164 ms 96092 KB Output is correct
23 Correct 154 ms 96088 KB Output is correct
24 Correct 114 ms 95768 KB Output is correct
25 Correct 140 ms 96120 KB Output is correct
26 Correct 71 ms 96088 KB Output is correct
27 Correct 22 ms 94296 KB Output is correct
28 Correct 22 ms 94300 KB Output is correct
29 Correct 22 ms 94300 KB Output is correct
30 Correct 22 ms 94300 KB Output is correct
31 Correct 26 ms 94292 KB Output is correct
32 Correct 22 ms 94300 KB Output is correct
33 Correct 23 ms 94300 KB Output is correct
34 Correct 175 ms 96048 KB Output is correct
35 Correct 154 ms 95836 KB Output is correct
36 Correct 169 ms 96092 KB Output is correct
37 Correct 154 ms 96080 KB Output is correct
38 Correct 75 ms 96196 KB Output is correct
39 Correct 39 ms 95316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 94320 KB Output is correct
2 Correct 22 ms 94292 KB Output is correct
3 Correct 22 ms 94300 KB Output is correct
4 Correct 22 ms 94288 KB Output is correct
5 Correct 23 ms 94332 KB Output is correct
6 Correct 22 ms 94300 KB Output is correct
7 Correct 22 ms 94296 KB Output is correct
8 Correct 22 ms 94300 KB Output is correct
9 Correct 22 ms 94300 KB Output is correct
10 Correct 22 ms 94300 KB Output is correct
11 Correct 135 ms 96124 KB Output is correct
12 Correct 97 ms 95320 KB Output is correct
13 Correct 110 ms 95836 KB Output is correct
14 Correct 116 ms 96080 KB Output is correct
15 Correct 71 ms 96088 KB Output is correct
16 Correct 50 ms 96080 KB Output is correct
17 Correct 22 ms 94308 KB Output is correct
18 Correct 23 ms 94292 KB Output is correct
19 Correct 22 ms 94288 KB Output is correct
20 Correct 25 ms 94316 KB Output is correct
21 Correct 24 ms 94300 KB Output is correct
22 Correct 164 ms 96092 KB Output is correct
23 Correct 154 ms 96088 KB Output is correct
24 Correct 114 ms 95768 KB Output is correct
25 Correct 140 ms 96120 KB Output is correct
26 Correct 71 ms 96088 KB Output is correct
27 Correct 22 ms 94296 KB Output is correct
28 Correct 22 ms 94300 KB Output is correct
29 Correct 22 ms 94300 KB Output is correct
30 Correct 22 ms 94300 KB Output is correct
31 Correct 26 ms 94292 KB Output is correct
32 Correct 22 ms 94300 KB Output is correct
33 Correct 23 ms 94300 KB Output is correct
34 Correct 175 ms 96048 KB Output is correct
35 Correct 154 ms 95836 KB Output is correct
36 Correct 169 ms 96092 KB Output is correct
37 Correct 154 ms 96080 KB Output is correct
38 Correct 75 ms 96196 KB Output is correct
39 Correct 39 ms 95316 KB Output is correct
40 Correct 25 ms 94296 KB Output is correct
41 Correct 26 ms 94300 KB Output is correct
42 Correct 26 ms 94292 KB Output is correct
43 Correct 26 ms 94300 KB Output is correct
44 Correct 187 ms 96128 KB Output is correct
45 Correct 168 ms 96096 KB Output is correct
46 Correct 172 ms 96092 KB Output is correct
47 Correct 163 ms 96088 KB Output is correct
48 Correct 80 ms 96128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 94296 KB Output is correct
2 Correct 22 ms 94296 KB Output is correct
3 Correct 22 ms 94124 KB Output is correct
4 Correct 22 ms 94288 KB Output is correct
5 Correct 23 ms 94300 KB Output is correct
6 Correct 22 ms 94296 KB Output is correct
7 Correct 22 ms 94300 KB Output is correct
8 Correct 23 ms 94300 KB Output is correct
9 Correct 22 ms 94344 KB Output is correct
10 Correct 22 ms 94300 KB Output is correct
11 Correct 23 ms 94348 KB Output is correct
12 Correct 23 ms 94204 KB Output is correct
13 Correct 22 ms 94300 KB Output is correct
14 Correct 23 ms 94292 KB Output is correct
15 Correct 23 ms 94300 KB Output is correct
16 Correct 23 ms 94332 KB Output is correct
17 Correct 23 ms 94300 KB Output is correct
18 Correct 22 ms 94296 KB Output is correct
19 Correct 23 ms 94300 KB Output is correct
20 Correct 22 ms 94296 KB Output is correct
21 Correct 22 ms 94300 KB Output is correct
22 Correct 22 ms 94292 KB Output is correct
23 Correct 22 ms 94200 KB Output is correct
24 Correct 22 ms 94288 KB Output is correct
25 Correct 22 ms 94292 KB Output is correct
26 Correct 28 ms 94540 KB Output is correct
27 Correct 28 ms 94408 KB Output is correct
28 Correct 28 ms 94192 KB Output is correct
29 Correct 26 ms 94300 KB Output is correct
30 Correct 25 ms 94332 KB Output is correct
31 Correct 27 ms 94300 KB Output is correct
32 Correct 25 ms 94300 KB Output is correct
33 Correct 24 ms 94288 KB Output is correct
34 Correct 26 ms 94300 KB Output is correct
35 Correct 24 ms 94280 KB Output is correct
36 Correct 23 ms 94212 KB Output is correct
37 Correct 26 ms 94300 KB Output is correct
38 Correct 26 ms 94332 KB Output is correct
39 Correct 24 ms 94300 KB Output is correct
40 Correct 24 ms 94320 KB Output is correct
41 Correct 22 ms 94292 KB Output is correct
42 Correct 22 ms 94300 KB Output is correct
43 Correct 22 ms 94288 KB Output is correct
44 Correct 23 ms 94332 KB Output is correct
45 Correct 22 ms 94300 KB Output is correct
46 Correct 22 ms 94296 KB Output is correct
47 Correct 22 ms 94300 KB Output is correct
48 Correct 22 ms 94300 KB Output is correct
49 Correct 22 ms 94300 KB Output is correct
50 Correct 135 ms 96124 KB Output is correct
51 Correct 97 ms 95320 KB Output is correct
52 Correct 110 ms 95836 KB Output is correct
53 Correct 116 ms 96080 KB Output is correct
54 Correct 71 ms 96088 KB Output is correct
55 Correct 50 ms 96080 KB Output is correct
56 Correct 22 ms 94308 KB Output is correct
57 Correct 23 ms 94292 KB Output is correct
58 Correct 22 ms 94288 KB Output is correct
59 Correct 25 ms 94316 KB Output is correct
60 Correct 24 ms 94300 KB Output is correct
61 Correct 164 ms 96092 KB Output is correct
62 Correct 154 ms 96088 KB Output is correct
63 Correct 114 ms 95768 KB Output is correct
64 Correct 140 ms 96120 KB Output is correct
65 Correct 71 ms 96088 KB Output is correct
66 Correct 22 ms 94296 KB Output is correct
67 Correct 22 ms 94300 KB Output is correct
68 Correct 22 ms 94300 KB Output is correct
69 Correct 22 ms 94300 KB Output is correct
70 Correct 26 ms 94292 KB Output is correct
71 Correct 22 ms 94300 KB Output is correct
72 Correct 23 ms 94300 KB Output is correct
73 Correct 175 ms 96048 KB Output is correct
74 Correct 154 ms 95836 KB Output is correct
75 Correct 169 ms 96092 KB Output is correct
76 Correct 154 ms 96080 KB Output is correct
77 Correct 75 ms 96196 KB Output is correct
78 Correct 39 ms 95316 KB Output is correct
79 Correct 25 ms 94296 KB Output is correct
80 Correct 26 ms 94300 KB Output is correct
81 Correct 26 ms 94292 KB Output is correct
82 Correct 26 ms 94300 KB Output is correct
83 Correct 187 ms 96128 KB Output is correct
84 Correct 168 ms 96096 KB Output is correct
85 Correct 172 ms 96092 KB Output is correct
86 Correct 163 ms 96088 KB Output is correct
87 Correct 80 ms 96128 KB Output is correct
88 Correct 279 ms 96088 KB Output is correct
89 Correct 247 ms 96092 KB Output is correct
90 Correct 260 ms 96124 KB Output is correct
91 Correct 211 ms 96092 KB Output is correct
92 Correct 198 ms 96132 KB Output is correct
93 Correct 197 ms 96124 KB Output is correct
94 Correct 180 ms 96080 KB Output is correct
95 Correct 88 ms 96340 KB Output is correct
96 Correct 180 ms 96128 KB Output is correct
97 Correct 66 ms 96124 KB Output is correct
98 Correct 138 ms 96128 KB Output is correct
99 Correct 151 ms 96128 KB Output is correct