#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize "Ofast"
#pragma GCC target "avx2,avx2"
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef complex<double> cmplx;
template <typename T> using minPq = priority_queue<T, vector<T>, greater<T>>;
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define ms(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define fs first
#define sn second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int) (v).size())
#define lbv(v, x) (lower_bound((v).begin(), (v).end(), x) - (v).begin())
#define ubv(v, x) (upper_bound((v).begin(), (v).end(), x) - (v).begin())
template <typename T> inline void UNIQUE(vector<T> &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) {cout << #x << ' ' << x << endl;}
#define dbgArr(arr, n) {cout << #arr; FR(_i, n) cout << ' ' << arr[_i]; cout << endl;}
template<typename T, int MSZ>
struct SegTree {
T data[MSZ*2];
int sz = MSZ;
static constexpr T unit = 0;
inline T merge(T t1, T t2){
return max(t1, t2);
}
void build(){
for (int i = sz-1; i > 0; --i){
data[i] = merge(data[i*2], data[i*2+1]);
}
}
void update(int p, T v){
p += sz;
data[p] = max(data[p], v);
for (; p >>= 1;){
data[p] = merge(data[p*2], data[p*2+1]);
}
}
// Query range [l, r)
T query(int l, int r){
T resL = unit, resR = unit;
for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
if(l&1) resL = merge(resL, data[l++]);
if(r&1) resR = merge(data[--r], resR);
}
return merge(resL, resR);
}
// Access the last layer of the segment tree
inline T& operator[](int i){
return data[i + sz];
}
};
typedef array<int, 3> trip;
const int MN = 150005;
int n;
vector<trip> vec;
vi ys, zs;
SegTree<int, MN> mxZPref, mxYPref;
int mxZ[MN];
int main(){
boost();
cin >> n;
FR(i, n){
int a, b, c;
cin >> a >> b >> c;
vec.pb({a, b, c});
ys.pb(b);
zs.pb(c);
}
UNIQUE(vec);
UNIQUE(ys);
UNIQUE(zs);
n = SZ(ys);
int ans = -1;
int lst = 0, prvX = vec[0][0];
FR(i, SZ(vec)){
if(vec[i][0] != prvX){
FOR(j, lst, i){
auto [x, y, z] = vec[j];
int yPos = lbv(ys, y);
int zPos = lbv(zs, z);
int mz = mxZPref.query(0, yPos);
if(mz > z) mxZ[yPos] = max(mxZ[yPos], mz);
mxYPref.update(zPos, y);
int mxY = mxYPref.query(0, zPos);
if(mxY > y){
int yp1 = lbv(ys, mxY);
mxZ[yp1] = max(mxZ[yp1], z);
}
mxZPref.update(yPos, z);
}
prvX = vec[i][0];
lst = i;
}
auto [x, y, z] = vec[i];
int yPos = lbv(ys, y);
int mxSum = 0;
FOR(j, yPos+1, n) mxSum = max(mxSum, (ys[j] + mxZ[j]) * (mxZ[j] > z));
if(mxSum) ans = max(ans, mxSum + x);
}
if(ans == -1) vi vec(1e7, 1234);
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
18 ms |
39432 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
18 ms |
39456 KB |
Output is correct |
6 |
Correct |
22 ms |
39496 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
20 ms |
39508 KB |
Output is correct |
9 |
Correct |
17 ms |
39508 KB |
Output is correct |
10 |
Correct |
17 ms |
39480 KB |
Output is correct |
11 |
Correct |
18 ms |
39380 KB |
Output is correct |
12 |
Correct |
17 ms |
39456 KB |
Output is correct |
13 |
Correct |
19 ms |
39492 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 |
21 ms |
39484 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
18 ms |
39508 KB |
Output is correct |
21 |
Correct |
17 ms |
39456 KB |
Output is correct |
22 |
Correct |
17 ms |
39544 KB |
Output is correct |
23 |
Correct |
17 ms |
39508 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
18 ms |
39432 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
18 ms |
39456 KB |
Output is correct |
6 |
Correct |
22 ms |
39496 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
20 ms |
39508 KB |
Output is correct |
9 |
Correct |
17 ms |
39508 KB |
Output is correct |
10 |
Correct |
17 ms |
39480 KB |
Output is correct |
11 |
Correct |
18 ms |
39380 KB |
Output is correct |
12 |
Correct |
17 ms |
39456 KB |
Output is correct |
13 |
Correct |
19 ms |
39492 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 |
21 ms |
39484 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
18 ms |
39508 KB |
Output is correct |
21 |
Correct |
17 ms |
39456 KB |
Output is correct |
22 |
Correct |
17 ms |
39544 KB |
Output is correct |
23 |
Correct |
17 ms |
39508 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
596 KB |
Output is correct |
27 |
Correct |
6 ms |
596 KB |
Output is correct |
28 |
Correct |
7 ms |
580 KB |
Output is correct |
29 |
Correct |
21 ms |
39704 KB |
Output is correct |
30 |
Correct |
3 ms |
476 KB |
Output is correct |
31 |
Correct |
5 ms |
468 KB |
Output is correct |
32 |
Correct |
20 ms |
39596 KB |
Output is correct |
33 |
Correct |
19 ms |
39736 KB |
Output is correct |
34 |
Correct |
22 ms |
39792 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 |
596 KB |
Output is correct |
38 |
Correct |
4 ms |
596 KB |
Output is correct |
39 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
17 ms |
39380 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
17 ms |
39488 KB |
Output is correct |
6 |
Correct |
20 ms |
39500 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
18 ms |
39416 KB |
Output is correct |
9 |
Correct |
17 ms |
39508 KB |
Output is correct |
10 |
Correct |
17 ms |
39508 KB |
Output is correct |
11 |
Correct |
51 ms |
4976 KB |
Output is correct |
12 |
Correct |
33 ms |
3008 KB |
Output is correct |
13 |
Correct |
35 ms |
3816 KB |
Output is correct |
14 |
Correct |
71 ms |
44588 KB |
Output is correct |
15 |
Correct |
63 ms |
44264 KB |
Output is correct |
16 |
Correct |
57 ms |
44348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
17 ms |
39380 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
17 ms |
39488 KB |
Output is correct |
6 |
Correct |
20 ms |
39500 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
18 ms |
39416 KB |
Output is correct |
9 |
Correct |
17 ms |
39508 KB |
Output is correct |
10 |
Correct |
17 ms |
39508 KB |
Output is correct |
11 |
Correct |
51 ms |
4976 KB |
Output is correct |
12 |
Correct |
33 ms |
3008 KB |
Output is correct |
13 |
Correct |
35 ms |
3816 KB |
Output is correct |
14 |
Correct |
71 ms |
44588 KB |
Output is correct |
15 |
Correct |
63 ms |
44264 KB |
Output is correct |
16 |
Correct |
57 ms |
44348 KB |
Output is correct |
17 |
Correct |
16 ms |
39356 KB |
Output is correct |
18 |
Correct |
17 ms |
39380 KB |
Output is correct |
19 |
Correct |
17 ms |
39508 KB |
Output is correct |
20 |
Correct |
18 ms |
39500 KB |
Output is correct |
21 |
Correct |
2 ms |
476 KB |
Output is correct |
22 |
Correct |
67 ms |
5452 KB |
Output is correct |
23 |
Correct |
53 ms |
5508 KB |
Output is correct |
24 |
Correct |
41 ms |
3468 KB |
Output is correct |
25 |
Correct |
73 ms |
44852 KB |
Output is correct |
26 |
Correct |
74 ms |
44768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
17 ms |
39380 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
17 ms |
39488 KB |
Output is correct |
6 |
Correct |
20 ms |
39500 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
18 ms |
39416 KB |
Output is correct |
9 |
Correct |
17 ms |
39508 KB |
Output is correct |
10 |
Correct |
17 ms |
39508 KB |
Output is correct |
11 |
Correct |
51 ms |
4976 KB |
Output is correct |
12 |
Correct |
33 ms |
3008 KB |
Output is correct |
13 |
Correct |
35 ms |
3816 KB |
Output is correct |
14 |
Correct |
71 ms |
44588 KB |
Output is correct |
15 |
Correct |
63 ms |
44264 KB |
Output is correct |
16 |
Correct |
57 ms |
44348 KB |
Output is correct |
17 |
Correct |
16 ms |
39356 KB |
Output is correct |
18 |
Correct |
17 ms |
39380 KB |
Output is correct |
19 |
Correct |
17 ms |
39508 KB |
Output is correct |
20 |
Correct |
18 ms |
39500 KB |
Output is correct |
21 |
Correct |
2 ms |
476 KB |
Output is correct |
22 |
Correct |
67 ms |
5452 KB |
Output is correct |
23 |
Correct |
53 ms |
5508 KB |
Output is correct |
24 |
Correct |
41 ms |
3468 KB |
Output is correct |
25 |
Correct |
73 ms |
44852 KB |
Output is correct |
26 |
Correct |
74 ms |
44768 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 |
20 ms |
39688 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
380 KB |
Output is correct |
34 |
Correct |
102 ms |
5960 KB |
Output is correct |
35 |
Correct |
94 ms |
5616 KB |
Output is correct |
36 |
Correct |
105 ms |
5660 KB |
Output is correct |
37 |
Correct |
108 ms |
45436 KB |
Output is correct |
38 |
Correct |
74 ms |
44852 KB |
Output is correct |
39 |
Correct |
51 ms |
42304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
17 ms |
39380 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
17 ms |
39488 KB |
Output is correct |
6 |
Correct |
20 ms |
39500 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
18 ms |
39416 KB |
Output is correct |
9 |
Correct |
17 ms |
39508 KB |
Output is correct |
10 |
Correct |
17 ms |
39508 KB |
Output is correct |
11 |
Correct |
51 ms |
4976 KB |
Output is correct |
12 |
Correct |
33 ms |
3008 KB |
Output is correct |
13 |
Correct |
35 ms |
3816 KB |
Output is correct |
14 |
Correct |
71 ms |
44588 KB |
Output is correct |
15 |
Correct |
63 ms |
44264 KB |
Output is correct |
16 |
Correct |
57 ms |
44348 KB |
Output is correct |
17 |
Correct |
16 ms |
39356 KB |
Output is correct |
18 |
Correct |
17 ms |
39380 KB |
Output is correct |
19 |
Correct |
17 ms |
39508 KB |
Output is correct |
20 |
Correct |
18 ms |
39500 KB |
Output is correct |
21 |
Correct |
2 ms |
476 KB |
Output is correct |
22 |
Correct |
67 ms |
5452 KB |
Output is correct |
23 |
Correct |
53 ms |
5508 KB |
Output is correct |
24 |
Correct |
41 ms |
3468 KB |
Output is correct |
25 |
Correct |
73 ms |
44852 KB |
Output is correct |
26 |
Correct |
74 ms |
44768 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 |
20 ms |
39688 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
380 KB |
Output is correct |
34 |
Correct |
102 ms |
5960 KB |
Output is correct |
35 |
Correct |
94 ms |
5616 KB |
Output is correct |
36 |
Correct |
105 ms |
5660 KB |
Output is correct |
37 |
Correct |
108 ms |
45436 KB |
Output is correct |
38 |
Correct |
74 ms |
44852 KB |
Output is correct |
39 |
Correct |
51 ms |
42304 KB |
Output is correct |
40 |
Correct |
3 ms |
468 KB |
Output is correct |
41 |
Correct |
5 ms |
480 KB |
Output is correct |
42 |
Correct |
3 ms |
468 KB |
Output is correct |
43 |
Correct |
5 ms |
476 KB |
Output is correct |
44 |
Correct |
214 ms |
6800 KB |
Output is correct |
45 |
Correct |
179 ms |
6704 KB |
Output is correct |
46 |
Correct |
212 ms |
6244 KB |
Output is correct |
47 |
Correct |
179 ms |
46056 KB |
Output is correct |
48 |
Correct |
81 ms |
45768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
18 ms |
39432 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
18 ms |
39456 KB |
Output is correct |
6 |
Correct |
22 ms |
39496 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
20 ms |
39508 KB |
Output is correct |
9 |
Correct |
17 ms |
39508 KB |
Output is correct |
10 |
Correct |
17 ms |
39480 KB |
Output is correct |
11 |
Correct |
18 ms |
39380 KB |
Output is correct |
12 |
Correct |
17 ms |
39456 KB |
Output is correct |
13 |
Correct |
19 ms |
39492 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 |
21 ms |
39484 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
18 ms |
39508 KB |
Output is correct |
21 |
Correct |
17 ms |
39456 KB |
Output is correct |
22 |
Correct |
17 ms |
39544 KB |
Output is correct |
23 |
Correct |
17 ms |
39508 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
596 KB |
Output is correct |
27 |
Correct |
6 ms |
596 KB |
Output is correct |
28 |
Correct |
7 ms |
580 KB |
Output is correct |
29 |
Correct |
21 ms |
39704 KB |
Output is correct |
30 |
Correct |
3 ms |
476 KB |
Output is correct |
31 |
Correct |
5 ms |
468 KB |
Output is correct |
32 |
Correct |
20 ms |
39596 KB |
Output is correct |
33 |
Correct |
19 ms |
39736 KB |
Output is correct |
34 |
Correct |
22 ms |
39792 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 |
596 KB |
Output is correct |
38 |
Correct |
4 ms |
596 KB |
Output is correct |
39 |
Correct |
2 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
17 ms |
39380 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
17 ms |
39488 KB |
Output is correct |
45 |
Correct |
20 ms |
39500 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
18 ms |
39416 KB |
Output is correct |
48 |
Correct |
17 ms |
39508 KB |
Output is correct |
49 |
Correct |
17 ms |
39508 KB |
Output is correct |
50 |
Correct |
51 ms |
4976 KB |
Output is correct |
51 |
Correct |
33 ms |
3008 KB |
Output is correct |
52 |
Correct |
35 ms |
3816 KB |
Output is correct |
53 |
Correct |
71 ms |
44588 KB |
Output is correct |
54 |
Correct |
63 ms |
44264 KB |
Output is correct |
55 |
Correct |
57 ms |
44348 KB |
Output is correct |
56 |
Correct |
16 ms |
39356 KB |
Output is correct |
57 |
Correct |
17 ms |
39380 KB |
Output is correct |
58 |
Correct |
17 ms |
39508 KB |
Output is correct |
59 |
Correct |
18 ms |
39500 KB |
Output is correct |
60 |
Correct |
2 ms |
476 KB |
Output is correct |
61 |
Correct |
67 ms |
5452 KB |
Output is correct |
62 |
Correct |
53 ms |
5508 KB |
Output is correct |
63 |
Correct |
41 ms |
3468 KB |
Output is correct |
64 |
Correct |
73 ms |
44852 KB |
Output is correct |
65 |
Correct |
74 ms |
44768 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 |
20 ms |
39688 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
380 KB |
Output is correct |
73 |
Correct |
102 ms |
5960 KB |
Output is correct |
74 |
Correct |
94 ms |
5616 KB |
Output is correct |
75 |
Correct |
105 ms |
5660 KB |
Output is correct |
76 |
Correct |
108 ms |
45436 KB |
Output is correct |
77 |
Correct |
74 ms |
44852 KB |
Output is correct |
78 |
Correct |
51 ms |
42304 KB |
Output is correct |
79 |
Correct |
3 ms |
468 KB |
Output is correct |
80 |
Correct |
5 ms |
480 KB |
Output is correct |
81 |
Correct |
3 ms |
468 KB |
Output is correct |
82 |
Correct |
5 ms |
476 KB |
Output is correct |
83 |
Correct |
214 ms |
6800 KB |
Output is correct |
84 |
Correct |
179 ms |
6704 KB |
Output is correct |
85 |
Correct |
212 ms |
6244 KB |
Output is correct |
86 |
Correct |
179 ms |
46056 KB |
Output is correct |
87 |
Correct |
81 ms |
45768 KB |
Output is correct |
88 |
Execution timed out |
2047 ms |
10012 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |