#include <bits/stdc++.h>
using namespace std;
constexpr int BASE = 1 << 18;
struct cord{
int x, y, z;
};
map<int, int> mapa[3];
int translate[3][BASE];
int TREE[2][BASE<<1];
pair<int, int> square;
vector<cord> sorted[BASE];
cord INPUT[BASE];
int n;
bool cmp(cord a, cord b){
if(a.z != b.z)
return a.z < b.z;
else if(a.x != b.x)
return a.x < b.x;
return a.y < b.y;
}
void scale(){
int pos = 0;
for(auto it = mapa[0].begin(); it != mapa[0].end(); ++it){
it->second = ++pos;
translate[0][pos] = it->first;
}
pos = 0;
for(auto it = mapa[1].begin(); it != mapa[1].end(); ++it){
it->second = ++pos;
translate[1][pos] = it->first;
}
pos = 0;
for(auto it = mapa[2].begin(); it != mapa[2].end(); ++it){
it->second = ++pos;
translate[2][pos] = it->first;
}
for(int i = 1; i <= n; i++){
INPUT[i].x = mapa[0][INPUT[i].x];
INPUT[i].y = mapa[1][INPUT[i].y];
INPUT[i].z = mapa[2][INPUT[i].z];
}
}
void update(int v, int val, int t){
v += BASE;
while(v > 0){
TREE[t][v] = max(TREE[t][v], val);
v/=2;
}
}
int query(int a, int b, int t){
a += BASE - 1;
b += BASE + 1;
int res = 0;
while(a/2 != b/2){
if(a%2 == 0) res = max(res, TREE[t][a+1]);
if(b%2 == 1) res = max(res, TREE[t][b-1]);
a/=2; b/=2;
}
return res;
}
int check(cord a){
if(a.x >= square.first) return -1;
if(a.y >= square.second) return -1;
return translate[0][square.first] + translate[1][square.second] + translate[2][a.z];
}
void updatesquare(cord a){
int maxX = query(0, a.y-1, 0);
int maxY = query(0, a.x-1, 1);
//jestem wtedy maxymalnym Y
if(maxX > a.x)
square = max(square, {maxX, a.y});
//jestem wtedy maxymalnym X
if(maxY > a.y)
square = max(square, {a.x, maxY});
update(a.y, a.x, 0);
update(a.x, a.y, 1);
}
int solve(){
int res = -1;
for(int i = 1; i < BASE; i++){
for(auto sor : sorted[i])
res = max(res, check(sor));
//cerr << "x " << INPUT[i].x << " y " << INPUT[i].y << " z " << INPUT[i].z << "\n";
for(auto sor : sorted[i])
updatesquare(sor);
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> INPUT[i].x >> INPUT[i].y >> INPUT[i].z;
mapa[0][INPUT[i].x];
mapa[1][INPUT[i].y];
mapa[2][INPUT[i].z];
}
scale();
for(int i = 1; i <= n; i++)
sorted[INPUT[i].z].push_back(INPUT[i]);
cout << solve() << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10720 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10584 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
3 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 |
3 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
3 ms |
10588 KB |
Output is correct |
19 |
Correct |
3 ms |
10720 KB |
Output is correct |
20 |
Correct |
2 ms |
10724 KB |
Output is correct |
21 |
Correct |
3 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10836 KB |
Output is correct |
23 |
Correct |
3 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 |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10720 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10584 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
3 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 |
3 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
3 ms |
10588 KB |
Output is correct |
19 |
Correct |
3 ms |
10720 KB |
Output is correct |
20 |
Correct |
2 ms |
10724 KB |
Output is correct |
21 |
Correct |
3 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10836 KB |
Output is correct |
23 |
Correct |
3 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 |
7 ms |
11608 KB |
Output is correct |
27 |
Correct |
6 ms |
11356 KB |
Output is correct |
28 |
Correct |
6 ms |
11356 KB |
Output is correct |
29 |
Correct |
6 ms |
11100 KB |
Output is correct |
30 |
Correct |
5 ms |
11100 KB |
Output is correct |
31 |
Correct |
6 ms |
11100 KB |
Output is correct |
32 |
Correct |
5 ms |
10980 KB |
Output is correct |
33 |
Correct |
5 ms |
11100 KB |
Output is correct |
34 |
Correct |
7 ms |
11584 KB |
Output is correct |
35 |
Correct |
2 ms |
10844 KB |
Output is correct |
36 |
Correct |
3 ms |
10812 KB |
Output is correct |
37 |
Correct |
4 ms |
11100 KB |
Output is correct |
38 |
Correct |
4 ms |
11144 KB |
Output is correct |
39 |
Correct |
3 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10772 KB |
Output is correct |
3 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10584 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
52 ms |
15736 KB |
Output is correct |
12 |
Correct |
37 ms |
15304 KB |
Output is correct |
13 |
Correct |
38 ms |
15340 KB |
Output is correct |
14 |
Correct |
50 ms |
16652 KB |
Output is correct |
15 |
Correct |
46 ms |
15876 KB |
Output is correct |
16 |
Correct |
44 ms |
16836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10772 KB |
Output is correct |
3 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10584 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
52 ms |
15736 KB |
Output is correct |
12 |
Correct |
37 ms |
15304 KB |
Output is correct |
13 |
Correct |
38 ms |
15340 KB |
Output is correct |
14 |
Correct |
50 ms |
16652 KB |
Output is correct |
15 |
Correct |
46 ms |
15876 KB |
Output is correct |
16 |
Correct |
44 ms |
16836 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
4 ms |
10844 KB |
Output is correct |
22 |
Correct |
64 ms |
16220 KB |
Output is correct |
23 |
Correct |
55 ms |
15960 KB |
Output is correct |
24 |
Correct |
48 ms |
15700 KB |
Output is correct |
25 |
Correct |
58 ms |
16536 KB |
Output is correct |
26 |
Correct |
48 ms |
15884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10772 KB |
Output is correct |
3 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10584 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
52 ms |
15736 KB |
Output is correct |
12 |
Correct |
37 ms |
15304 KB |
Output is correct |
13 |
Correct |
38 ms |
15340 KB |
Output is correct |
14 |
Correct |
50 ms |
16652 KB |
Output is correct |
15 |
Correct |
46 ms |
15876 KB |
Output is correct |
16 |
Correct |
44 ms |
16836 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
4 ms |
10844 KB |
Output is correct |
22 |
Correct |
64 ms |
16220 KB |
Output is correct |
23 |
Correct |
55 ms |
15960 KB |
Output is correct |
24 |
Correct |
48 ms |
15700 KB |
Output is correct |
25 |
Correct |
58 ms |
16536 KB |
Output is correct |
26 |
Correct |
48 ms |
15884 KB |
Output is correct |
27 |
Correct |
2 ms |
10588 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
2 ms |
10724 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
4 ms |
10936 KB |
Output is correct |
32 |
Correct |
3 ms |
10844 KB |
Output is correct |
33 |
Correct |
3 ms |
10844 KB |
Output is correct |
34 |
Correct |
92 ms |
16632 KB |
Output is correct |
35 |
Correct |
81 ms |
17236 KB |
Output is correct |
36 |
Correct |
87 ms |
16796 KB |
Output is correct |
37 |
Correct |
79 ms |
17220 KB |
Output is correct |
38 |
Correct |
55 ms |
16456 KB |
Output is correct |
39 |
Correct |
38 ms |
15700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10772 KB |
Output is correct |
3 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10584 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
52 ms |
15736 KB |
Output is correct |
12 |
Correct |
37 ms |
15304 KB |
Output is correct |
13 |
Correct |
38 ms |
15340 KB |
Output is correct |
14 |
Correct |
50 ms |
16652 KB |
Output is correct |
15 |
Correct |
46 ms |
15876 KB |
Output is correct |
16 |
Correct |
44 ms |
16836 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
4 ms |
10844 KB |
Output is correct |
22 |
Correct |
64 ms |
16220 KB |
Output is correct |
23 |
Correct |
55 ms |
15960 KB |
Output is correct |
24 |
Correct |
48 ms |
15700 KB |
Output is correct |
25 |
Correct |
58 ms |
16536 KB |
Output is correct |
26 |
Correct |
48 ms |
15884 KB |
Output is correct |
27 |
Correct |
2 ms |
10588 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
2 ms |
10724 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
4 ms |
10936 KB |
Output is correct |
32 |
Correct |
3 ms |
10844 KB |
Output is correct |
33 |
Correct |
3 ms |
10844 KB |
Output is correct |
34 |
Correct |
92 ms |
16632 KB |
Output is correct |
35 |
Correct |
81 ms |
17236 KB |
Output is correct |
36 |
Correct |
87 ms |
16796 KB |
Output is correct |
37 |
Correct |
79 ms |
17220 KB |
Output is correct |
38 |
Correct |
55 ms |
16456 KB |
Output is correct |
39 |
Correct |
38 ms |
15700 KB |
Output is correct |
40 |
Correct |
5 ms |
11100 KB |
Output is correct |
41 |
Correct |
7 ms |
11100 KB |
Output is correct |
42 |
Correct |
4 ms |
11100 KB |
Output is correct |
43 |
Correct |
5 ms |
11100 KB |
Output is correct |
44 |
Correct |
140 ms |
18604 KB |
Output is correct |
45 |
Correct |
131 ms |
18368 KB |
Output is correct |
46 |
Correct |
138 ms |
18464 KB |
Output is correct |
47 |
Correct |
135 ms |
18516 KB |
Output is correct |
48 |
Correct |
68 ms |
17360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10720 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10584 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
3 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 |
3 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
3 ms |
10588 KB |
Output is correct |
19 |
Correct |
3 ms |
10720 KB |
Output is correct |
20 |
Correct |
2 ms |
10724 KB |
Output is correct |
21 |
Correct |
3 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10836 KB |
Output is correct |
23 |
Correct |
3 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 |
7 ms |
11608 KB |
Output is correct |
27 |
Correct |
6 ms |
11356 KB |
Output is correct |
28 |
Correct |
6 ms |
11356 KB |
Output is correct |
29 |
Correct |
6 ms |
11100 KB |
Output is correct |
30 |
Correct |
5 ms |
11100 KB |
Output is correct |
31 |
Correct |
6 ms |
11100 KB |
Output is correct |
32 |
Correct |
5 ms |
10980 KB |
Output is correct |
33 |
Correct |
5 ms |
11100 KB |
Output is correct |
34 |
Correct |
7 ms |
11584 KB |
Output is correct |
35 |
Correct |
2 ms |
10844 KB |
Output is correct |
36 |
Correct |
3 ms |
10812 KB |
Output is correct |
37 |
Correct |
4 ms |
11100 KB |
Output is correct |
38 |
Correct |
4 ms |
11144 KB |
Output is correct |
39 |
Correct |
3 ms |
10844 KB |
Output is correct |
40 |
Correct |
2 ms |
10588 KB |
Output is correct |
41 |
Correct |
2 ms |
10772 KB |
Output is correct |
42 |
Correct |
3 ms |
10588 KB |
Output is correct |
43 |
Correct |
2 ms |
10588 KB |
Output is correct |
44 |
Correct |
3 ms |
10588 KB |
Output is correct |
45 |
Correct |
2 ms |
10588 KB |
Output is correct |
46 |
Correct |
2 ms |
10588 KB |
Output is correct |
47 |
Correct |
2 ms |
10588 KB |
Output is correct |
48 |
Correct |
3 ms |
10584 KB |
Output is correct |
49 |
Correct |
2 ms |
10588 KB |
Output is correct |
50 |
Correct |
52 ms |
15736 KB |
Output is correct |
51 |
Correct |
37 ms |
15304 KB |
Output is correct |
52 |
Correct |
38 ms |
15340 KB |
Output is correct |
53 |
Correct |
50 ms |
16652 KB |
Output is correct |
54 |
Correct |
46 ms |
15876 KB |
Output is correct |
55 |
Correct |
44 ms |
16836 KB |
Output is correct |
56 |
Correct |
3 ms |
10588 KB |
Output is correct |
57 |
Correct |
2 ms |
10588 KB |
Output is correct |
58 |
Correct |
2 ms |
10588 KB |
Output is correct |
59 |
Correct |
2 ms |
10588 KB |
Output is correct |
60 |
Correct |
4 ms |
10844 KB |
Output is correct |
61 |
Correct |
64 ms |
16220 KB |
Output is correct |
62 |
Correct |
55 ms |
15960 KB |
Output is correct |
63 |
Correct |
48 ms |
15700 KB |
Output is correct |
64 |
Correct |
58 ms |
16536 KB |
Output is correct |
65 |
Correct |
48 ms |
15884 KB |
Output is correct |
66 |
Correct |
2 ms |
10588 KB |
Output is correct |
67 |
Correct |
2 ms |
10588 KB |
Output is correct |
68 |
Correct |
2 ms |
10724 KB |
Output is correct |
69 |
Correct |
2 ms |
10588 KB |
Output is correct |
70 |
Correct |
4 ms |
10936 KB |
Output is correct |
71 |
Correct |
3 ms |
10844 KB |
Output is correct |
72 |
Correct |
3 ms |
10844 KB |
Output is correct |
73 |
Correct |
92 ms |
16632 KB |
Output is correct |
74 |
Correct |
81 ms |
17236 KB |
Output is correct |
75 |
Correct |
87 ms |
16796 KB |
Output is correct |
76 |
Correct |
79 ms |
17220 KB |
Output is correct |
77 |
Correct |
55 ms |
16456 KB |
Output is correct |
78 |
Correct |
38 ms |
15700 KB |
Output is correct |
79 |
Correct |
5 ms |
11100 KB |
Output is correct |
80 |
Correct |
7 ms |
11100 KB |
Output is correct |
81 |
Correct |
4 ms |
11100 KB |
Output is correct |
82 |
Correct |
5 ms |
11100 KB |
Output is correct |
83 |
Correct |
140 ms |
18604 KB |
Output is correct |
84 |
Correct |
131 ms |
18368 KB |
Output is correct |
85 |
Correct |
138 ms |
18464 KB |
Output is correct |
86 |
Correct |
135 ms |
18516 KB |
Output is correct |
87 |
Correct |
68 ms |
17360 KB |
Output is correct |
88 |
Correct |
474 ms |
44856 KB |
Output is correct |
89 |
Correct |
341 ms |
32768 KB |
Output is correct |
90 |
Correct |
326 ms |
34644 KB |
Output is correct |
91 |
Correct |
289 ms |
30356 KB |
Output is correct |
92 |
Correct |
216 ms |
22732 KB |
Output is correct |
93 |
Correct |
320 ms |
32588 KB |
Output is correct |
94 |
Correct |
255 ms |
26892 KB |
Output is correct |
95 |
Correct |
119 ms |
24748 KB |
Output is correct |
96 |
Correct |
392 ms |
44880 KB |
Output is correct |
97 |
Correct |
60 ms |
19936 KB |
Output is correct |
98 |
Correct |
109 ms |
26060 KB |
Output is correct |
99 |
Correct |
109 ms |
25996 KB |
Output is correct |