#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
vector<int> Y;
vector<int> Z;
vector<int> X;
vector<int> ordery;
vector<int> rg;
struct seg{
vector<int> arr;
int n;
void init(int S){
n = S;
arr.resize(2*S);
}
void chmax(int l,int r,int v){
l+=n;r+=n;
while(l<r){
if(l&1){arr[l] = max(arr[l],v);l++;}
if(r&1){r--;arr[r] = max(arr[r],v);}
l>>=1;r>>=1;
}
}
int get(int ind){
ind+=n;
int ans = 0;
while(ind){
ans = max(ans,arr[ind]);
ind>>=1;
}
return ans;
}
} sgt;
/*
6
12 10 2
3 4 16
1 8 11
9 13 17
15 5 14
18 6 7
0,3 <=4
*/
int P = -1;
map<int,int> posP;
int n;
void add(int ind){
int k = ordery[ind];
sgt.chmax(rg[k],n,Z[ind]);
if(posP.size()==0){
if(k>P){
if(sgt.get(k)>Z[ind]) P=k;
else posP[Y[ind]]=ind;
}
return;
}
auto it = posP.upper_bound(Y[ind]);
if(it==posP.end() || Z[it->second]>=Z[ind]){
int g = it->second;
--it;
while(posP.begin()->second!=g){
if(Z[it->second]>=Z[ind]) posP.erase(it--);
else break;
}
if(k>P){
posP[Y[ind]]=ind;
if(sgt.get(k)>Z[ind]){
P = k;
while(posP.size() && ordery[posP.begin()->second]<=P){
posP.erase(posP.begin());
}
}
}
}else{
int g = it->second;
while(posP.size() && posP.begin()->second!=g){posP.erase(posP.begin());}
while(posP.size() && sgt.get(ordery[posP.begin()->second])>Z[posP.begin()->second]){
P=ordery[posP.begin()->second];
posP.erase(posP.begin());
}
}
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n;
// cout<<n<<"\n";
X.resize(n);
Y.resize(n);
Z.resize(n);
vector<int> w(n);
sgt.init(n);
for(int i=0;i<n;i++) cin>>X[i]>>Y[i]>>Z[i];
//for(int i=0;i<n;i++) cout<<X[i]<<" "<<Y[i]<<" "<<Z[i]<<"\n";
vector<int> order(n);
vector<int> oty(n);
ordery.resize(n);
for(int i=0;i<n;i++) order[i]=i;
sort(order.begin(),order.end(),[&](const int a,const int b){return (Y[a]==Y[b])?(Z[a]>Z[b]):(Y[a]<Y[b]);});
for(int i=0;i<n;i++){
oty[i]=order[i];
ordery[order[i]]=i;
}
rg.resize(n,0);
int head = 0;
for(int i=0;i<n;i++){
while(head<n && Y[order[head]]<=Y[order[i]]) head++;
rg[i]=head;
}
sort(order.begin(),order.end(),[&](const int a,const int b){return (X[a]==X[b])?(Y[a]>Y[b]):(X[a]<X[b]);});
int prevx = -1;
queue<int> tobeadd;
int ans = -1;
for(auto i : order){
//cout<<i<<":\n";
if(X[i]!=prevx){
while(tobeadd.size()){
add(tobeadd.front());
tobeadd.pop();
}
}
//cout<<((P==-1)?(-1):(oty[P]))<<"\n";
//for(auto i : posP) cout<<i.second<<" ";
//cout<<"\n";
if(P>=0 && Y[oty[P]]>Y[i] && sgt.get(P)>Z[i]){
ans = max(ans,X[i]+Y[oty[P]]+sgt.get(P));
}
prevx = X[i];
tobeadd.push(i);
}
cout<<ans<<"\n";
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 |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
460 KB |
Output is correct |
25 |
Correct |
1 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 |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
600 KB |
Output is correct |
29 |
Correct |
3 ms |
732 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
412 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 |
908 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
2 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
42 ms |
7000 KB |
Output is correct |
12 |
Correct |
27 ms |
4956 KB |
Output is correct |
13 |
Correct |
29 ms |
5980 KB |
Output is correct |
14 |
Correct |
41 ms |
7532 KB |
Output is correct |
15 |
Correct |
35 ms |
7508 KB |
Output is correct |
16 |
Correct |
26 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
42 ms |
7000 KB |
Output is correct |
12 |
Correct |
27 ms |
4956 KB |
Output is correct |
13 |
Correct |
29 ms |
5980 KB |
Output is correct |
14 |
Correct |
41 ms |
7532 KB |
Output is correct |
15 |
Correct |
35 ms |
7508 KB |
Output is correct |
16 |
Correct |
26 ms |
7508 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
460 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
54 ms |
7068 KB |
Output is correct |
23 |
Correct |
48 ms |
7000 KB |
Output is correct |
24 |
Correct |
41 ms |
5324 KB |
Output is correct |
25 |
Correct |
50 ms |
7156 KB |
Output is correct |
26 |
Correct |
34 ms |
7516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
42 ms |
7000 KB |
Output is correct |
12 |
Correct |
27 ms |
4956 KB |
Output is correct |
13 |
Correct |
29 ms |
5980 KB |
Output is correct |
14 |
Correct |
41 ms |
7532 KB |
Output is correct |
15 |
Correct |
35 ms |
7508 KB |
Output is correct |
16 |
Correct |
26 ms |
7508 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
460 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
54 ms |
7068 KB |
Output is correct |
23 |
Correct |
48 ms |
7000 KB |
Output is correct |
24 |
Correct |
41 ms |
5324 KB |
Output is correct |
25 |
Correct |
50 ms |
7156 KB |
Output is correct |
26 |
Correct |
34 ms |
7516 KB |
Output is correct |
27 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
604 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 |
7280 KB |
Output is correct |
35 |
Correct |
67 ms |
6728 KB |
Output is correct |
36 |
Correct |
72 ms |
7248 KB |
Output is correct |
37 |
Correct |
69 ms |
7248 KB |
Output is correct |
38 |
Correct |
42 ms |
7676 KB |
Output is correct |
39 |
Correct |
19 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
42 ms |
7000 KB |
Output is correct |
12 |
Correct |
27 ms |
4956 KB |
Output is correct |
13 |
Correct |
29 ms |
5980 KB |
Output is correct |
14 |
Correct |
41 ms |
7532 KB |
Output is correct |
15 |
Correct |
35 ms |
7508 KB |
Output is correct |
16 |
Correct |
26 ms |
7508 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
460 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
54 ms |
7068 KB |
Output is correct |
23 |
Correct |
48 ms |
7000 KB |
Output is correct |
24 |
Correct |
41 ms |
5324 KB |
Output is correct |
25 |
Correct |
50 ms |
7156 KB |
Output is correct |
26 |
Correct |
34 ms |
7516 KB |
Output is correct |
27 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
604 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 |
7280 KB |
Output is correct |
35 |
Correct |
67 ms |
6728 KB |
Output is correct |
36 |
Correct |
72 ms |
7248 KB |
Output is correct |
37 |
Correct |
69 ms |
7248 KB |
Output is correct |
38 |
Correct |
42 ms |
7676 KB |
Output is correct |
39 |
Correct |
19 ms |
4948 KB |
Output is correct |
40 |
Correct |
2 ms |
600 KB |
Output is correct |
41 |
Correct |
2 ms |
600 KB |
Output is correct |
42 |
Correct |
2 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
84 ms |
7412 KB |
Output is correct |
45 |
Correct |
84 ms |
7552 KB |
Output is correct |
46 |
Correct |
85 ms |
7508 KB |
Output is correct |
47 |
Correct |
92 ms |
7768 KB |
Output is correct |
48 |
Correct |
43 ms |
8016 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 |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
600 KB |
Output is correct |
29 |
Correct |
3 ms |
732 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
412 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 |
908 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
2 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
42 ms |
7000 KB |
Output is correct |
51 |
Correct |
27 ms |
4956 KB |
Output is correct |
52 |
Correct |
29 ms |
5980 KB |
Output is correct |
53 |
Correct |
41 ms |
7532 KB |
Output is correct |
54 |
Correct |
35 ms |
7508 KB |
Output is correct |
55 |
Correct |
26 ms |
7508 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
460 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
344 KB |
Output is correct |
61 |
Correct |
54 ms |
7068 KB |
Output is correct |
62 |
Correct |
48 ms |
7000 KB |
Output is correct |
63 |
Correct |
41 ms |
5324 KB |
Output is correct |
64 |
Correct |
50 ms |
7156 KB |
Output is correct |
65 |
Correct |
34 ms |
7516 KB |
Output is correct |
66 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
70 |
Correct |
2 ms |
604 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 |
7280 KB |
Output is correct |
74 |
Correct |
67 ms |
6728 KB |
Output is correct |
75 |
Correct |
72 ms |
7248 KB |
Output is correct |
76 |
Correct |
69 ms |
7248 KB |
Output is correct |
77 |
Correct |
42 ms |
7676 KB |
Output is correct |
78 |
Correct |
19 ms |
4948 KB |
Output is correct |
79 |
Correct |
2 ms |
600 KB |
Output is correct |
80 |
Correct |
2 ms |
600 KB |
Output is correct |
81 |
Correct |
2 ms |
604 KB |
Output is correct |
82 |
Correct |
2 ms |
604 KB |
Output is correct |
83 |
Correct |
84 ms |
7412 KB |
Output is correct |
84 |
Correct |
84 ms |
7552 KB |
Output is correct |
85 |
Correct |
85 ms |
7508 KB |
Output is correct |
86 |
Correct |
92 ms |
7768 KB |
Output is correct |
87 |
Correct |
43 ms |
8016 KB |
Output is correct |
88 |
Correct |
84 ms |
8532 KB |
Output is correct |
89 |
Correct |
99 ms |
9092 KB |
Output is correct |
90 |
Correct |
89 ms |
8528 KB |
Output is correct |
91 |
Correct |
107 ms |
9352 KB |
Output is correct |
92 |
Correct |
91 ms |
8020 KB |
Output is correct |
93 |
Correct |
98 ms |
8668 KB |
Output is correct |
94 |
Correct |
97 ms |
8532 KB |
Output is correct |
95 |
Correct |
53 ms |
8784 KB |
Output is correct |
96 |
Correct |
103 ms |
15596 KB |
Output is correct |
97 |
Correct |
39 ms |
9044 KB |
Output is correct |
98 |
Correct |
67 ms |
9300 KB |
Output is correct |
99 |
Correct |
85 ms |
9300 KB |
Output is correct |