#include<bits/stdc++.h>
using namespace std;
const int N = 15e4;
const int inf = 2e9;
struct xyz{
int x,y,z;
}v[N];
int p[N];
int pos[N];
int n;
int ans = -1;
set <int> instances;
set <int> good;
struct nod{
int mxy,mxz;
}seg[4*N];
nod operator+(nod a,nod b){
return {max(a.mxy,b.mxy),max(a.mxz,b.mxz)};
}
void upd(int pos, int y, int z, int l = 0, int r = n - 1, int node = 1){
if(l == r){
seg[node].mxy = y;
seg[node].mxz = z;
}else{
int mij = (l + r)/2;
if(pos <= mij){
upd(pos, y, z, l, mij, node*2);
}else{
upd(pos, y, z, mij + 1, r, node*2 + 1);
}
seg[node] = seg[node*2] + seg[node*2 + 1];
}
}
nod get2(int ql,int qr,int l = 0,int r = n - 1,int node = 1){
//cout<<seg[node].mxy<<' '<<seg[node].mxz<<' '<<ql<<' '<<qr<<' '<<l<<' '<<r<<' '<<node<<"????\n";
if(ql <= l && r <= qr){
return seg[node];
}else{
int mij = (l + r)/2;
if(qr <= mij){
return get2(ql,qr,l,mij,node*2);
}else if(mij + 1 <= ql){
return get2(ql,qr,mij + 1,r,node*2 + 1);
}else{
return get2(ql,qr,l,mij,node*2) + get2(ql,qr,mij + 1,r,node*2 + 1);
}
}
}
void del(int x){
int id = pos[x];
if(instances.find(id) != instances.end()){
upd(id, -inf, -inf);
instances.erase(id);
}
}
nod get(){
while(!instances.empty()){
auto id = *instances.rbegin();
nod x = get2(0,id);
if(x.mxy > v[p[id]].y || x.mxz > v[p[id]].z)break;
instances.erase(prev(instances.end()));
}
if(instances.empty())return {-inf,-inf};
nod p = get2(0,*instances.rbegin());
return p;
}
int main(){
cin>>n;
for(int i = 0;i < n;i++){
cin>>v[i].x>>v[i].y>>v[i].z;
p[i] = i;
}
sort(v,v + n,[&](xyz a,xyz b){
return a.x < b.x;
});
sort(p,p + n,[&](int a,int b){
if(v[a].y == v[b].y)return v[a].z < v[b].z;
return v[a].y < v[b].y;
});
for(int i = 0;i < n;i++){
//cout<<v[p[i]].y<<' '<<v[p[i]].z<<'\n';
pos[p[i]] = i;
instances.insert(i);
upd(i, v[p[i]].y, v[p[i]].z);
}
int pt = n - 1;
for(int i = n - 1;i >= 0;i--){
while(pt >= 0 && v[pt].x >= v[i].x){
del(pt);
pt--;
}
nod f = get();
if(f.mxy > v[i].y && f.mxz > v[i].z){
ans = max(ans,f.mxy + f.mxz + v[i].x);
}
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
6 ms |
2652 KB |
Output is correct |
27 |
Correct |
6 ms |
2652 KB |
Output is correct |
28 |
Correct |
6 ms |
2652 KB |
Output is correct |
29 |
Correct |
6 ms |
2652 KB |
Output is correct |
30 |
Correct |
3 ms |
2652 KB |
Output is correct |
31 |
Correct |
4 ms |
2652 KB |
Output is correct |
32 |
Correct |
4 ms |
2652 KB |
Output is correct |
33 |
Correct |
5 ms |
2652 KB |
Output is correct |
34 |
Correct |
5 ms |
2796 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
3 ms |
2652 KB |
Output is correct |
38 |
Correct |
4 ms |
2804 KB |
Output is correct |
39 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
165 ms |
15840 KB |
Output is correct |
12 |
Correct |
96 ms |
10528 KB |
Output is correct |
13 |
Correct |
87 ms |
12116 KB |
Output is correct |
14 |
Correct |
144 ms |
15972 KB |
Output is correct |
15 |
Correct |
124 ms |
15956 KB |
Output is correct |
16 |
Correct |
112 ms |
15952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
165 ms |
15840 KB |
Output is correct |
12 |
Correct |
96 ms |
10528 KB |
Output is correct |
13 |
Correct |
87 ms |
12116 KB |
Output is correct |
14 |
Correct |
144 ms |
15972 KB |
Output is correct |
15 |
Correct |
124 ms |
15956 KB |
Output is correct |
16 |
Correct |
112 ms |
15952 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2496 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2512 KB |
Output is correct |
22 |
Correct |
199 ms |
16232 KB |
Output is correct |
23 |
Correct |
163 ms |
15696 KB |
Output is correct |
24 |
Correct |
114 ms |
11600 KB |
Output is correct |
25 |
Correct |
189 ms |
16424 KB |
Output is correct |
26 |
Correct |
129 ms |
16040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
165 ms |
15840 KB |
Output is correct |
12 |
Correct |
96 ms |
10528 KB |
Output is correct |
13 |
Correct |
87 ms |
12116 KB |
Output is correct |
14 |
Correct |
144 ms |
15972 KB |
Output is correct |
15 |
Correct |
124 ms |
15956 KB |
Output is correct |
16 |
Correct |
112 ms |
15952 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2496 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2512 KB |
Output is correct |
22 |
Correct |
199 ms |
16232 KB |
Output is correct |
23 |
Correct |
163 ms |
15696 KB |
Output is correct |
24 |
Correct |
114 ms |
11600 KB |
Output is correct |
25 |
Correct |
189 ms |
16424 KB |
Output is correct |
26 |
Correct |
129 ms |
16040 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
0 ms |
2396 KB |
Output is correct |
31 |
Correct |
4 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
210 ms |
16196 KB |
Output is correct |
35 |
Correct |
172 ms |
15448 KB |
Output is correct |
36 |
Correct |
193 ms |
16564 KB |
Output is correct |
37 |
Correct |
181 ms |
16688 KB |
Output is correct |
38 |
Correct |
152 ms |
16212 KB |
Output is correct |
39 |
Correct |
78 ms |
10524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
165 ms |
15840 KB |
Output is correct |
12 |
Correct |
96 ms |
10528 KB |
Output is correct |
13 |
Correct |
87 ms |
12116 KB |
Output is correct |
14 |
Correct |
144 ms |
15972 KB |
Output is correct |
15 |
Correct |
124 ms |
15956 KB |
Output is correct |
16 |
Correct |
112 ms |
15952 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2496 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2512 KB |
Output is correct |
22 |
Correct |
199 ms |
16232 KB |
Output is correct |
23 |
Correct |
163 ms |
15696 KB |
Output is correct |
24 |
Correct |
114 ms |
11600 KB |
Output is correct |
25 |
Correct |
189 ms |
16424 KB |
Output is correct |
26 |
Correct |
129 ms |
16040 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
0 ms |
2396 KB |
Output is correct |
31 |
Correct |
4 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
210 ms |
16196 KB |
Output is correct |
35 |
Correct |
172 ms |
15448 KB |
Output is correct |
36 |
Correct |
193 ms |
16564 KB |
Output is correct |
37 |
Correct |
181 ms |
16688 KB |
Output is correct |
38 |
Correct |
152 ms |
16212 KB |
Output is correct |
39 |
Correct |
78 ms |
10524 KB |
Output is correct |
40 |
Correct |
3 ms |
2652 KB |
Output is correct |
41 |
Correct |
4 ms |
2652 KB |
Output is correct |
42 |
Correct |
3 ms |
2652 KB |
Output is correct |
43 |
Correct |
3 ms |
2652 KB |
Output is correct |
44 |
Correct |
221 ms |
17056 KB |
Output is correct |
45 |
Correct |
220 ms |
16984 KB |
Output is correct |
46 |
Correct |
199 ms |
17064 KB |
Output is correct |
47 |
Correct |
191 ms |
17236 KB |
Output is correct |
48 |
Correct |
162 ms |
16980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
6 ms |
2652 KB |
Output is correct |
27 |
Correct |
6 ms |
2652 KB |
Output is correct |
28 |
Correct |
6 ms |
2652 KB |
Output is correct |
29 |
Correct |
6 ms |
2652 KB |
Output is correct |
30 |
Correct |
3 ms |
2652 KB |
Output is correct |
31 |
Correct |
4 ms |
2652 KB |
Output is correct |
32 |
Correct |
4 ms |
2652 KB |
Output is correct |
33 |
Correct |
5 ms |
2652 KB |
Output is correct |
34 |
Correct |
5 ms |
2796 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
3 ms |
2652 KB |
Output is correct |
38 |
Correct |
4 ms |
2804 KB |
Output is correct |
39 |
Correct |
2 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
0 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2392 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
0 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
165 ms |
15840 KB |
Output is correct |
51 |
Correct |
96 ms |
10528 KB |
Output is correct |
52 |
Correct |
87 ms |
12116 KB |
Output is correct |
53 |
Correct |
144 ms |
15972 KB |
Output is correct |
54 |
Correct |
124 ms |
15956 KB |
Output is correct |
55 |
Correct |
112 ms |
15952 KB |
Output is correct |
56 |
Correct |
0 ms |
2396 KB |
Output is correct |
57 |
Correct |
0 ms |
2496 KB |
Output is correct |
58 |
Correct |
0 ms |
2396 KB |
Output is correct |
59 |
Correct |
1 ms |
2396 KB |
Output is correct |
60 |
Correct |
2 ms |
2512 KB |
Output is correct |
61 |
Correct |
199 ms |
16232 KB |
Output is correct |
62 |
Correct |
163 ms |
15696 KB |
Output is correct |
63 |
Correct |
114 ms |
11600 KB |
Output is correct |
64 |
Correct |
189 ms |
16424 KB |
Output is correct |
65 |
Correct |
129 ms |
16040 KB |
Output is correct |
66 |
Correct |
1 ms |
2396 KB |
Output is correct |
67 |
Correct |
1 ms |
2396 KB |
Output is correct |
68 |
Correct |
1 ms |
2396 KB |
Output is correct |
69 |
Correct |
0 ms |
2396 KB |
Output is correct |
70 |
Correct |
4 ms |
2652 KB |
Output is correct |
71 |
Correct |
2 ms |
2396 KB |
Output is correct |
72 |
Correct |
1 ms |
2396 KB |
Output is correct |
73 |
Correct |
210 ms |
16196 KB |
Output is correct |
74 |
Correct |
172 ms |
15448 KB |
Output is correct |
75 |
Correct |
193 ms |
16564 KB |
Output is correct |
76 |
Correct |
181 ms |
16688 KB |
Output is correct |
77 |
Correct |
152 ms |
16212 KB |
Output is correct |
78 |
Correct |
78 ms |
10524 KB |
Output is correct |
79 |
Correct |
3 ms |
2652 KB |
Output is correct |
80 |
Correct |
4 ms |
2652 KB |
Output is correct |
81 |
Correct |
3 ms |
2652 KB |
Output is correct |
82 |
Correct |
3 ms |
2652 KB |
Output is correct |
83 |
Correct |
221 ms |
17056 KB |
Output is correct |
84 |
Correct |
220 ms |
16984 KB |
Output is correct |
85 |
Correct |
199 ms |
17064 KB |
Output is correct |
86 |
Correct |
191 ms |
17236 KB |
Output is correct |
87 |
Correct |
162 ms |
16980 KB |
Output is correct |
88 |
Correct |
249 ms |
18772 KB |
Output is correct |
89 |
Correct |
242 ms |
18964 KB |
Output is correct |
90 |
Correct |
261 ms |
18892 KB |
Output is correct |
91 |
Correct |
222 ms |
18924 KB |
Output is correct |
92 |
Correct |
212 ms |
17488 KB |
Output is correct |
93 |
Correct |
208 ms |
17844 KB |
Output is correct |
94 |
Correct |
227 ms |
17492 KB |
Output is correct |
95 |
Correct |
202 ms |
18680 KB |
Output is correct |
96 |
Correct |
170 ms |
18772 KB |
Output is correct |
97 |
Correct |
177 ms |
19028 KB |
Output is correct |
98 |
Correct |
131 ms |
17492 KB |
Output is correct |
99 |
Correct |
151 ms |
17492 KB |
Output is correct |