#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[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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
94296 KB |
Output is correct |
2 |
Correct |
18 ms |
94300 KB |
Output is correct |
3 |
Correct |
17 ms |
94300 KB |
Output is correct |
4 |
Correct |
17 ms |
94300 KB |
Output is correct |
5 |
Correct |
18 ms |
94300 KB |
Output is correct |
6 |
Correct |
18 ms |
94336 KB |
Output is correct |
7 |
Correct |
17 ms |
94300 KB |
Output is correct |
8 |
Correct |
17 ms |
94300 KB |
Output is correct |
9 |
Correct |
17 ms |
94296 KB |
Output is correct |
10 |
Correct |
17 ms |
94300 KB |
Output is correct |
11 |
Correct |
17 ms |
94300 KB |
Output is correct |
12 |
Correct |
18 ms |
94300 KB |
Output is correct |
13 |
Correct |
17 ms |
94300 KB |
Output is correct |
14 |
Correct |
18 ms |
94308 KB |
Output is correct |
15 |
Correct |
19 ms |
94300 KB |
Output is correct |
16 |
Correct |
18 ms |
94332 KB |
Output is correct |
17 |
Correct |
18 ms |
94300 KB |
Output is correct |
18 |
Correct |
18 ms |
94300 KB |
Output is correct |
19 |
Correct |
18 ms |
94348 KB |
Output is correct |
20 |
Correct |
17 ms |
94300 KB |
Output is correct |
21 |
Correct |
19 ms |
94300 KB |
Output is correct |
22 |
Correct |
18 ms |
94300 KB |
Output is correct |
23 |
Correct |
18 ms |
94344 KB |
Output is correct |
24 |
Correct |
18 ms |
94300 KB |
Output is correct |
25 |
Correct |
17 ms |
94300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
94296 KB |
Output is correct |
2 |
Correct |
18 ms |
94300 KB |
Output is correct |
3 |
Correct |
17 ms |
94300 KB |
Output is correct |
4 |
Correct |
17 ms |
94300 KB |
Output is correct |
5 |
Correct |
18 ms |
94300 KB |
Output is correct |
6 |
Correct |
18 ms |
94336 KB |
Output is correct |
7 |
Correct |
17 ms |
94300 KB |
Output is correct |
8 |
Correct |
17 ms |
94300 KB |
Output is correct |
9 |
Correct |
17 ms |
94296 KB |
Output is correct |
10 |
Correct |
17 ms |
94300 KB |
Output is correct |
11 |
Correct |
17 ms |
94300 KB |
Output is correct |
12 |
Correct |
18 ms |
94300 KB |
Output is correct |
13 |
Correct |
17 ms |
94300 KB |
Output is correct |
14 |
Correct |
18 ms |
94308 KB |
Output is correct |
15 |
Correct |
19 ms |
94300 KB |
Output is correct |
16 |
Correct |
18 ms |
94332 KB |
Output is correct |
17 |
Correct |
18 ms |
94300 KB |
Output is correct |
18 |
Correct |
18 ms |
94300 KB |
Output is correct |
19 |
Correct |
18 ms |
94348 KB |
Output is correct |
20 |
Correct |
17 ms |
94300 KB |
Output is correct |
21 |
Correct |
19 ms |
94300 KB |
Output is correct |
22 |
Correct |
18 ms |
94300 KB |
Output is correct |
23 |
Correct |
18 ms |
94344 KB |
Output is correct |
24 |
Correct |
18 ms |
94300 KB |
Output is correct |
25 |
Correct |
17 ms |
94300 KB |
Output is correct |
26 |
Correct |
23 ms |
94292 KB |
Output is correct |
27 |
Correct |
23 ms |
94300 KB |
Output is correct |
28 |
Correct |
23 ms |
94276 KB |
Output is correct |
29 |
Correct |
23 ms |
94300 KB |
Output is correct |
30 |
Correct |
22 ms |
94296 KB |
Output is correct |
31 |
Correct |
22 ms |
94300 KB |
Output is correct |
32 |
Correct |
21 ms |
94500 KB |
Output is correct |
33 |
Correct |
20 ms |
94272 KB |
Output is correct |
34 |
Correct |
22 ms |
94352 KB |
Output is correct |
35 |
Correct |
18 ms |
94204 KB |
Output is correct |
36 |
Correct |
18 ms |
94356 KB |
Output is correct |
37 |
Correct |
21 ms |
94308 KB |
Output is correct |
38 |
Correct |
21 ms |
94552 KB |
Output is correct |
39 |
Correct |
19 ms |
94292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
94556 KB |
Output is correct |
2 |
Correct |
17 ms |
94300 KB |
Output is correct |
3 |
Correct |
17 ms |
94296 KB |
Output is correct |
4 |
Correct |
17 ms |
94300 KB |
Output is correct |
5 |
Correct |
17 ms |
94300 KB |
Output is correct |
6 |
Correct |
18 ms |
94168 KB |
Output is correct |
7 |
Correct |
19 ms |
94324 KB |
Output is correct |
8 |
Correct |
17 ms |
94200 KB |
Output is correct |
9 |
Correct |
17 ms |
94296 KB |
Output is correct |
10 |
Correct |
17 ms |
94300 KB |
Output is correct |
11 |
Correct |
163 ms |
96380 KB |
Output is correct |
12 |
Correct |
102 ms |
95560 KB |
Output is correct |
13 |
Correct |
119 ms |
95808 KB |
Output is correct |
14 |
Correct |
124 ms |
96128 KB |
Output is correct |
15 |
Correct |
72 ms |
96336 KB |
Output is correct |
16 |
Correct |
44 ms |
96092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
94556 KB |
Output is correct |
2 |
Correct |
17 ms |
94300 KB |
Output is correct |
3 |
Correct |
17 ms |
94296 KB |
Output is correct |
4 |
Correct |
17 ms |
94300 KB |
Output is correct |
5 |
Correct |
17 ms |
94300 KB |
Output is correct |
6 |
Correct |
18 ms |
94168 KB |
Output is correct |
7 |
Correct |
19 ms |
94324 KB |
Output is correct |
8 |
Correct |
17 ms |
94200 KB |
Output is correct |
9 |
Correct |
17 ms |
94296 KB |
Output is correct |
10 |
Correct |
17 ms |
94300 KB |
Output is correct |
11 |
Correct |
163 ms |
96380 KB |
Output is correct |
12 |
Correct |
102 ms |
95560 KB |
Output is correct |
13 |
Correct |
119 ms |
95808 KB |
Output is correct |
14 |
Correct |
124 ms |
96128 KB |
Output is correct |
15 |
Correct |
72 ms |
96336 KB |
Output is correct |
16 |
Correct |
44 ms |
96092 KB |
Output is correct |
17 |
Correct |
18 ms |
94300 KB |
Output is correct |
18 |
Correct |
17 ms |
94300 KB |
Output is correct |
19 |
Correct |
17 ms |
94300 KB |
Output is correct |
20 |
Correct |
18 ms |
94300 KB |
Output is correct |
21 |
Correct |
19 ms |
94300 KB |
Output is correct |
22 |
Correct |
190 ms |
96124 KB |
Output is correct |
23 |
Correct |
168 ms |
96092 KB |
Output is correct |
24 |
Correct |
128 ms |
95580 KB |
Output is correct |
25 |
Correct |
153 ms |
96064 KB |
Output is correct |
26 |
Correct |
71 ms |
96088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
94556 KB |
Output is correct |
2 |
Correct |
17 ms |
94300 KB |
Output is correct |
3 |
Correct |
17 ms |
94296 KB |
Output is correct |
4 |
Correct |
17 ms |
94300 KB |
Output is correct |
5 |
Correct |
17 ms |
94300 KB |
Output is correct |
6 |
Correct |
18 ms |
94168 KB |
Output is correct |
7 |
Correct |
19 ms |
94324 KB |
Output is correct |
8 |
Correct |
17 ms |
94200 KB |
Output is correct |
9 |
Correct |
17 ms |
94296 KB |
Output is correct |
10 |
Correct |
17 ms |
94300 KB |
Output is correct |
11 |
Correct |
163 ms |
96380 KB |
Output is correct |
12 |
Correct |
102 ms |
95560 KB |
Output is correct |
13 |
Correct |
119 ms |
95808 KB |
Output is correct |
14 |
Correct |
124 ms |
96128 KB |
Output is correct |
15 |
Correct |
72 ms |
96336 KB |
Output is correct |
16 |
Correct |
44 ms |
96092 KB |
Output is correct |
17 |
Correct |
18 ms |
94300 KB |
Output is correct |
18 |
Correct |
17 ms |
94300 KB |
Output is correct |
19 |
Correct |
17 ms |
94300 KB |
Output is correct |
20 |
Correct |
18 ms |
94300 KB |
Output is correct |
21 |
Correct |
19 ms |
94300 KB |
Output is correct |
22 |
Correct |
190 ms |
96124 KB |
Output is correct |
23 |
Correct |
168 ms |
96092 KB |
Output is correct |
24 |
Correct |
128 ms |
95580 KB |
Output is correct |
25 |
Correct |
153 ms |
96064 KB |
Output is correct |
26 |
Correct |
71 ms |
96088 KB |
Output is correct |
27 |
Correct |
17 ms |
94300 KB |
Output is correct |
28 |
Correct |
18 ms |
94300 KB |
Output is correct |
29 |
Correct |
18 ms |
94296 KB |
Output is correct |
30 |
Correct |
18 ms |
94296 KB |
Output is correct |
31 |
Correct |
21 ms |
94300 KB |
Output is correct |
32 |
Correct |
18 ms |
94224 KB |
Output is correct |
33 |
Correct |
18 ms |
94296 KB |
Output is correct |
34 |
Correct |
186 ms |
96044 KB |
Output is correct |
35 |
Correct |
164 ms |
95836 KB |
Output is correct |
36 |
Correct |
180 ms |
96092 KB |
Output is correct |
37 |
Correct |
163 ms |
96104 KB |
Output is correct |
38 |
Correct |
75 ms |
96336 KB |
Output is correct |
39 |
Correct |
34 ms |
95324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
94556 KB |
Output is correct |
2 |
Correct |
17 ms |
94300 KB |
Output is correct |
3 |
Correct |
17 ms |
94296 KB |
Output is correct |
4 |
Correct |
17 ms |
94300 KB |
Output is correct |
5 |
Correct |
17 ms |
94300 KB |
Output is correct |
6 |
Correct |
18 ms |
94168 KB |
Output is correct |
7 |
Correct |
19 ms |
94324 KB |
Output is correct |
8 |
Correct |
17 ms |
94200 KB |
Output is correct |
9 |
Correct |
17 ms |
94296 KB |
Output is correct |
10 |
Correct |
17 ms |
94300 KB |
Output is correct |
11 |
Correct |
163 ms |
96380 KB |
Output is correct |
12 |
Correct |
102 ms |
95560 KB |
Output is correct |
13 |
Correct |
119 ms |
95808 KB |
Output is correct |
14 |
Correct |
124 ms |
96128 KB |
Output is correct |
15 |
Correct |
72 ms |
96336 KB |
Output is correct |
16 |
Correct |
44 ms |
96092 KB |
Output is correct |
17 |
Correct |
18 ms |
94300 KB |
Output is correct |
18 |
Correct |
17 ms |
94300 KB |
Output is correct |
19 |
Correct |
17 ms |
94300 KB |
Output is correct |
20 |
Correct |
18 ms |
94300 KB |
Output is correct |
21 |
Correct |
19 ms |
94300 KB |
Output is correct |
22 |
Correct |
190 ms |
96124 KB |
Output is correct |
23 |
Correct |
168 ms |
96092 KB |
Output is correct |
24 |
Correct |
128 ms |
95580 KB |
Output is correct |
25 |
Correct |
153 ms |
96064 KB |
Output is correct |
26 |
Correct |
71 ms |
96088 KB |
Output is correct |
27 |
Correct |
17 ms |
94300 KB |
Output is correct |
28 |
Correct |
18 ms |
94300 KB |
Output is correct |
29 |
Correct |
18 ms |
94296 KB |
Output is correct |
30 |
Correct |
18 ms |
94296 KB |
Output is correct |
31 |
Correct |
21 ms |
94300 KB |
Output is correct |
32 |
Correct |
18 ms |
94224 KB |
Output is correct |
33 |
Correct |
18 ms |
94296 KB |
Output is correct |
34 |
Correct |
186 ms |
96044 KB |
Output is correct |
35 |
Correct |
164 ms |
95836 KB |
Output is correct |
36 |
Correct |
180 ms |
96092 KB |
Output is correct |
37 |
Correct |
163 ms |
96104 KB |
Output is correct |
38 |
Correct |
75 ms |
96336 KB |
Output is correct |
39 |
Correct |
34 ms |
95324 KB |
Output is correct |
40 |
Correct |
21 ms |
94300 KB |
Output is correct |
41 |
Correct |
22 ms |
94440 KB |
Output is correct |
42 |
Correct |
21 ms |
94300 KB |
Output is correct |
43 |
Correct |
22 ms |
94300 KB |
Output is correct |
44 |
Correct |
201 ms |
96092 KB |
Output is correct |
45 |
Correct |
176 ms |
96088 KB |
Output is correct |
46 |
Correct |
188 ms |
96128 KB |
Output is correct |
47 |
Correct |
174 ms |
96124 KB |
Output is correct |
48 |
Correct |
80 ms |
96092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
94296 KB |
Output is correct |
2 |
Correct |
18 ms |
94300 KB |
Output is correct |
3 |
Correct |
17 ms |
94300 KB |
Output is correct |
4 |
Correct |
17 ms |
94300 KB |
Output is correct |
5 |
Correct |
18 ms |
94300 KB |
Output is correct |
6 |
Correct |
18 ms |
94336 KB |
Output is correct |
7 |
Correct |
17 ms |
94300 KB |
Output is correct |
8 |
Correct |
17 ms |
94300 KB |
Output is correct |
9 |
Correct |
17 ms |
94296 KB |
Output is correct |
10 |
Correct |
17 ms |
94300 KB |
Output is correct |
11 |
Correct |
17 ms |
94300 KB |
Output is correct |
12 |
Correct |
18 ms |
94300 KB |
Output is correct |
13 |
Correct |
17 ms |
94300 KB |
Output is correct |
14 |
Correct |
18 ms |
94308 KB |
Output is correct |
15 |
Correct |
19 ms |
94300 KB |
Output is correct |
16 |
Correct |
18 ms |
94332 KB |
Output is correct |
17 |
Correct |
18 ms |
94300 KB |
Output is correct |
18 |
Correct |
18 ms |
94300 KB |
Output is correct |
19 |
Correct |
18 ms |
94348 KB |
Output is correct |
20 |
Correct |
17 ms |
94300 KB |
Output is correct |
21 |
Correct |
19 ms |
94300 KB |
Output is correct |
22 |
Correct |
18 ms |
94300 KB |
Output is correct |
23 |
Correct |
18 ms |
94344 KB |
Output is correct |
24 |
Correct |
18 ms |
94300 KB |
Output is correct |
25 |
Correct |
17 ms |
94300 KB |
Output is correct |
26 |
Correct |
23 ms |
94292 KB |
Output is correct |
27 |
Correct |
23 ms |
94300 KB |
Output is correct |
28 |
Correct |
23 ms |
94276 KB |
Output is correct |
29 |
Correct |
23 ms |
94300 KB |
Output is correct |
30 |
Correct |
22 ms |
94296 KB |
Output is correct |
31 |
Correct |
22 ms |
94300 KB |
Output is correct |
32 |
Correct |
21 ms |
94500 KB |
Output is correct |
33 |
Correct |
20 ms |
94272 KB |
Output is correct |
34 |
Correct |
22 ms |
94352 KB |
Output is correct |
35 |
Correct |
18 ms |
94204 KB |
Output is correct |
36 |
Correct |
18 ms |
94356 KB |
Output is correct |
37 |
Correct |
21 ms |
94308 KB |
Output is correct |
38 |
Correct |
21 ms |
94552 KB |
Output is correct |
39 |
Correct |
19 ms |
94292 KB |
Output is correct |
40 |
Correct |
18 ms |
94556 KB |
Output is correct |
41 |
Correct |
17 ms |
94300 KB |
Output is correct |
42 |
Correct |
17 ms |
94296 KB |
Output is correct |
43 |
Correct |
17 ms |
94300 KB |
Output is correct |
44 |
Correct |
17 ms |
94300 KB |
Output is correct |
45 |
Correct |
18 ms |
94168 KB |
Output is correct |
46 |
Correct |
19 ms |
94324 KB |
Output is correct |
47 |
Correct |
17 ms |
94200 KB |
Output is correct |
48 |
Correct |
17 ms |
94296 KB |
Output is correct |
49 |
Correct |
17 ms |
94300 KB |
Output is correct |
50 |
Correct |
163 ms |
96380 KB |
Output is correct |
51 |
Correct |
102 ms |
95560 KB |
Output is correct |
52 |
Correct |
119 ms |
95808 KB |
Output is correct |
53 |
Correct |
124 ms |
96128 KB |
Output is correct |
54 |
Correct |
72 ms |
96336 KB |
Output is correct |
55 |
Correct |
44 ms |
96092 KB |
Output is correct |
56 |
Correct |
18 ms |
94300 KB |
Output is correct |
57 |
Correct |
17 ms |
94300 KB |
Output is correct |
58 |
Correct |
17 ms |
94300 KB |
Output is correct |
59 |
Correct |
18 ms |
94300 KB |
Output is correct |
60 |
Correct |
19 ms |
94300 KB |
Output is correct |
61 |
Correct |
190 ms |
96124 KB |
Output is correct |
62 |
Correct |
168 ms |
96092 KB |
Output is correct |
63 |
Correct |
128 ms |
95580 KB |
Output is correct |
64 |
Correct |
153 ms |
96064 KB |
Output is correct |
65 |
Correct |
71 ms |
96088 KB |
Output is correct |
66 |
Correct |
17 ms |
94300 KB |
Output is correct |
67 |
Correct |
18 ms |
94300 KB |
Output is correct |
68 |
Correct |
18 ms |
94296 KB |
Output is correct |
69 |
Correct |
18 ms |
94296 KB |
Output is correct |
70 |
Correct |
21 ms |
94300 KB |
Output is correct |
71 |
Correct |
18 ms |
94224 KB |
Output is correct |
72 |
Correct |
18 ms |
94296 KB |
Output is correct |
73 |
Correct |
186 ms |
96044 KB |
Output is correct |
74 |
Correct |
164 ms |
95836 KB |
Output is correct |
75 |
Correct |
180 ms |
96092 KB |
Output is correct |
76 |
Correct |
163 ms |
96104 KB |
Output is correct |
77 |
Correct |
75 ms |
96336 KB |
Output is correct |
78 |
Correct |
34 ms |
95324 KB |
Output is correct |
79 |
Correct |
21 ms |
94300 KB |
Output is correct |
80 |
Correct |
22 ms |
94440 KB |
Output is correct |
81 |
Correct |
21 ms |
94300 KB |
Output is correct |
82 |
Correct |
22 ms |
94300 KB |
Output is correct |
83 |
Correct |
201 ms |
96092 KB |
Output is correct |
84 |
Correct |
176 ms |
96088 KB |
Output is correct |
85 |
Correct |
188 ms |
96128 KB |
Output is correct |
86 |
Correct |
174 ms |
96124 KB |
Output is correct |
87 |
Correct |
80 ms |
96092 KB |
Output is correct |
88 |
Correct |
292 ms |
96092 KB |
Output is correct |
89 |
Correct |
240 ms |
96124 KB |
Output is correct |
90 |
Correct |
279 ms |
96340 KB |
Output is correct |
91 |
Correct |
217 ms |
96092 KB |
Output is correct |
92 |
Correct |
208 ms |
96092 KB |
Output is correct |
93 |
Correct |
207 ms |
96088 KB |
Output is correct |
94 |
Correct |
191 ms |
96080 KB |
Output is correct |
95 |
Correct |
86 ms |
96088 KB |
Output is correct |
96 |
Correct |
184 ms |
96080 KB |
Output is correct |
97 |
Correct |
59 ms |
96088 KB |
Output is correct |
98 |
Correct |
148 ms |
96088 KB |
Output is correct |
99 |
Correct |
163 ms |
96128 KB |
Output is correct |