#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define all(x) begin(x), end(x)
#define sz(x) (int)size(x)
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> pp;
void dbg(){
cerr << endl;
}
template<typename H, typename... T> void dbg(H h, T... t){
cerr << h << ", ";
dbg(t...);
}
void IOS(){
cin.tie(0) -> sync_with_stdio(0);
#ifndef ONLINE_JUDGE
// freopen("inp.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#define er(...) cerr << __LINE__ << " <" << #__VA_ARGS__ << ">: ", dbg(__VA_ARGS__)
#else
#define er(...) 0
#endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353, maxn = 5e5 + 5, lg = 21, inf = ll(1e9) + 5;
struct Fen{
vector<int> fen;
Fen(){}
Fen(int n){
fen.assign(n + 1, -inf);
}
void upd(int i, int k){
for(i++; i < sz(fen); i += i&-i) fen[i] = max(fen[i], k);
}
int get(int i){
int res = -inf;
for(i++; i; i -= i&-i) res = max(res, fen[i]);
return res;
}
} prf, suf;
int n, x[maxn], y[maxn], z[maxn];
int X = -1, Y = -1, id;
map<int, int> mp;
multiset<pp> s;
void add(int x, int y){
// for(auto[x, y]: s){
// er(x, y);
// }
vector<pp> del;
auto it = s.lower_bound(pp(x, -1));
while(it != begin(s)){
it--;
if(it->ss <= y) break;
del.pb(*it);
}
auto it2 = s.upper_bound(pp(x, inf));
while(it2 != end(s)){
if(it2->ss >= y) break;
del.pb(*it2);
it2++;
}
auto add2 = [&](int x, int y){
X = max(X, x), Y = max(Y, y);
prf.upd(mp[x], y);
suf.upd(id-mp[x]-1, -y);
};
if(del.empty()){
if(prf.get(mp[x]-1) > y) add2(x, y);
else {
if(-suf.get(id-1-mp[x]-1) < y) add2(x, y);
else s.insert({x, y});
}
} else{
add2(x, y);
for(auto p: del){
// er(p.ff, p.ss);
auto it = s.find(p);
add2(p.ff, p.ss);
s.erase(it);
}
}
}
int slv1(){
s.clear(), X = Y = -1, mp.clear();
map<int, vector<pp>> mpp;
rep(i,0,n){
mpp[z[i]].pb({x[i], y[i]});
mp[x[i]] = 0;
}
for(auto&c: mp) c.ss = id++;
prf = Fen(id);
suf = Fen(id);
int ans = -1;
for(auto[Z, v]: mpp){
for(auto[x, y]: v){
if(X > x && Y > y){
ans = max(ans, Z + X + Y);
}
}
for(auto[x, y]: v){
add(x, y);
}
}
return ans;
}
int main(){ IOS();
cin >> n;
rep(i,0,n){
cin >> x[i] >> y[i] >> z[i];
}
cout << slv1() << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
264 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
264 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
5 ms |
980 KB |
Output is correct |
27 |
Correct |
5 ms |
724 KB |
Output is correct |
28 |
Correct |
5 ms |
736 KB |
Output is correct |
29 |
Correct |
5 ms |
724 KB |
Output is correct |
30 |
Correct |
3 ms |
596 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
3 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
596 KB |
Output is correct |
34 |
Correct |
4 ms |
1236 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
3 ms |
724 KB |
Output is correct |
38 |
Correct |
3 ms |
724 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
46 ms |
3976 KB |
Output is correct |
12 |
Correct |
37 ms |
4672 KB |
Output is correct |
13 |
Correct |
57 ms |
8980 KB |
Output is correct |
14 |
Correct |
49 ms |
6424 KB |
Output is correct |
15 |
Correct |
52 ms |
7712 KB |
Output is correct |
16 |
Correct |
81 ms |
11416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
46 ms |
3976 KB |
Output is correct |
12 |
Correct |
37 ms |
4672 KB |
Output is correct |
13 |
Correct |
57 ms |
8980 KB |
Output is correct |
14 |
Correct |
49 ms |
6424 KB |
Output is correct |
15 |
Correct |
52 ms |
7712 KB |
Output is correct |
16 |
Correct |
81 ms |
11416 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
47 ms |
3572 KB |
Output is correct |
23 |
Correct |
44 ms |
3788 KB |
Output is correct |
24 |
Correct |
42 ms |
3592 KB |
Output is correct |
25 |
Correct |
69 ms |
6668 KB |
Output is correct |
26 |
Correct |
58 ms |
8708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
46 ms |
3976 KB |
Output is correct |
12 |
Correct |
37 ms |
4672 KB |
Output is correct |
13 |
Correct |
57 ms |
8980 KB |
Output is correct |
14 |
Correct |
49 ms |
6424 KB |
Output is correct |
15 |
Correct |
52 ms |
7712 KB |
Output is correct |
16 |
Correct |
81 ms |
11416 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
47 ms |
3572 KB |
Output is correct |
23 |
Correct |
44 ms |
3788 KB |
Output is correct |
24 |
Correct |
42 ms |
3592 KB |
Output is correct |
25 |
Correct |
69 ms |
6668 KB |
Output is correct |
26 |
Correct |
58 ms |
8708 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
532 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
63 ms |
4960 KB |
Output is correct |
35 |
Correct |
71 ms |
5836 KB |
Output is correct |
36 |
Correct |
78 ms |
5776 KB |
Output is correct |
37 |
Correct |
93 ms |
7124 KB |
Output is correct |
38 |
Correct |
65 ms |
9244 KB |
Output is correct |
39 |
Correct |
40 ms |
7864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
46 ms |
3976 KB |
Output is correct |
12 |
Correct |
37 ms |
4672 KB |
Output is correct |
13 |
Correct |
57 ms |
8980 KB |
Output is correct |
14 |
Correct |
49 ms |
6424 KB |
Output is correct |
15 |
Correct |
52 ms |
7712 KB |
Output is correct |
16 |
Correct |
81 ms |
11416 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
47 ms |
3572 KB |
Output is correct |
23 |
Correct |
44 ms |
3788 KB |
Output is correct |
24 |
Correct |
42 ms |
3592 KB |
Output is correct |
25 |
Correct |
69 ms |
6668 KB |
Output is correct |
26 |
Correct |
58 ms |
8708 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
532 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
63 ms |
4960 KB |
Output is correct |
35 |
Correct |
71 ms |
5836 KB |
Output is correct |
36 |
Correct |
78 ms |
5776 KB |
Output is correct |
37 |
Correct |
93 ms |
7124 KB |
Output is correct |
38 |
Correct |
65 ms |
9244 KB |
Output is correct |
39 |
Correct |
40 ms |
7864 KB |
Output is correct |
40 |
Correct |
3 ms |
596 KB |
Output is correct |
41 |
Correct |
4 ms |
604 KB |
Output is correct |
42 |
Correct |
4 ms |
852 KB |
Output is correct |
43 |
Correct |
4 ms |
852 KB |
Output is correct |
44 |
Correct |
109 ms |
6960 KB |
Output is correct |
45 |
Correct |
159 ms |
8092 KB |
Output is correct |
46 |
Correct |
138 ms |
7500 KB |
Output is correct |
47 |
Correct |
143 ms |
8180 KB |
Output is correct |
48 |
Correct |
85 ms |
10040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
264 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
5 ms |
980 KB |
Output is correct |
27 |
Correct |
5 ms |
724 KB |
Output is correct |
28 |
Correct |
5 ms |
736 KB |
Output is correct |
29 |
Correct |
5 ms |
724 KB |
Output is correct |
30 |
Correct |
3 ms |
596 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
3 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
596 KB |
Output is correct |
34 |
Correct |
4 ms |
1236 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
3 ms |
724 KB |
Output is correct |
38 |
Correct |
3 ms |
724 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
0 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
46 ms |
3976 KB |
Output is correct |
51 |
Correct |
37 ms |
4672 KB |
Output is correct |
52 |
Correct |
57 ms |
8980 KB |
Output is correct |
53 |
Correct |
49 ms |
6424 KB |
Output is correct |
54 |
Correct |
52 ms |
7712 KB |
Output is correct |
55 |
Correct |
81 ms |
11416 KB |
Output is correct |
56 |
Correct |
0 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
47 ms |
3572 KB |
Output is correct |
62 |
Correct |
44 ms |
3788 KB |
Output is correct |
63 |
Correct |
42 ms |
3592 KB |
Output is correct |
64 |
Correct |
69 ms |
6668 KB |
Output is correct |
65 |
Correct |
58 ms |
8708 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
3 ms |
532 KB |
Output is correct |
71 |
Correct |
1 ms |
468 KB |
Output is correct |
72 |
Correct |
1 ms |
468 KB |
Output is correct |
73 |
Correct |
63 ms |
4960 KB |
Output is correct |
74 |
Correct |
71 ms |
5836 KB |
Output is correct |
75 |
Correct |
78 ms |
5776 KB |
Output is correct |
76 |
Correct |
93 ms |
7124 KB |
Output is correct |
77 |
Correct |
65 ms |
9244 KB |
Output is correct |
78 |
Correct |
40 ms |
7864 KB |
Output is correct |
79 |
Correct |
3 ms |
596 KB |
Output is correct |
80 |
Correct |
4 ms |
604 KB |
Output is correct |
81 |
Correct |
4 ms |
852 KB |
Output is correct |
82 |
Correct |
4 ms |
852 KB |
Output is correct |
83 |
Correct |
109 ms |
6960 KB |
Output is correct |
84 |
Correct |
159 ms |
8092 KB |
Output is correct |
85 |
Correct |
138 ms |
7500 KB |
Output is correct |
86 |
Correct |
143 ms |
8180 KB |
Output is correct |
87 |
Correct |
85 ms |
10040 KB |
Output is correct |
88 |
Correct |
406 ms |
30648 KB |
Output is correct |
89 |
Correct |
357 ms |
20660 KB |
Output is correct |
90 |
Correct |
303 ms |
21724 KB |
Output is correct |
91 |
Correct |
299 ms |
18348 KB |
Output is correct |
92 |
Correct |
192 ms |
11084 KB |
Output is correct |
93 |
Correct |
341 ms |
20944 KB |
Output is correct |
94 |
Correct |
282 ms |
15940 KB |
Output is correct |
95 |
Correct |
165 ms |
17192 KB |
Output is correct |
96 |
Correct |
313 ms |
37824 KB |
Output is correct |
97 |
Correct |
97 ms |
15436 KB |
Output is correct |
98 |
Correct |
133 ms |
20668 KB |
Output is correct |
99 |
Correct |
133 ms |
20692 KB |
Output is correct |