#include <bits/stdc++.h>
using namespace std;
struct abc {
int a, b, c, bestB, bestC;
};
const int MAX_N = 2e5;
const int INF = 1e8;
abc v[MAX_N];
struct AIB {
unordered_map<int, int> aib;
void init() {
aib.clear();
}
void update( int i, int x ) {
while ( i <= MAX_N ) {
aib[i] = max( aib[i], x );
i += (i & -i);
}
}
int query( int i ) {
int ans = 0;
while ( i > 0 ) {
ans = max( ans, aib[i] );
i -= (i & -i);
}
return (ans == 0 ? -INF : ans);
}
} aib;
struct AIB2d {
unordered_map<int, int> aib[MAX_N + 1];
void init() {
for ( int i = 0; i <= MAX_N; i++ )
aib[i].clear();
}
void update( int i, int j, int x ) {
while ( i <= MAX_N ) {
int p = j;
while ( p <= MAX_N ) {
aib[i][p] = max( aib[i][p], x );
p += (p & -p);
}
i += (i & -i);
}
}
int query( int i, int j ) {
int ans = 0;
while ( i > 0 ) {
int p = j;
while ( p > 0 ) {
ans = max( ans, aib[i][p] );
p -= (p & -p);
}
i -= (i & -i);
}
return (ans == 0 ? -INF : ans);
}
void updateInv( int i, int j, int x ) {
update( MAX_N + 1 - i, MAX_N + 1 - j, x );
}
int queryInv( int i, int j ) {
return query( MAX_N + 1 - i, MAX_N + 1 - j );
}
} aib2d;
map<int, int> normA, normB, normC;
int main() {
ios_base::sync_with_stdio( false );
cin.tie( NULL );
int n;
cin >> n;
for ( int i = 0; i < n; i++ )
cin >> v[i].a >> v[i].b >> v[i].c;
for ( int i = 0; i < n; i++ ) {
normA[v[i].a] = 1;
normB[v[i].b] = 1;
normC[v[i].c] = 1;
}
int x;
x = 0;
for ( auto p: normA )
normA[p.first] = ++x;
x = 0;
for ( auto p: normB )
normB[p.first] = ++x;
x = 0;
for ( auto p: normC )
normC[p.first] = ++x;
sort( v, v + n, []( abc a, abc b ) {
if ( a.a == b.a )
return a.b < b.b;
return a.a < b.a;
} );
aib.init();
for ( int i = 0; i < n; i++ ) {
v[i].bestC = aib.query( normB[v[i].b] - 1 );
aib.update( normB[v[i].b], v[i].c );
}
sort( v, v + n, []( abc a, abc b ) {
if ( a.a == b.a )
return a.c < b.c;
return a.a < b.a;
} );
aib.init();
for ( int i = 0; i < n; i++ ) {
v[i].bestB = aib.query( normC[v[i].c] - 1 );
aib.update( normC[v[i].c], v[i].b );
}
int ans = -1;
int l = 0, r = 0;
aib2d.init();
while ( l < n ) {
r = l;
while ( r < n && v[l].a == v[r].a )
r++;
for ( int i = l; i < r; i++ )
ans = max( ans, v[i].a + aib2d.queryInv( normB[v[i].b] + 1, normC[v[i].c] + 1 ) );
for ( int i = l; i < r; i++ ) {
if ( v[i].bestC > v[i].c )
aib2d.updateInv( normB[v[i].b], normC[v[i].bestC], v[i].b + v[i].bestC );
if ( v[i].bestB > v[i].b )
aib2d.updateInv( normB[v[i].bestB], normC[v[i].c], v[i].bestB + v[i].c );
}
l = r;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12896 KB |
Output is correct |
4 |
Correct |
4 ms |
12888 KB |
Output is correct |
5 |
Correct |
5 ms |
13144 KB |
Output is correct |
6 |
Correct |
4 ms |
12892 KB |
Output is correct |
7 |
Correct |
4 ms |
12892 KB |
Output is correct |
8 |
Correct |
5 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
4 ms |
12888 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12696 KB |
Output is correct |
13 |
Correct |
4 ms |
12720 KB |
Output is correct |
14 |
Correct |
6 ms |
13148 KB |
Output is correct |
15 |
Correct |
5 ms |
12892 KB |
Output is correct |
16 |
Correct |
5 ms |
13144 KB |
Output is correct |
17 |
Correct |
5 ms |
12892 KB |
Output is correct |
18 |
Correct |
5 ms |
12956 KB |
Output is correct |
19 |
Correct |
5 ms |
12892 KB |
Output is correct |
20 |
Correct |
4 ms |
12892 KB |
Output is correct |
21 |
Correct |
5 ms |
13040 KB |
Output is correct |
22 |
Correct |
5 ms |
13148 KB |
Output is correct |
23 |
Correct |
5 ms |
12892 KB |
Output is correct |
24 |
Correct |
6 ms |
12888 KB |
Output is correct |
25 |
Correct |
5 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12896 KB |
Output is correct |
4 |
Correct |
4 ms |
12888 KB |
Output is correct |
5 |
Correct |
5 ms |
13144 KB |
Output is correct |
6 |
Correct |
4 ms |
12892 KB |
Output is correct |
7 |
Correct |
4 ms |
12892 KB |
Output is correct |
8 |
Correct |
5 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
4 ms |
12888 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12696 KB |
Output is correct |
13 |
Correct |
4 ms |
12720 KB |
Output is correct |
14 |
Correct |
6 ms |
13148 KB |
Output is correct |
15 |
Correct |
5 ms |
12892 KB |
Output is correct |
16 |
Correct |
5 ms |
13144 KB |
Output is correct |
17 |
Correct |
5 ms |
12892 KB |
Output is correct |
18 |
Correct |
5 ms |
12956 KB |
Output is correct |
19 |
Correct |
5 ms |
12892 KB |
Output is correct |
20 |
Correct |
4 ms |
12892 KB |
Output is correct |
21 |
Correct |
5 ms |
13040 KB |
Output is correct |
22 |
Correct |
5 ms |
13148 KB |
Output is correct |
23 |
Correct |
5 ms |
12892 KB |
Output is correct |
24 |
Correct |
6 ms |
12888 KB |
Output is correct |
25 |
Correct |
5 ms |
12892 KB |
Output is correct |
26 |
Correct |
45 ms |
21012 KB |
Output is correct |
27 |
Correct |
30 ms |
18000 KB |
Output is correct |
28 |
Correct |
26 ms |
17616 KB |
Output is correct |
29 |
Correct |
24 ms |
16112 KB |
Output is correct |
30 |
Correct |
18 ms |
15964 KB |
Output is correct |
31 |
Correct |
33 ms |
15956 KB |
Output is correct |
32 |
Correct |
13 ms |
13656 KB |
Output is correct |
33 |
Correct |
11 ms |
13916 KB |
Output is correct |
34 |
Correct |
19 ms |
16332 KB |
Output is correct |
35 |
Correct |
6 ms |
13148 KB |
Output is correct |
36 |
Correct |
6 ms |
13148 KB |
Output is correct |
37 |
Correct |
11 ms |
13976 KB |
Output is correct |
38 |
Correct |
11 ms |
14176 KB |
Output is correct |
39 |
Correct |
8 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12892 KB |
Output is correct |
4 |
Correct |
4 ms |
12892 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12892 KB |
Output is correct |
7 |
Correct |
4 ms |
12892 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12932 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
11 |
Correct |
240 ms |
14936 KB |
Output is correct |
12 |
Correct |
150 ms |
14940 KB |
Output is correct |
13 |
Correct |
198 ms |
15480 KB |
Output is correct |
14 |
Correct |
219 ms |
15952 KB |
Output is correct |
15 |
Correct |
216 ms |
15736 KB |
Output is correct |
16 |
Correct |
234 ms |
15736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12892 KB |
Output is correct |
4 |
Correct |
4 ms |
12892 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12892 KB |
Output is correct |
7 |
Correct |
4 ms |
12892 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12932 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
11 |
Correct |
240 ms |
14936 KB |
Output is correct |
12 |
Correct |
150 ms |
14940 KB |
Output is correct |
13 |
Correct |
198 ms |
15480 KB |
Output is correct |
14 |
Correct |
219 ms |
15952 KB |
Output is correct |
15 |
Correct |
216 ms |
15736 KB |
Output is correct |
16 |
Correct |
234 ms |
15736 KB |
Output is correct |
17 |
Correct |
4 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
4 ms |
12888 KB |
Output is correct |
20 |
Correct |
5 ms |
12944 KB |
Output is correct |
21 |
Correct |
8 ms |
12892 KB |
Output is correct |
22 |
Correct |
284 ms |
15744 KB |
Output is correct |
23 |
Correct |
248 ms |
15956 KB |
Output is correct |
24 |
Correct |
176 ms |
15744 KB |
Output is correct |
25 |
Correct |
241 ms |
15708 KB |
Output is correct |
26 |
Correct |
199 ms |
15740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12892 KB |
Output is correct |
4 |
Correct |
4 ms |
12892 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12892 KB |
Output is correct |
7 |
Correct |
4 ms |
12892 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12932 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
11 |
Correct |
240 ms |
14936 KB |
Output is correct |
12 |
Correct |
150 ms |
14940 KB |
Output is correct |
13 |
Correct |
198 ms |
15480 KB |
Output is correct |
14 |
Correct |
219 ms |
15952 KB |
Output is correct |
15 |
Correct |
216 ms |
15736 KB |
Output is correct |
16 |
Correct |
234 ms |
15736 KB |
Output is correct |
17 |
Correct |
4 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
4 ms |
12888 KB |
Output is correct |
20 |
Correct |
5 ms |
12944 KB |
Output is correct |
21 |
Correct |
8 ms |
12892 KB |
Output is correct |
22 |
Correct |
284 ms |
15744 KB |
Output is correct |
23 |
Correct |
248 ms |
15956 KB |
Output is correct |
24 |
Correct |
176 ms |
15744 KB |
Output is correct |
25 |
Correct |
241 ms |
15708 KB |
Output is correct |
26 |
Correct |
199 ms |
15740 KB |
Output is correct |
27 |
Correct |
5 ms |
13148 KB |
Output is correct |
28 |
Correct |
5 ms |
12940 KB |
Output is correct |
29 |
Correct |
5 ms |
12892 KB |
Output is correct |
30 |
Correct |
5 ms |
12892 KB |
Output is correct |
31 |
Correct |
13 ms |
13660 KB |
Output is correct |
32 |
Correct |
7 ms |
13228 KB |
Output is correct |
33 |
Correct |
7 ms |
13148 KB |
Output is correct |
34 |
Correct |
400 ms |
20268 KB |
Output is correct |
35 |
Correct |
293 ms |
19536 KB |
Output is correct |
36 |
Correct |
308 ms |
19588 KB |
Output is correct |
37 |
Correct |
247 ms |
18776 KB |
Output is correct |
38 |
Correct |
192 ms |
16104 KB |
Output is correct |
39 |
Correct |
209 ms |
20004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12892 KB |
Output is correct |
4 |
Correct |
4 ms |
12892 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12892 KB |
Output is correct |
7 |
Correct |
4 ms |
12892 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12932 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
11 |
Correct |
240 ms |
14936 KB |
Output is correct |
12 |
Correct |
150 ms |
14940 KB |
Output is correct |
13 |
Correct |
198 ms |
15480 KB |
Output is correct |
14 |
Correct |
219 ms |
15952 KB |
Output is correct |
15 |
Correct |
216 ms |
15736 KB |
Output is correct |
16 |
Correct |
234 ms |
15736 KB |
Output is correct |
17 |
Correct |
4 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
4 ms |
12888 KB |
Output is correct |
20 |
Correct |
5 ms |
12944 KB |
Output is correct |
21 |
Correct |
8 ms |
12892 KB |
Output is correct |
22 |
Correct |
284 ms |
15744 KB |
Output is correct |
23 |
Correct |
248 ms |
15956 KB |
Output is correct |
24 |
Correct |
176 ms |
15744 KB |
Output is correct |
25 |
Correct |
241 ms |
15708 KB |
Output is correct |
26 |
Correct |
199 ms |
15740 KB |
Output is correct |
27 |
Correct |
5 ms |
13148 KB |
Output is correct |
28 |
Correct |
5 ms |
12940 KB |
Output is correct |
29 |
Correct |
5 ms |
12892 KB |
Output is correct |
30 |
Correct |
5 ms |
12892 KB |
Output is correct |
31 |
Correct |
13 ms |
13660 KB |
Output is correct |
32 |
Correct |
7 ms |
13228 KB |
Output is correct |
33 |
Correct |
7 ms |
13148 KB |
Output is correct |
34 |
Correct |
400 ms |
20268 KB |
Output is correct |
35 |
Correct |
293 ms |
19536 KB |
Output is correct |
36 |
Correct |
308 ms |
19588 KB |
Output is correct |
37 |
Correct |
247 ms |
18776 KB |
Output is correct |
38 |
Correct |
192 ms |
16104 KB |
Output is correct |
39 |
Correct |
209 ms |
20004 KB |
Output is correct |
40 |
Correct |
17 ms |
15696 KB |
Output is correct |
41 |
Correct |
26 ms |
15904 KB |
Output is correct |
42 |
Correct |
11 ms |
14148 KB |
Output is correct |
43 |
Correct |
12 ms |
14168 KB |
Output is correct |
44 |
Correct |
1724 ms |
83052 KB |
Output is correct |
45 |
Correct |
762 ms |
74516 KB |
Output is correct |
46 |
Correct |
936 ms |
78772 KB |
Output is correct |
47 |
Correct |
733 ms |
74088 KB |
Output is correct |
48 |
Correct |
251 ms |
18812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12896 KB |
Output is correct |
4 |
Correct |
4 ms |
12888 KB |
Output is correct |
5 |
Correct |
5 ms |
13144 KB |
Output is correct |
6 |
Correct |
4 ms |
12892 KB |
Output is correct |
7 |
Correct |
4 ms |
12892 KB |
Output is correct |
8 |
Correct |
5 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
4 ms |
12888 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12696 KB |
Output is correct |
13 |
Correct |
4 ms |
12720 KB |
Output is correct |
14 |
Correct |
6 ms |
13148 KB |
Output is correct |
15 |
Correct |
5 ms |
12892 KB |
Output is correct |
16 |
Correct |
5 ms |
13144 KB |
Output is correct |
17 |
Correct |
5 ms |
12892 KB |
Output is correct |
18 |
Correct |
5 ms |
12956 KB |
Output is correct |
19 |
Correct |
5 ms |
12892 KB |
Output is correct |
20 |
Correct |
4 ms |
12892 KB |
Output is correct |
21 |
Correct |
5 ms |
13040 KB |
Output is correct |
22 |
Correct |
5 ms |
13148 KB |
Output is correct |
23 |
Correct |
5 ms |
12892 KB |
Output is correct |
24 |
Correct |
6 ms |
12888 KB |
Output is correct |
25 |
Correct |
5 ms |
12892 KB |
Output is correct |
26 |
Correct |
45 ms |
21012 KB |
Output is correct |
27 |
Correct |
30 ms |
18000 KB |
Output is correct |
28 |
Correct |
26 ms |
17616 KB |
Output is correct |
29 |
Correct |
24 ms |
16112 KB |
Output is correct |
30 |
Correct |
18 ms |
15964 KB |
Output is correct |
31 |
Correct |
33 ms |
15956 KB |
Output is correct |
32 |
Correct |
13 ms |
13656 KB |
Output is correct |
33 |
Correct |
11 ms |
13916 KB |
Output is correct |
34 |
Correct |
19 ms |
16332 KB |
Output is correct |
35 |
Correct |
6 ms |
13148 KB |
Output is correct |
36 |
Correct |
6 ms |
13148 KB |
Output is correct |
37 |
Correct |
11 ms |
13976 KB |
Output is correct |
38 |
Correct |
11 ms |
14176 KB |
Output is correct |
39 |
Correct |
8 ms |
12892 KB |
Output is correct |
40 |
Correct |
4 ms |
12888 KB |
Output is correct |
41 |
Correct |
4 ms |
12892 KB |
Output is correct |
42 |
Correct |
4 ms |
12892 KB |
Output is correct |
43 |
Correct |
4 ms |
12892 KB |
Output is correct |
44 |
Correct |
4 ms |
12892 KB |
Output is correct |
45 |
Correct |
4 ms |
12892 KB |
Output is correct |
46 |
Correct |
4 ms |
12892 KB |
Output is correct |
47 |
Correct |
4 ms |
12892 KB |
Output is correct |
48 |
Correct |
4 ms |
12932 KB |
Output is correct |
49 |
Correct |
4 ms |
12892 KB |
Output is correct |
50 |
Correct |
240 ms |
14936 KB |
Output is correct |
51 |
Correct |
150 ms |
14940 KB |
Output is correct |
52 |
Correct |
198 ms |
15480 KB |
Output is correct |
53 |
Correct |
219 ms |
15952 KB |
Output is correct |
54 |
Correct |
216 ms |
15736 KB |
Output is correct |
55 |
Correct |
234 ms |
15736 KB |
Output is correct |
56 |
Correct |
4 ms |
12892 KB |
Output is correct |
57 |
Correct |
4 ms |
12892 KB |
Output is correct |
58 |
Correct |
4 ms |
12888 KB |
Output is correct |
59 |
Correct |
5 ms |
12944 KB |
Output is correct |
60 |
Correct |
8 ms |
12892 KB |
Output is correct |
61 |
Correct |
284 ms |
15744 KB |
Output is correct |
62 |
Correct |
248 ms |
15956 KB |
Output is correct |
63 |
Correct |
176 ms |
15744 KB |
Output is correct |
64 |
Correct |
241 ms |
15708 KB |
Output is correct |
65 |
Correct |
199 ms |
15740 KB |
Output is correct |
66 |
Correct |
5 ms |
13148 KB |
Output is correct |
67 |
Correct |
5 ms |
12940 KB |
Output is correct |
68 |
Correct |
5 ms |
12892 KB |
Output is correct |
69 |
Correct |
5 ms |
12892 KB |
Output is correct |
70 |
Correct |
13 ms |
13660 KB |
Output is correct |
71 |
Correct |
7 ms |
13228 KB |
Output is correct |
72 |
Correct |
7 ms |
13148 KB |
Output is correct |
73 |
Correct |
400 ms |
20268 KB |
Output is correct |
74 |
Correct |
293 ms |
19536 KB |
Output is correct |
75 |
Correct |
308 ms |
19588 KB |
Output is correct |
76 |
Correct |
247 ms |
18776 KB |
Output is correct |
77 |
Correct |
192 ms |
16104 KB |
Output is correct |
78 |
Correct |
209 ms |
20004 KB |
Output is correct |
79 |
Correct |
17 ms |
15696 KB |
Output is correct |
80 |
Correct |
26 ms |
15904 KB |
Output is correct |
81 |
Correct |
11 ms |
14148 KB |
Output is correct |
82 |
Correct |
12 ms |
14168 KB |
Output is correct |
83 |
Correct |
1724 ms |
83052 KB |
Output is correct |
84 |
Correct |
762 ms |
74516 KB |
Output is correct |
85 |
Correct |
936 ms |
78772 KB |
Output is correct |
86 |
Correct |
733 ms |
74088 KB |
Output is correct |
87 |
Correct |
251 ms |
18812 KB |
Output is correct |
88 |
Execution timed out |
2102 ms |
215384 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |