#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 150005;
struct Fenwick {
int s[N];
void upd(int i, int x) {
for (; i < N; i += i & -i) {
s[i] = max(s[i], x);
}
}
int qry(int i) {
int res = 0;
for (; i; i -= i & -i) {
res = max(res, s[i]);
}
return res;
}
} ft[2];
int n;
int x[N], y[N], z[N];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
array<vector<int>, 2> comp;
for (int i = 1; i <= n; ++i) {
cin >> x[i] >> y[i] >> z[i];
comp[0].push_back(y[i]);
comp[1].push_back(z[i]);
}
for (auto it : {0, 1}) {
sort(comp[it].begin(), comp[it].end());
comp[it].erase(unique(comp[it].begin(), comp[it].end()), comp[it].end());
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 1);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return x[i] < x[j];
});
auto ID = [&](const vector<int> &comp, int x) {
return lower_bound(comp.begin(), comp.end(), x) - comp.begin() + 1;
};
array<int, 2> cands{};
auto add = [&](int id) {
int Y = ID(comp[0], y[id]), Z = ID(comp[1], z[id]);
int rZ = ft[1].qry(Y - 1), lY = ft[0].qry(Z - 1);
if (rZ > z[id]) {
cands = max(cands, {y[id], rZ});
}
if (lY > y[id]) {
cands = max(cands, {lY, z[id]});
}
ft[0].upd(Z, y[id]);
ft[1].upd(Y, z[id]);
};
int res = -1;
for (int i = 0; i < n; ) {
int j = i;
while (j < n && x[ord[i]] == x[ord[j]]) {
if (cands[0] > y[ord[j]] && cands[1] > z[ord[j]]) {
res = max(res, x[ord[j]] + cands[0] + cands[1]);
}
++j;
}
while (i < j) {
add(ord[i++]);
}
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
472 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
472 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
608 KB |
Output is correct |
28 |
Correct |
3 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
3 ms |
568 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
672 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
472 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
36 ms |
4856 KB |
Output is correct |
12 |
Correct |
24 ms |
3536 KB |
Output is correct |
13 |
Correct |
26 ms |
4352 KB |
Output is correct |
14 |
Correct |
45 ms |
5064 KB |
Output is correct |
15 |
Correct |
32 ms |
5064 KB |
Output is correct |
16 |
Correct |
29 ms |
5064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
472 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
36 ms |
4856 KB |
Output is correct |
12 |
Correct |
24 ms |
3536 KB |
Output is correct |
13 |
Correct |
26 ms |
4352 KB |
Output is correct |
14 |
Correct |
45 ms |
5064 KB |
Output is correct |
15 |
Correct |
32 ms |
5064 KB |
Output is correct |
16 |
Correct |
29 ms |
5064 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
45 ms |
5184 KB |
Output is correct |
23 |
Correct |
39 ms |
5012 KB |
Output is correct |
24 |
Correct |
31 ms |
4024 KB |
Output is correct |
25 |
Correct |
45 ms |
5360 KB |
Output is correct |
26 |
Correct |
33 ms |
5060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
472 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
36 ms |
4856 KB |
Output is correct |
12 |
Correct |
24 ms |
3536 KB |
Output is correct |
13 |
Correct |
26 ms |
4352 KB |
Output is correct |
14 |
Correct |
45 ms |
5064 KB |
Output is correct |
15 |
Correct |
32 ms |
5064 KB |
Output is correct |
16 |
Correct |
29 ms |
5064 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
45 ms |
5184 KB |
Output is correct |
23 |
Correct |
39 ms |
5012 KB |
Output is correct |
24 |
Correct |
31 ms |
4024 KB |
Output is correct |
25 |
Correct |
45 ms |
5360 KB |
Output is correct |
26 |
Correct |
33 ms |
5060 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
572 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
70 ms |
5572 KB |
Output is correct |
35 |
Correct |
56 ms |
5692 KB |
Output is correct |
36 |
Correct |
64 ms |
5564 KB |
Output is correct |
37 |
Correct |
53 ms |
5808 KB |
Output is correct |
38 |
Correct |
38 ms |
5572 KB |
Output is correct |
39 |
Correct |
31 ms |
3792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
472 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
36 ms |
4856 KB |
Output is correct |
12 |
Correct |
24 ms |
3536 KB |
Output is correct |
13 |
Correct |
26 ms |
4352 KB |
Output is correct |
14 |
Correct |
45 ms |
5064 KB |
Output is correct |
15 |
Correct |
32 ms |
5064 KB |
Output is correct |
16 |
Correct |
29 ms |
5064 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
45 ms |
5184 KB |
Output is correct |
23 |
Correct |
39 ms |
5012 KB |
Output is correct |
24 |
Correct |
31 ms |
4024 KB |
Output is correct |
25 |
Correct |
45 ms |
5360 KB |
Output is correct |
26 |
Correct |
33 ms |
5060 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
572 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
70 ms |
5572 KB |
Output is correct |
35 |
Correct |
56 ms |
5692 KB |
Output is correct |
36 |
Correct |
64 ms |
5564 KB |
Output is correct |
37 |
Correct |
53 ms |
5808 KB |
Output is correct |
38 |
Correct |
38 ms |
5572 KB |
Output is correct |
39 |
Correct |
31 ms |
3792 KB |
Output is correct |
40 |
Correct |
2 ms |
600 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
72 ms |
6360 KB |
Output is correct |
45 |
Correct |
66 ms |
6332 KB |
Output is correct |
46 |
Correct |
80 ms |
6588 KB |
Output is correct |
47 |
Correct |
66 ms |
6336 KB |
Output is correct |
48 |
Correct |
48 ms |
6300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
472 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
608 KB |
Output is correct |
28 |
Correct |
3 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
3 ms |
568 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
672 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
472 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
36 ms |
4856 KB |
Output is correct |
51 |
Correct |
24 ms |
3536 KB |
Output is correct |
52 |
Correct |
26 ms |
4352 KB |
Output is correct |
53 |
Correct |
45 ms |
5064 KB |
Output is correct |
54 |
Correct |
32 ms |
5064 KB |
Output is correct |
55 |
Correct |
29 ms |
5064 KB |
Output is correct |
56 |
Correct |
0 ms |
344 KB |
Output is correct |
57 |
Correct |
1 ms |
344 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
604 KB |
Output is correct |
61 |
Correct |
45 ms |
5184 KB |
Output is correct |
62 |
Correct |
39 ms |
5012 KB |
Output is correct |
63 |
Correct |
31 ms |
4024 KB |
Output is correct |
64 |
Correct |
45 ms |
5360 KB |
Output is correct |
65 |
Correct |
33 ms |
5060 KB |
Output is correct |
66 |
Correct |
1 ms |
348 KB |
Output is correct |
67 |
Correct |
0 ms |
348 KB |
Output is correct |
68 |
Correct |
0 ms |
348 KB |
Output is correct |
69 |
Correct |
1 ms |
348 KB |
Output is correct |
70 |
Correct |
2 ms |
572 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
70 ms |
5572 KB |
Output is correct |
74 |
Correct |
56 ms |
5692 KB |
Output is correct |
75 |
Correct |
64 ms |
5564 KB |
Output is correct |
76 |
Correct |
53 ms |
5808 KB |
Output is correct |
77 |
Correct |
38 ms |
5572 KB |
Output is correct |
78 |
Correct |
31 ms |
3792 KB |
Output is correct |
79 |
Correct |
2 ms |
600 KB |
Output is correct |
80 |
Correct |
2 ms |
604 KB |
Output is correct |
81 |
Correct |
1 ms |
604 KB |
Output is correct |
82 |
Correct |
2 ms |
604 KB |
Output is correct |
83 |
Correct |
72 ms |
6360 KB |
Output is correct |
84 |
Correct |
66 ms |
6332 KB |
Output is correct |
85 |
Correct |
80 ms |
6588 KB |
Output is correct |
86 |
Correct |
66 ms |
6336 KB |
Output is correct |
87 |
Correct |
48 ms |
6300 KB |
Output is correct |
88 |
Correct |
107 ms |
9148 KB |
Output is correct |
89 |
Correct |
95 ms |
8808 KB |
Output is correct |
90 |
Correct |
99 ms |
8636 KB |
Output is correct |
91 |
Correct |
93 ms |
8664 KB |
Output is correct |
92 |
Correct |
82 ms |
6892 KB |
Output is correct |
93 |
Correct |
97 ms |
7608 KB |
Output is correct |
94 |
Correct |
89 ms |
7180 KB |
Output is correct |
95 |
Correct |
57 ms |
8128 KB |
Output is correct |
96 |
Correct |
76 ms |
9152 KB |
Output is correct |
97 |
Correct |
42 ms |
8132 KB |
Output is correct |
98 |
Correct |
47 ms |
7096 KB |
Output is correct |
99 |
Correct |
70 ms |
7096 KB |
Output is correct |