#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
struct CONT {
long long int a, b, c;
} a[150005], b[150005];
int za = 0, zb = 0, zc = 0, t[600005];
vector<int> va, vb, vc;
vector<CONT> g[150005];
long long int da[150005], db[150005], dc[150005];
map<int, int> ma, mb, mc;
bool cmp(CONT aa, CONT bb) {
if (aa.a == bb.a) return aa.b < bb.b;
return aa.a < bb.a;
}
bool cmp3(CONT aa, CONT bb) {
if (aa.a == bb.a) return aa.c < bb.c;
return aa.a < bb.a;
}
bool cmp2(CONT aa, CONT bb) {
return aa.b < bb.b;
}
void Clear(int n) {
for (int i = 1; i <= n * 4; i++) t[i] = 0;
}
void update(int v, int tl, int tr, int x, int y) {
if (tl == tr) {
t[v] = max(t[v], y);
return;
}
int mid = (tl + tr) / 2;
if (mid >= x) update(v * 2, tl, mid, x, y);
else update(v * 2 + 1, mid + 1, tr, x, y);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
int sum(int v, int tl, int tr, int l, int r) {
if (l > r) return 0;
if (tl == l && tr == r) {
return t[v];
}
int mid = (tl + tr) / 2;
return max(sum(v * 2, tl, mid, l, min(r, mid)), sum(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r));
}
void Print(CONT aa) {
cout << aa.a << " " << aa.b << " " << aa.c << ' ';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].a >> a[i].b >> a[i].c;
va.push_back(a[i].a);
vb.push_back(a[i].b);
vc.push_back(a[i].c);
}
sort(va.begin(), va.end());
sort(vb.begin(), vb.end());
sort(vc.begin(), vc.end());
for (int w : va) {
if (!ma.count(w)) {
ma[w] = ++za;
da[za] = w;
}
}
for (int w : vb) {
if (!mb.count(w)) {
mb[w] = ++zb;
db[zb] = w;
}
}
for (int w : vc) {
if (!mc.count(w)) {
mc[w] = ++zc;
dc[zc] = w;
}
}
for (int i = 1; i <= n; i++) {
a[i].a = ma[a[i].a], a[i].b = mb[a[i].b], a[i].c = mc[a[i].c];
b[i] = a[i];
}
sort(a + 1, a + n + 1, cmp);
sort(b + 1, b + n + 1, cmp2);
long long int res = -1;
for (int i = 1; i <= n; i++) {
long long int h = sum(1, 1, zb, 1, a[i].b - 1);
if (h > a[i].c) g[a[i].b].push_back({a[i].a, a[i].b, h});
update(1, 1, zb, a[i].b, a[i].c);
}
Clear(zb);
sort(a + 1, a + n + 1, cmp3);
for (int i = 1; i <= n; i++) {
long long int h = sum(1, 1, zc, 1, a[i].c - 1);
if (h > a[i].b) g[h].push_back({a[i].a, h, a[i].c});
update(1, 1, zc, a[i].c, a[i].b);
}
Clear(zc);
for (int i = 1; i <= n; i++) {
if (b[i].b != b[i - 1].b) {
for (auto w : g[b[i].b]) {
long long int h = sum(1, 1, zc, 1, w.c - 1);
if (h > w.a) {
res = max(res, da[h] + db[w.b] + dc[w.c]);
}
}
}
update(1, 1, zc, b[i].c, b[i].a);
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
10588 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10588 KB |
Output is correct |
11 |
Correct |
1 ms |
10588 KB |
Output is correct |
12 |
Correct |
1 ms |
10716 KB |
Output is correct |
13 |
Correct |
1 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10716 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
1 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10720 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
10588 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10588 KB |
Output is correct |
11 |
Correct |
1 ms |
10588 KB |
Output is correct |
12 |
Correct |
1 ms |
10716 KB |
Output is correct |
13 |
Correct |
1 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10716 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
1 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10720 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
9 ms |
11868 KB |
Output is correct |
27 |
Correct |
8 ms |
11356 KB |
Output is correct |
28 |
Correct |
8 ms |
11356 KB |
Output is correct |
29 |
Correct |
8 ms |
11100 KB |
Output is correct |
30 |
Correct |
5 ms |
11192 KB |
Output is correct |
31 |
Correct |
7 ms |
11100 KB |
Output is correct |
32 |
Correct |
5 ms |
11100 KB |
Output is correct |
33 |
Correct |
5 ms |
11220 KB |
Output is correct |
34 |
Correct |
7 ms |
11356 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10588 KB |
Output is correct |
37 |
Correct |
6 ms |
11100 KB |
Output is correct |
38 |
Correct |
6 ms |
11088 KB |
Output is correct |
39 |
Correct |
3 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10584 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10684 KB |
Output is correct |
11 |
Correct |
76 ms |
22940 KB |
Output is correct |
12 |
Correct |
48 ms |
18528 KB |
Output is correct |
13 |
Correct |
48 ms |
17600 KB |
Output is correct |
14 |
Correct |
72 ms |
22964 KB |
Output is correct |
15 |
Correct |
65 ms |
22004 KB |
Output is correct |
16 |
Correct |
53 ms |
18372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10584 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10684 KB |
Output is correct |
11 |
Correct |
76 ms |
22940 KB |
Output is correct |
12 |
Correct |
48 ms |
18528 KB |
Output is correct |
13 |
Correct |
48 ms |
17600 KB |
Output is correct |
14 |
Correct |
72 ms |
22964 KB |
Output is correct |
15 |
Correct |
65 ms |
22004 KB |
Output is correct |
16 |
Correct |
53 ms |
18372 KB |
Output is correct |
17 |
Correct |
1 ms |
10588 KB |
Output is correct |
18 |
Correct |
1 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
3 ms |
10844 KB |
Output is correct |
22 |
Correct |
103 ms |
29872 KB |
Output is correct |
23 |
Correct |
94 ms |
23996 KB |
Output is correct |
24 |
Correct |
67 ms |
20032 KB |
Output is correct |
25 |
Correct |
96 ms |
23100 KB |
Output is correct |
26 |
Correct |
68 ms |
22956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10584 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10684 KB |
Output is correct |
11 |
Correct |
76 ms |
22940 KB |
Output is correct |
12 |
Correct |
48 ms |
18528 KB |
Output is correct |
13 |
Correct |
48 ms |
17600 KB |
Output is correct |
14 |
Correct |
72 ms |
22964 KB |
Output is correct |
15 |
Correct |
65 ms |
22004 KB |
Output is correct |
16 |
Correct |
53 ms |
18372 KB |
Output is correct |
17 |
Correct |
1 ms |
10588 KB |
Output is correct |
18 |
Correct |
1 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
3 ms |
10844 KB |
Output is correct |
22 |
Correct |
103 ms |
29872 KB |
Output is correct |
23 |
Correct |
94 ms |
23996 KB |
Output is correct |
24 |
Correct |
67 ms |
20032 KB |
Output is correct |
25 |
Correct |
96 ms |
23100 KB |
Output is correct |
26 |
Correct |
68 ms |
22956 KB |
Output is correct |
27 |
Correct |
2 ms |
10588 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
1 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
5 ms |
11036 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
153 ms |
30380 KB |
Output is correct |
35 |
Correct |
120 ms |
25200 KB |
Output is correct |
36 |
Correct |
128 ms |
27572 KB |
Output is correct |
37 |
Correct |
123 ms |
23996 KB |
Output is correct |
38 |
Correct |
89 ms |
23732 KB |
Output is correct |
39 |
Correct |
75 ms |
22848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10584 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10684 KB |
Output is correct |
11 |
Correct |
76 ms |
22940 KB |
Output is correct |
12 |
Correct |
48 ms |
18528 KB |
Output is correct |
13 |
Correct |
48 ms |
17600 KB |
Output is correct |
14 |
Correct |
72 ms |
22964 KB |
Output is correct |
15 |
Correct |
65 ms |
22004 KB |
Output is correct |
16 |
Correct |
53 ms |
18372 KB |
Output is correct |
17 |
Correct |
1 ms |
10588 KB |
Output is correct |
18 |
Correct |
1 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
3 ms |
10844 KB |
Output is correct |
22 |
Correct |
103 ms |
29872 KB |
Output is correct |
23 |
Correct |
94 ms |
23996 KB |
Output is correct |
24 |
Correct |
67 ms |
20032 KB |
Output is correct |
25 |
Correct |
96 ms |
23100 KB |
Output is correct |
26 |
Correct |
68 ms |
22956 KB |
Output is correct |
27 |
Correct |
2 ms |
10588 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
1 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
5 ms |
11036 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
153 ms |
30380 KB |
Output is correct |
35 |
Correct |
120 ms |
25200 KB |
Output is correct |
36 |
Correct |
128 ms |
27572 KB |
Output is correct |
37 |
Correct |
123 ms |
23996 KB |
Output is correct |
38 |
Correct |
89 ms |
23732 KB |
Output is correct |
39 |
Correct |
75 ms |
22848 KB |
Output is correct |
40 |
Correct |
5 ms |
11100 KB |
Output is correct |
41 |
Correct |
8 ms |
11356 KB |
Output is correct |
42 |
Correct |
4 ms |
11128 KB |
Output is correct |
43 |
Correct |
6 ms |
11100 KB |
Output is correct |
44 |
Correct |
233 ms |
35172 KB |
Output is correct |
45 |
Correct |
204 ms |
26044 KB |
Output is correct |
46 |
Correct |
210 ms |
26804 KB |
Output is correct |
47 |
Correct |
208 ms |
25780 KB |
Output is correct |
48 |
Correct |
126 ms |
24504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
10588 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10588 KB |
Output is correct |
11 |
Correct |
1 ms |
10588 KB |
Output is correct |
12 |
Correct |
1 ms |
10716 KB |
Output is correct |
13 |
Correct |
1 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10716 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
1 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10720 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
9 ms |
11868 KB |
Output is correct |
27 |
Correct |
8 ms |
11356 KB |
Output is correct |
28 |
Correct |
8 ms |
11356 KB |
Output is correct |
29 |
Correct |
8 ms |
11100 KB |
Output is correct |
30 |
Correct |
5 ms |
11192 KB |
Output is correct |
31 |
Correct |
7 ms |
11100 KB |
Output is correct |
32 |
Correct |
5 ms |
11100 KB |
Output is correct |
33 |
Correct |
5 ms |
11220 KB |
Output is correct |
34 |
Correct |
7 ms |
11356 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10588 KB |
Output is correct |
37 |
Correct |
6 ms |
11100 KB |
Output is correct |
38 |
Correct |
6 ms |
11088 KB |
Output is correct |
39 |
Correct |
3 ms |
10844 KB |
Output is correct |
40 |
Correct |
1 ms |
10588 KB |
Output is correct |
41 |
Correct |
1 ms |
10588 KB |
Output is correct |
42 |
Correct |
1 ms |
10588 KB |
Output is correct |
43 |
Correct |
1 ms |
10588 KB |
Output is correct |
44 |
Correct |
1 ms |
10588 KB |
Output is correct |
45 |
Correct |
2 ms |
10584 KB |
Output is correct |
46 |
Correct |
1 ms |
10584 KB |
Output is correct |
47 |
Correct |
2 ms |
10588 KB |
Output is correct |
48 |
Correct |
2 ms |
10588 KB |
Output is correct |
49 |
Correct |
1 ms |
10684 KB |
Output is correct |
50 |
Correct |
76 ms |
22940 KB |
Output is correct |
51 |
Correct |
48 ms |
18528 KB |
Output is correct |
52 |
Correct |
48 ms |
17600 KB |
Output is correct |
53 |
Correct |
72 ms |
22964 KB |
Output is correct |
54 |
Correct |
65 ms |
22004 KB |
Output is correct |
55 |
Correct |
53 ms |
18372 KB |
Output is correct |
56 |
Correct |
1 ms |
10588 KB |
Output is correct |
57 |
Correct |
1 ms |
10588 KB |
Output is correct |
58 |
Correct |
2 ms |
10588 KB |
Output is correct |
59 |
Correct |
1 ms |
10588 KB |
Output is correct |
60 |
Correct |
3 ms |
10844 KB |
Output is correct |
61 |
Correct |
103 ms |
29872 KB |
Output is correct |
62 |
Correct |
94 ms |
23996 KB |
Output is correct |
63 |
Correct |
67 ms |
20032 KB |
Output is correct |
64 |
Correct |
96 ms |
23100 KB |
Output is correct |
65 |
Correct |
68 ms |
22956 KB |
Output is correct |
66 |
Correct |
2 ms |
10588 KB |
Output is correct |
67 |
Correct |
2 ms |
10588 KB |
Output is correct |
68 |
Correct |
1 ms |
10588 KB |
Output is correct |
69 |
Correct |
2 ms |
10588 KB |
Output is correct |
70 |
Correct |
5 ms |
11036 KB |
Output is correct |
71 |
Correct |
2 ms |
10588 KB |
Output is correct |
72 |
Correct |
2 ms |
10588 KB |
Output is correct |
73 |
Correct |
153 ms |
30380 KB |
Output is correct |
74 |
Correct |
120 ms |
25200 KB |
Output is correct |
75 |
Correct |
128 ms |
27572 KB |
Output is correct |
76 |
Correct |
123 ms |
23996 KB |
Output is correct |
77 |
Correct |
89 ms |
23732 KB |
Output is correct |
78 |
Correct |
75 ms |
22848 KB |
Output is correct |
79 |
Correct |
5 ms |
11100 KB |
Output is correct |
80 |
Correct |
8 ms |
11356 KB |
Output is correct |
81 |
Correct |
4 ms |
11128 KB |
Output is correct |
82 |
Correct |
6 ms |
11100 KB |
Output is correct |
83 |
Correct |
233 ms |
35172 KB |
Output is correct |
84 |
Correct |
204 ms |
26044 KB |
Output is correct |
85 |
Correct |
210 ms |
26804 KB |
Output is correct |
86 |
Correct |
208 ms |
25780 KB |
Output is correct |
87 |
Correct |
126 ms |
24504 KB |
Output is correct |
88 |
Correct |
537 ms |
53988 KB |
Output is correct |
89 |
Correct |
391 ms |
38384 KB |
Output is correct |
90 |
Correct |
458 ms |
45120 KB |
Output is correct |
91 |
Correct |
327 ms |
33980 KB |
Output is correct |
92 |
Correct |
340 ms |
34496 KB |
Output is correct |
93 |
Correct |
409 ms |
37448 KB |
Output is correct |
94 |
Correct |
355 ms |
32188 KB |
Output is correct |
95 |
Correct |
235 ms |
30392 KB |
Output is correct |
96 |
Correct |
410 ms |
43704 KB |
Output is correct |
97 |
Correct |
64 ms |
21556 KB |
Output is correct |
98 |
Correct |
200 ms |
27224 KB |
Output is correct |
99 |
Correct |
231 ms |
27068 KB |
Output is correct |