#include <bits/stdc++.h>
using namespace std;
#define maxim(X, Y) (X = max(X, Y))
#define all(X) begin(X), end(X)
const int INF = 2e9+5;
struct DS : set<pair<int, int>> {
void add(int i, int v) {
auto f = lower_bound({i+1, 0});
if(f != begin() && prev(f) != end() && prev(f)->second >= v) return;
f = insert({i, v}).first;
while(next(f) != end() && next(f)->second <= v) {
erase(next(f));
if(f == end()) exit(0);
}
}
int query(int i) {
auto f = lower_bound({i+1, 0});
if(f == begin()) return -INF;
if(prev(f) == end()) return -INF;
return prev(f)->second;
}
};
struct BIT {
int n;
vector<DS> a;
BIT(int N) : n(N), a(N+1) {}
void update(int i, int j, int v) {
for(++i; i <= n; i += i&-i) a[i].add(j, v);
}
int query(int i, int j) {
int v = -INF;
for(++i; i >= 1; i -= i&-i) maxim(v, a[i].query(j));
return v;
}
};
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int N; cin >> N;
array<int, 3> a[N];
vector<int> C[2];
array<int, 2> sz, c[N];
for(auto &[x, y, z] : a) {
cin >> x >> y >> z;
C[0].push_back(x);
C[1].push_back(y);
}
DS f[2];
for(int i = 0; i < 2; ++i) {
sort(all(C[i]));
C[i].erase(unique(all(C[i])), end(C[i]));
}
sort(a, a + N, [&](const auto &i, const auto &j) {
return i[2] < j[2];
});
BIT b(sz[0]);
for(int i = 0; i < N; ++i)
for(int k = 0; k < 2; ++k)
c[i][k] = sz[k] - 1 - (lower_bound(all(C[k]), a[i][k]) - begin(C[k]));
int ans = -INF;
for(int l = 0, r; l < N; l = r) {
for(r = l + 1; r < N && a[l][2] == a[r][2]; ++r);
for(int i = l; i < r; ++i)
maxim(ans, a[i][2] + b.query(c[i][0] - 1, c[i][1] - 1));
for(int i = l; i < r; ++i) {
int j = f[0].query(sz[0] - 2 - c[i][0]);
if(j > sz[1] - 1 - c[i][1])
b.update(c[i][0], sz[1] - 1 - j, a[i][0] + C[1][j]);
j = f[1].query(sz[1] - 2 - c[i][1]);
if(j > sz[0] - 1 - c[i][0])
b.update(sz[0] - 1 - j, c[i][1], a[i][1] + C[0][j]);
for(int k = 0; k < 2; ++k)
f[k].add(sz[k] - 1 - c[i][k], sz[!k] - 1 - c[i][!k]);
}
}
cout << max(ans, int(-1));
}
Compilation message
team.cpp: In function 'int main()':
team.cpp:64:13: warning: 'sz' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | BIT b(sz[0]);
| ^
team.cpp:68:24: warning: ''target_mem_ref' not supported by dump_expr<expression error>' may be used uninitialized in this function [-Wmaybe-uninitialized]
68 | c[i][k] = sz[k] - 1 - (lower_bound(all(C[k]), a[i][k]) - begin(C[k]));
team.cpp:80:17: warning: '*((void*)& sz +4)' may be used uninitialized in this function [-Wmaybe-uninitialized]
80 | if(j > sz[1] - 1 - c[i][1])
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
452 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
456 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
584 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
452 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
456 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
584 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
6 ms |
980 KB |
Output is correct |
27 |
Correct |
6 ms |
852 KB |
Output is correct |
28 |
Correct |
6 ms |
852 KB |
Output is correct |
29 |
Correct |
7 ms |
724 KB |
Output is correct |
30 |
Correct |
5 ms |
724 KB |
Output is correct |
31 |
Correct |
4 ms |
724 KB |
Output is correct |
32 |
Correct |
5 ms |
596 KB |
Output is correct |
33 |
Correct |
4 ms |
676 KB |
Output is correct |
34 |
Correct |
7 ms |
1096 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
2 ms |
596 KB |
Output is correct |
37 |
Correct |
5 ms |
724 KB |
Output is correct |
38 |
Correct |
5 ms |
720 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
55 ms |
5312 KB |
Output is correct |
12 |
Correct |
51 ms |
3532 KB |
Output is correct |
13 |
Correct |
49 ms |
4176 KB |
Output is correct |
14 |
Correct |
74 ms |
5332 KB |
Output is correct |
15 |
Correct |
57 ms |
5328 KB |
Output is correct |
16 |
Correct |
36 ms |
5352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
55 ms |
5312 KB |
Output is correct |
12 |
Correct |
51 ms |
3532 KB |
Output is correct |
13 |
Correct |
49 ms |
4176 KB |
Output is correct |
14 |
Correct |
74 ms |
5332 KB |
Output is correct |
15 |
Correct |
57 ms |
5328 KB |
Output is correct |
16 |
Correct |
36 ms |
5352 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
600 KB |
Output is correct |
22 |
Correct |
92 ms |
5316 KB |
Output is correct |
23 |
Correct |
73 ms |
5256 KB |
Output is correct |
24 |
Correct |
49 ms |
3892 KB |
Output is correct |
25 |
Correct |
71 ms |
5324 KB |
Output is correct |
26 |
Correct |
66 ms |
5312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
55 ms |
5312 KB |
Output is correct |
12 |
Correct |
51 ms |
3532 KB |
Output is correct |
13 |
Correct |
49 ms |
4176 KB |
Output is correct |
14 |
Correct |
74 ms |
5332 KB |
Output is correct |
15 |
Correct |
57 ms |
5328 KB |
Output is correct |
16 |
Correct |
36 ms |
5352 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
600 KB |
Output is correct |
22 |
Correct |
92 ms |
5316 KB |
Output is correct |
23 |
Correct |
73 ms |
5256 KB |
Output is correct |
24 |
Correct |
49 ms |
3892 KB |
Output is correct |
25 |
Correct |
71 ms |
5324 KB |
Output is correct |
26 |
Correct |
66 ms |
5312 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
5 ms |
724 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
596 KB |
Output is correct |
34 |
Correct |
104 ms |
5480 KB |
Output is correct |
35 |
Correct |
88 ms |
5352 KB |
Output is correct |
36 |
Correct |
122 ms |
5596 KB |
Output is correct |
37 |
Correct |
93 ms |
5528 KB |
Output is correct |
38 |
Correct |
65 ms |
5536 KB |
Output is correct |
39 |
Correct |
32 ms |
3448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
55 ms |
5312 KB |
Output is correct |
12 |
Correct |
51 ms |
3532 KB |
Output is correct |
13 |
Correct |
49 ms |
4176 KB |
Output is correct |
14 |
Correct |
74 ms |
5332 KB |
Output is correct |
15 |
Correct |
57 ms |
5328 KB |
Output is correct |
16 |
Correct |
36 ms |
5352 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
600 KB |
Output is correct |
22 |
Correct |
92 ms |
5316 KB |
Output is correct |
23 |
Correct |
73 ms |
5256 KB |
Output is correct |
24 |
Correct |
49 ms |
3892 KB |
Output is correct |
25 |
Correct |
71 ms |
5324 KB |
Output is correct |
26 |
Correct |
66 ms |
5312 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
5 ms |
724 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
596 KB |
Output is correct |
34 |
Correct |
104 ms |
5480 KB |
Output is correct |
35 |
Correct |
88 ms |
5352 KB |
Output is correct |
36 |
Correct |
122 ms |
5596 KB |
Output is correct |
37 |
Correct |
93 ms |
5528 KB |
Output is correct |
38 |
Correct |
65 ms |
5536 KB |
Output is correct |
39 |
Correct |
32 ms |
3448 KB |
Output is correct |
40 |
Correct |
4 ms |
736 KB |
Output is correct |
41 |
Correct |
4 ms |
716 KB |
Output is correct |
42 |
Correct |
3 ms |
724 KB |
Output is correct |
43 |
Correct |
4 ms |
732 KB |
Output is correct |
44 |
Correct |
140 ms |
5564 KB |
Output is correct |
45 |
Correct |
135 ms |
5612 KB |
Output is correct |
46 |
Correct |
152 ms |
5520 KB |
Output is correct |
47 |
Correct |
131 ms |
5060 KB |
Output is correct |
48 |
Correct |
60 ms |
5056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
452 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
456 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
584 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
6 ms |
980 KB |
Output is correct |
27 |
Correct |
6 ms |
852 KB |
Output is correct |
28 |
Correct |
6 ms |
852 KB |
Output is correct |
29 |
Correct |
7 ms |
724 KB |
Output is correct |
30 |
Correct |
5 ms |
724 KB |
Output is correct |
31 |
Correct |
4 ms |
724 KB |
Output is correct |
32 |
Correct |
5 ms |
596 KB |
Output is correct |
33 |
Correct |
4 ms |
676 KB |
Output is correct |
34 |
Correct |
7 ms |
1096 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
2 ms |
596 KB |
Output is correct |
37 |
Correct |
5 ms |
724 KB |
Output is correct |
38 |
Correct |
5 ms |
720 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
448 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
55 ms |
5312 KB |
Output is correct |
51 |
Correct |
51 ms |
3532 KB |
Output is correct |
52 |
Correct |
49 ms |
4176 KB |
Output is correct |
53 |
Correct |
74 ms |
5332 KB |
Output is correct |
54 |
Correct |
57 ms |
5328 KB |
Output is correct |
55 |
Correct |
36 ms |
5352 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
1 ms |
468 KB |
Output is correct |
58 |
Correct |
1 ms |
468 KB |
Output is correct |
59 |
Correct |
1 ms |
468 KB |
Output is correct |
60 |
Correct |
3 ms |
600 KB |
Output is correct |
61 |
Correct |
92 ms |
5316 KB |
Output is correct |
62 |
Correct |
73 ms |
5256 KB |
Output is correct |
63 |
Correct |
49 ms |
3892 KB |
Output is correct |
64 |
Correct |
71 ms |
5324 KB |
Output is correct |
65 |
Correct |
66 ms |
5312 KB |
Output is correct |
66 |
Correct |
1 ms |
468 KB |
Output is correct |
67 |
Correct |
1 ms |
468 KB |
Output is correct |
68 |
Correct |
1 ms |
468 KB |
Output is correct |
69 |
Correct |
1 ms |
468 KB |
Output is correct |
70 |
Correct |
5 ms |
724 KB |
Output is correct |
71 |
Correct |
2 ms |
596 KB |
Output is correct |
72 |
Correct |
2 ms |
596 KB |
Output is correct |
73 |
Correct |
104 ms |
5480 KB |
Output is correct |
74 |
Correct |
88 ms |
5352 KB |
Output is correct |
75 |
Correct |
122 ms |
5596 KB |
Output is correct |
76 |
Correct |
93 ms |
5528 KB |
Output is correct |
77 |
Correct |
65 ms |
5536 KB |
Output is correct |
78 |
Correct |
32 ms |
3448 KB |
Output is correct |
79 |
Correct |
4 ms |
736 KB |
Output is correct |
80 |
Correct |
4 ms |
716 KB |
Output is correct |
81 |
Correct |
3 ms |
724 KB |
Output is correct |
82 |
Correct |
4 ms |
732 KB |
Output is correct |
83 |
Correct |
140 ms |
5564 KB |
Output is correct |
84 |
Correct |
135 ms |
5612 KB |
Output is correct |
85 |
Correct |
152 ms |
5520 KB |
Output is correct |
86 |
Correct |
131 ms |
5060 KB |
Output is correct |
87 |
Correct |
60 ms |
5056 KB |
Output is correct |
88 |
Runtime error |
116 ms |
9248 KB |
Execution killed with signal 11 |
89 |
Halted |
0 ms |
0 KB |
- |