#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
// want O(C + n(log))
const int SIZE = 1.5e5 + 5;
int n, ans = -1;
array<int, 3> a[SIZE];
struct LIS {
vector<int> lis;
void add(int x) {
lis.pb(x);
}
void work() {
sort(lis.begin(), lis.end());
lis.erase(unique(lis.begin(), lis.end()), lis.end());
}
int id(int x) {
return lower_bound(lis.begin(), lis.end(), x) - lis.begin() + 1;
}
};
LIS lx, ly;
int bit[4005][4005];
void upd(int px, int py, int x) {
for (; px <= n; px += px & -px) {
for (int pos = py; pos <= n; pos += pos & -pos) {
bit[px][pos] = max(bit[px][pos], x);
}
}
}
int que(int px, int py) {
int re = 0;
for (; px; px -= px & -px) {
for (int pos = py; pos; pos -= pos & -pos) {
re = max(re, bit[px][pos]);
}
}
return re;
}
void small() {
FOR (i, 1, n) lx.add(a[i][0]), ly.add(a[i][1]);
lx.work(), ly.work();
FOR (i, 1, n) {
FOR (j, i + 1, n) if (a[j][0] > a[i][0] && a[i][1] > a[j][1]) {
int val = que(lx.id(a[j][0]) - 1, ly.id(a[i][1]) - 1);
if (val > max(a[i][2], a[j][2])) ans = max(ans, a[j][0] + a[i][1] + val);
}
upd(lx.id(a[i][0]), ly.id(a[i][1]), a[i][2]);
}
lx.lis.clear(), ly.lis.clear();
FOR (i, 1, n) {
swap(a[i][1], a[i][2]);
fill(bit[i], bit[i] + n + 1, 0);
}
FOR (i, 1, n) lx.add(a[i][0]), ly.add(a[i][1]);
lx.work(), ly.work();
FOR (i, 1, n) {
FOR (j, i + 1, n) if (a[j][0] > a[i][0] && a[i][1] > a[j][1]) {
int val = que(lx.id(a[j][0]) - 1, ly.id(a[i][1]) - 1);
if (val > max(a[i][2], a[j][2])) ans = max(ans, a[j][0] + a[i][1] + val);
}
upd(lx.id(a[i][0]), ly.id(a[i][1]), a[i][2]);
}
cout << ans << '\n';
}
int mnx[4005][4005], mny[4005][4005], dp[4005][4005];
int mx, my;
void C_small() {
FOR (i, 1, n) {
mx = max(mx, a[i][0]);
my = max(my, a[i][1]);
}
FOR (i, 0, mx) FOR (j, 0, my) mnx[i][j] = mny[i][j] = INT_MAX;
FOR (i, 1, n) {
mnx[a[i][0]][a[i][1]] = min(mnx[a[i][0]][a[i][1]], a[i][2]);
mny[a[i][0]][a[i][1]] = min(mny[a[i][0]][a[i][1]], a[i][2]);
dp[a[i][0]][a[i][1]] = max(dp[a[i][0]][a[i][1]], a[i][2]);
}
FOR (i, 0, mx) FOR (j, 0, my) {
if (i) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
mny[i][j] = min(mny[i][j], mny[i - 1][j]);
}
if (j) {
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
mnx[i][j] = min(mnx[i][j], mnx[i][j - 1]);
}
}
// X2<X1, Y1<Y2
FOR (X1, 1, mx) FOR (Y2, 1, my) {
int val = dp[X1 - 1][Y2 - 1];
if (val > max(mnx[X1][Y2 - 1], mny[X1 - 1][Y2])) ans = max(ans, X1 + Y2 + val);
}
cout << ans << '\n';
}
void solve() {
cin >> n;
FOR (i, 1, n) FOR (j, 0, 2) cin >> a[i][j];
sort(a + 1, a + n + 1);
if (n <= 4000) {
small();
return;
}
C_small();
}
int main() {
Waimai;
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 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 |
0 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 |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
8 ms |
1900 KB |
Output is correct |
15 |
Correct |
2 ms |
1492 KB |
Output is correct |
16 |
Correct |
3 ms |
1620 KB |
Output is correct |
17 |
Correct |
3 ms |
1876 KB |
Output is correct |
18 |
Correct |
4 ms |
1748 KB |
Output is correct |
19 |
Correct |
3 ms |
1876 KB |
Output is correct |
20 |
Correct |
2 ms |
1876 KB |
Output is correct |
21 |
Correct |
2 ms |
1748 KB |
Output is correct |
22 |
Correct |
2 ms |
1748 KB |
Output is correct |
23 |
Correct |
1 ms |
1876 KB |
Output is correct |
24 |
Correct |
1 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 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 |
0 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 |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
8 ms |
1900 KB |
Output is correct |
15 |
Correct |
2 ms |
1492 KB |
Output is correct |
16 |
Correct |
3 ms |
1620 KB |
Output is correct |
17 |
Correct |
3 ms |
1876 KB |
Output is correct |
18 |
Correct |
4 ms |
1748 KB |
Output is correct |
19 |
Correct |
3 ms |
1876 KB |
Output is correct |
20 |
Correct |
2 ms |
1876 KB |
Output is correct |
21 |
Correct |
2 ms |
1748 KB |
Output is correct |
22 |
Correct |
2 ms |
1748 KB |
Output is correct |
23 |
Correct |
1 ms |
1876 KB |
Output is correct |
24 |
Correct |
1 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
1434 ms |
63144 KB |
Output is correct |
27 |
Correct |
877 ms |
62720 KB |
Output is correct |
28 |
Correct |
722 ms |
63052 KB |
Output is correct |
29 |
Correct |
451 ms |
62860 KB |
Output is correct |
30 |
Correct |
307 ms |
38940 KB |
Output is correct |
31 |
Correct |
613 ms |
63240 KB |
Output is correct |
32 |
Correct |
381 ms |
63036 KB |
Output is correct |
33 |
Correct |
121 ms |
60412 KB |
Output is correct |
34 |
Correct |
42 ms |
62996 KB |
Output is correct |
35 |
Correct |
4 ms |
7124 KB |
Output is correct |
36 |
Correct |
5 ms |
7124 KB |
Output is correct |
37 |
Correct |
38 ms |
63060 KB |
Output is correct |
38 |
Correct |
43 ms |
63056 KB |
Output is correct |
39 |
Correct |
56 ms |
24048 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 |
0 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 |
36 ms |
2144 KB |
Output is correct |
12 |
Correct |
23 ms |
1512 KB |
Output is correct |
13 |
Correct |
26 ms |
1748 KB |
Output is correct |
14 |
Correct |
40 ms |
2148 KB |
Output is correct |
15 |
Correct |
34 ms |
2092 KB |
Output is correct |
16 |
Correct |
30 ms |
1996 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 |
0 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 |
36 ms |
2144 KB |
Output is correct |
12 |
Correct |
23 ms |
1512 KB |
Output is correct |
13 |
Correct |
26 ms |
1748 KB |
Output is correct |
14 |
Correct |
40 ms |
2148 KB |
Output is correct |
15 |
Correct |
34 ms |
2092 KB |
Output is correct |
16 |
Correct |
30 ms |
1996 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
1876 KB |
Output is correct |
21 |
Correct |
51 ms |
24044 KB |
Output is correct |
22 |
Correct |
44 ms |
2324 KB |
Output is correct |
23 |
Correct |
40 ms |
2172 KB |
Output is correct |
24 |
Correct |
30 ms |
1716 KB |
Output is correct |
25 |
Correct |
45 ms |
2328 KB |
Output is correct |
26 |
Correct |
43 ms |
2044 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 |
0 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 |
36 ms |
2144 KB |
Output is correct |
12 |
Correct |
23 ms |
1512 KB |
Output is correct |
13 |
Correct |
26 ms |
1748 KB |
Output is correct |
14 |
Correct |
40 ms |
2148 KB |
Output is correct |
15 |
Correct |
34 ms |
2092 KB |
Output is correct |
16 |
Correct |
30 ms |
1996 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
1876 KB |
Output is correct |
21 |
Correct |
51 ms |
24044 KB |
Output is correct |
22 |
Correct |
44 ms |
2324 KB |
Output is correct |
23 |
Correct |
40 ms |
2172 KB |
Output is correct |
24 |
Correct |
30 ms |
1716 KB |
Output is correct |
25 |
Correct |
45 ms |
2328 KB |
Output is correct |
26 |
Correct |
43 ms |
2044 KB |
Output is correct |
27 |
Correct |
4 ms |
1748 KB |
Output is correct |
28 |
Correct |
4 ms |
1876 KB |
Output is correct |
29 |
Correct |
2 ms |
1876 KB |
Output is correct |
30 |
Correct |
2 ms |
1876 KB |
Output is correct |
31 |
Correct |
399 ms |
63036 KB |
Output is correct |
32 |
Correct |
6 ms |
7124 KB |
Output is correct |
33 |
Correct |
7 ms |
7136 KB |
Output is correct |
34 |
Correct |
49 ms |
6604 KB |
Output is correct |
35 |
Correct |
50 ms |
6452 KB |
Output is correct |
36 |
Correct |
65 ms |
6572 KB |
Output is correct |
37 |
Correct |
54 ms |
6672 KB |
Output is correct |
38 |
Correct |
43 ms |
6272 KB |
Output is correct |
39 |
Correct |
34 ms |
6076 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 |
0 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 |
36 ms |
2144 KB |
Output is correct |
12 |
Correct |
23 ms |
1512 KB |
Output is correct |
13 |
Correct |
26 ms |
1748 KB |
Output is correct |
14 |
Correct |
40 ms |
2148 KB |
Output is correct |
15 |
Correct |
34 ms |
2092 KB |
Output is correct |
16 |
Correct |
30 ms |
1996 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
1876 KB |
Output is correct |
21 |
Correct |
51 ms |
24044 KB |
Output is correct |
22 |
Correct |
44 ms |
2324 KB |
Output is correct |
23 |
Correct |
40 ms |
2172 KB |
Output is correct |
24 |
Correct |
30 ms |
1716 KB |
Output is correct |
25 |
Correct |
45 ms |
2328 KB |
Output is correct |
26 |
Correct |
43 ms |
2044 KB |
Output is correct |
27 |
Correct |
4 ms |
1748 KB |
Output is correct |
28 |
Correct |
4 ms |
1876 KB |
Output is correct |
29 |
Correct |
2 ms |
1876 KB |
Output is correct |
30 |
Correct |
2 ms |
1876 KB |
Output is correct |
31 |
Correct |
399 ms |
63036 KB |
Output is correct |
32 |
Correct |
6 ms |
7124 KB |
Output is correct |
33 |
Correct |
7 ms |
7136 KB |
Output is correct |
34 |
Correct |
49 ms |
6604 KB |
Output is correct |
35 |
Correct |
50 ms |
6452 KB |
Output is correct |
36 |
Correct |
65 ms |
6572 KB |
Output is correct |
37 |
Correct |
54 ms |
6672 KB |
Output is correct |
38 |
Correct |
43 ms |
6272 KB |
Output is correct |
39 |
Correct |
34 ms |
6076 KB |
Output is correct |
40 |
Correct |
313 ms |
38996 KB |
Output is correct |
41 |
Correct |
609 ms |
63212 KB |
Output is correct |
42 |
Correct |
44 ms |
63056 KB |
Output is correct |
43 |
Correct |
44 ms |
63104 KB |
Output is correct |
44 |
Correct |
256 ms |
190116 KB |
Output is correct |
45 |
Correct |
236 ms |
174820 KB |
Output is correct |
46 |
Correct |
255 ms |
191828 KB |
Output is correct |
47 |
Correct |
258 ms |
192388 KB |
Output is correct |
48 |
Correct |
84 ms |
29848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 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 |
0 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 |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
8 ms |
1900 KB |
Output is correct |
15 |
Correct |
2 ms |
1492 KB |
Output is correct |
16 |
Correct |
3 ms |
1620 KB |
Output is correct |
17 |
Correct |
3 ms |
1876 KB |
Output is correct |
18 |
Correct |
4 ms |
1748 KB |
Output is correct |
19 |
Correct |
3 ms |
1876 KB |
Output is correct |
20 |
Correct |
2 ms |
1876 KB |
Output is correct |
21 |
Correct |
2 ms |
1748 KB |
Output is correct |
22 |
Correct |
2 ms |
1748 KB |
Output is correct |
23 |
Correct |
1 ms |
1876 KB |
Output is correct |
24 |
Correct |
1 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
1434 ms |
63144 KB |
Output is correct |
27 |
Correct |
877 ms |
62720 KB |
Output is correct |
28 |
Correct |
722 ms |
63052 KB |
Output is correct |
29 |
Correct |
451 ms |
62860 KB |
Output is correct |
30 |
Correct |
307 ms |
38940 KB |
Output is correct |
31 |
Correct |
613 ms |
63240 KB |
Output is correct |
32 |
Correct |
381 ms |
63036 KB |
Output is correct |
33 |
Correct |
121 ms |
60412 KB |
Output is correct |
34 |
Correct |
42 ms |
62996 KB |
Output is correct |
35 |
Correct |
4 ms |
7124 KB |
Output is correct |
36 |
Correct |
5 ms |
7124 KB |
Output is correct |
37 |
Correct |
38 ms |
63060 KB |
Output is correct |
38 |
Correct |
43 ms |
63056 KB |
Output is correct |
39 |
Correct |
56 ms |
24048 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
340 KB |
Output is correct |
45 |
Correct |
0 ms |
340 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
0 ms |
340 KB |
Output is correct |
50 |
Correct |
36 ms |
2144 KB |
Output is correct |
51 |
Correct |
23 ms |
1512 KB |
Output is correct |
52 |
Correct |
26 ms |
1748 KB |
Output is correct |
53 |
Correct |
40 ms |
2148 KB |
Output is correct |
54 |
Correct |
34 ms |
2092 KB |
Output is correct |
55 |
Correct |
30 ms |
1996 KB |
Output is correct |
56 |
Correct |
0 ms |
340 KB |
Output is correct |
57 |
Correct |
0 ms |
340 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
2 ms |
1876 KB |
Output is correct |
60 |
Correct |
51 ms |
24044 KB |
Output is correct |
61 |
Correct |
44 ms |
2324 KB |
Output is correct |
62 |
Correct |
40 ms |
2172 KB |
Output is correct |
63 |
Correct |
30 ms |
1716 KB |
Output is correct |
64 |
Correct |
45 ms |
2328 KB |
Output is correct |
65 |
Correct |
43 ms |
2044 KB |
Output is correct |
66 |
Correct |
4 ms |
1748 KB |
Output is correct |
67 |
Correct |
4 ms |
1876 KB |
Output is correct |
68 |
Correct |
2 ms |
1876 KB |
Output is correct |
69 |
Correct |
2 ms |
1876 KB |
Output is correct |
70 |
Correct |
399 ms |
63036 KB |
Output is correct |
71 |
Correct |
6 ms |
7124 KB |
Output is correct |
72 |
Correct |
7 ms |
7136 KB |
Output is correct |
73 |
Correct |
49 ms |
6604 KB |
Output is correct |
74 |
Correct |
50 ms |
6452 KB |
Output is correct |
75 |
Correct |
65 ms |
6572 KB |
Output is correct |
76 |
Correct |
54 ms |
6672 KB |
Output is correct |
77 |
Correct |
43 ms |
6272 KB |
Output is correct |
78 |
Correct |
34 ms |
6076 KB |
Output is correct |
79 |
Correct |
313 ms |
38996 KB |
Output is correct |
80 |
Correct |
609 ms |
63212 KB |
Output is correct |
81 |
Correct |
44 ms |
63056 KB |
Output is correct |
82 |
Correct |
44 ms |
63104 KB |
Output is correct |
83 |
Correct |
256 ms |
190116 KB |
Output is correct |
84 |
Correct |
236 ms |
174820 KB |
Output is correct |
85 |
Correct |
255 ms |
191828 KB |
Output is correct |
86 |
Correct |
258 ms |
192388 KB |
Output is correct |
87 |
Correct |
84 ms |
29848 KB |
Output is correct |
88 |
Runtime error |
317 ms |
389732 KB |
Execution killed with signal 11 |
89 |
Halted |
0 ms |
0 KB |
- |