#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int n;
vector<pii> P[100005];
struct segtree {
ll seg[1 << 18];
void init() {
memset(seg, 0xcf, sizeof(seg));
}
void update(int i, int s, int e, int x, int y, ll v) {
if (e < x || y < s) return;
if (x <= s && e <= y) {
seg[i] = max(seg[i], v);
return;
}
int m = (s + e) / 2;
update(i + i, s, m, x, y, v);
update(i + i + 1, m + 1, e, x, y, v);
}
ll query(int i, int s, int e, int x) {
if (s == e) return seg[i];
int m = (s + e) / 2;
if (x <= m) return max(seg[i], query(i + i, s, m, x));
return max(seg[i], query(i + i + 1, m + 1, e, x));
}
} up, dn;
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
n = N;
for (int i = 0; i < M; ++i) {
P[X[i] + 1].emplace_back(Y[i] + 1, W[i]);
}
ll p = 0;
dn.init();
for (int i = 1; i <= n; ++i) {
ll sum = 0;
sort(P[i].begin(), P[i].end());
for (auto [j, v] : P[i]) {
sum += v;
up.update(1, 0, n + 1, j + 1, n + 1, up.query(1, 0, n + 1, j) + v);
}
reverse(P[i].begin(), P[i].end());
for (auto [j, v] : P[i]) {
dn.update(1, 0, n + 1, 0, j - 1, dn.query(1, 0, n + 1, j) + v);
}
ll u = up.query(1, 0, n + 1, n + 1);
ll d = dn.query(1, 0, n + 1, 0);
up.update(1, 0, n + 1, 0, n + 1, d);
dn.update(1, 0, n + 1, 0, n + 1, p);
p = max(u, d);
}
return dn.query(1, 0, n + 1, 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
9312 KB |
Output is correct |
2 |
Correct |
76 ms |
10020 KB |
Output is correct |
3 |
Correct |
11 ms |
4820 KB |
Output is correct |
4 |
Correct |
13 ms |
4692 KB |
Output is correct |
5 |
Correct |
236 ms |
16304 KB |
Output is correct |
6 |
Correct |
287 ms |
18172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4692 KB |
Output is correct |
2 |
Correct |
122 ms |
11940 KB |
Output is correct |
3 |
Correct |
150 ms |
13188 KB |
Output is correct |
4 |
Correct |
62 ms |
9408 KB |
Output is correct |
5 |
Correct |
75 ms |
9972 KB |
Output is correct |
6 |
Correct |
2 ms |
4692 KB |
Output is correct |
7 |
Correct |
2 ms |
4692 KB |
Output is correct |
8 |
Correct |
2 ms |
4692 KB |
Output is correct |
9 |
Correct |
2 ms |
4692 KB |
Output is correct |
10 |
Correct |
11 ms |
4740 KB |
Output is correct |
11 |
Correct |
11 ms |
4692 KB |
Output is correct |
12 |
Correct |
61 ms |
9368 KB |
Output is correct |
13 |
Correct |
73 ms |
9920 KB |
Output is correct |
14 |
Correct |
78 ms |
9432 KB |
Output is correct |
15 |
Correct |
70 ms |
8820 KB |
Output is correct |
16 |
Correct |
63 ms |
9404 KB |
Output is correct |
17 |
Correct |
75 ms |
9788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4692 KB |
Output is correct |
2 |
Correct |
14 ms |
4708 KB |
Output is correct |
3 |
Correct |
43 ms |
7660 KB |
Output is correct |
4 |
Correct |
33 ms |
7112 KB |
Output is correct |
5 |
Correct |
66 ms |
10316 KB |
Output is correct |
6 |
Correct |
69 ms |
11060 KB |
Output is correct |
7 |
Correct |
68 ms |
11132 KB |
Output is correct |
8 |
Correct |
89 ms |
11136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4692 KB |
Output is correct |
2 |
Correct |
2 ms |
4692 KB |
Output is correct |
3 |
Correct |
2 ms |
4692 KB |
Output is correct |
4 |
Correct |
2 ms |
4692 KB |
Output is correct |
5 |
Correct |
2 ms |
4692 KB |
Output is correct |
6 |
Correct |
3 ms |
4712 KB |
Output is correct |
7 |
Correct |
3 ms |
4712 KB |
Output is correct |
8 |
Correct |
2 ms |
4692 KB |
Output is correct |
9 |
Correct |
2 ms |
4692 KB |
Output is correct |
10 |
Correct |
4 ms |
4852 KB |
Output is correct |
11 |
Correct |
3 ms |
4692 KB |
Output is correct |
12 |
Correct |
3 ms |
4740 KB |
Output is correct |
13 |
Correct |
3 ms |
4692 KB |
Output is correct |
14 |
Correct |
4 ms |
4692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4692 KB |
Output is correct |
2 |
Correct |
2 ms |
4692 KB |
Output is correct |
3 |
Correct |
2 ms |
4692 KB |
Output is correct |
4 |
Correct |
2 ms |
4692 KB |
Output is correct |
5 |
Correct |
2 ms |
4692 KB |
Output is correct |
6 |
Correct |
3 ms |
4712 KB |
Output is correct |
7 |
Correct |
3 ms |
4712 KB |
Output is correct |
8 |
Correct |
2 ms |
4692 KB |
Output is correct |
9 |
Correct |
2 ms |
4692 KB |
Output is correct |
10 |
Correct |
4 ms |
4852 KB |
Output is correct |
11 |
Correct |
3 ms |
4692 KB |
Output is correct |
12 |
Correct |
3 ms |
4740 KB |
Output is correct |
13 |
Correct |
3 ms |
4692 KB |
Output is correct |
14 |
Correct |
4 ms |
4692 KB |
Output is correct |
15 |
Correct |
3 ms |
4692 KB |
Output is correct |
16 |
Correct |
3 ms |
4820 KB |
Output is correct |
17 |
Correct |
23 ms |
7020 KB |
Output is correct |
18 |
Correct |
23 ms |
7252 KB |
Output is correct |
19 |
Correct |
23 ms |
7124 KB |
Output is correct |
20 |
Correct |
22 ms |
7140 KB |
Output is correct |
21 |
Correct |
28 ms |
7208 KB |
Output is correct |
22 |
Correct |
43 ms |
9064 KB |
Output is correct |
23 |
Correct |
7 ms |
5184 KB |
Output is correct |
24 |
Correct |
17 ms |
6228 KB |
Output is correct |
25 |
Correct |
3 ms |
4692 KB |
Output is correct |
26 |
Correct |
7 ms |
5108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4692 KB |
Output is correct |
2 |
Correct |
2 ms |
4692 KB |
Output is correct |
3 |
Correct |
2 ms |
4692 KB |
Output is correct |
4 |
Correct |
2 ms |
4692 KB |
Output is correct |
5 |
Correct |
2 ms |
4692 KB |
Output is correct |
6 |
Correct |
3 ms |
4712 KB |
Output is correct |
7 |
Correct |
3 ms |
4712 KB |
Output is correct |
8 |
Correct |
2 ms |
4692 KB |
Output is correct |
9 |
Correct |
2 ms |
4692 KB |
Output is correct |
10 |
Correct |
4 ms |
4852 KB |
Output is correct |
11 |
Correct |
3 ms |
4692 KB |
Output is correct |
12 |
Correct |
3 ms |
4740 KB |
Output is correct |
13 |
Correct |
3 ms |
4692 KB |
Output is correct |
14 |
Correct |
4 ms |
4692 KB |
Output is correct |
15 |
Correct |
3 ms |
4692 KB |
Output is correct |
16 |
Correct |
3 ms |
4820 KB |
Output is correct |
17 |
Correct |
23 ms |
7020 KB |
Output is correct |
18 |
Correct |
23 ms |
7252 KB |
Output is correct |
19 |
Correct |
23 ms |
7124 KB |
Output is correct |
20 |
Correct |
22 ms |
7140 KB |
Output is correct |
21 |
Correct |
28 ms |
7208 KB |
Output is correct |
22 |
Correct |
43 ms |
9064 KB |
Output is correct |
23 |
Correct |
7 ms |
5184 KB |
Output is correct |
24 |
Correct |
17 ms |
6228 KB |
Output is correct |
25 |
Correct |
3 ms |
4692 KB |
Output is correct |
26 |
Correct |
7 ms |
5108 KB |
Output is correct |
27 |
Correct |
4 ms |
4948 KB |
Output is correct |
28 |
Correct |
112 ms |
13744 KB |
Output is correct |
29 |
Correct |
184 ms |
16460 KB |
Output is correct |
30 |
Correct |
187 ms |
16064 KB |
Output is correct |
31 |
Correct |
180 ms |
15920 KB |
Output is correct |
32 |
Correct |
174 ms |
17440 KB |
Output is correct |
33 |
Correct |
190 ms |
15956 KB |
Output is correct |
34 |
Correct |
192 ms |
15864 KB |
Output is correct |
35 |
Correct |
67 ms |
9744 KB |
Output is correct |
36 |
Correct |
185 ms |
16860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4692 KB |
Output is correct |
2 |
Correct |
14 ms |
4708 KB |
Output is correct |
3 |
Correct |
43 ms |
7660 KB |
Output is correct |
4 |
Correct |
33 ms |
7112 KB |
Output is correct |
5 |
Correct |
66 ms |
10316 KB |
Output is correct |
6 |
Correct |
69 ms |
11060 KB |
Output is correct |
7 |
Correct |
68 ms |
11132 KB |
Output is correct |
8 |
Correct |
89 ms |
11136 KB |
Output is correct |
9 |
Correct |
87 ms |
13092 KB |
Output is correct |
10 |
Correct |
77 ms |
9468 KB |
Output is correct |
11 |
Correct |
126 ms |
13276 KB |
Output is correct |
12 |
Correct |
2 ms |
4692 KB |
Output is correct |
13 |
Correct |
2 ms |
4692 KB |
Output is correct |
14 |
Correct |
2 ms |
4692 KB |
Output is correct |
15 |
Correct |
2 ms |
4692 KB |
Output is correct |
16 |
Correct |
2 ms |
4692 KB |
Output is correct |
17 |
Correct |
2 ms |
4692 KB |
Output is correct |
18 |
Correct |
10 ms |
4692 KB |
Output is correct |
19 |
Correct |
10 ms |
4712 KB |
Output is correct |
20 |
Correct |
9 ms |
4692 KB |
Output is correct |
21 |
Correct |
10 ms |
4708 KB |
Output is correct |
22 |
Correct |
123 ms |
11396 KB |
Output is correct |
23 |
Correct |
135 ms |
12884 KB |
Output is correct |
24 |
Correct |
144 ms |
13444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
9312 KB |
Output is correct |
2 |
Correct |
76 ms |
10020 KB |
Output is correct |
3 |
Correct |
11 ms |
4820 KB |
Output is correct |
4 |
Correct |
13 ms |
4692 KB |
Output is correct |
5 |
Correct |
236 ms |
16304 KB |
Output is correct |
6 |
Correct |
287 ms |
18172 KB |
Output is correct |
7 |
Correct |
3 ms |
4692 KB |
Output is correct |
8 |
Correct |
122 ms |
11940 KB |
Output is correct |
9 |
Correct |
150 ms |
13188 KB |
Output is correct |
10 |
Correct |
62 ms |
9408 KB |
Output is correct |
11 |
Correct |
75 ms |
9972 KB |
Output is correct |
12 |
Correct |
2 ms |
4692 KB |
Output is correct |
13 |
Correct |
2 ms |
4692 KB |
Output is correct |
14 |
Correct |
2 ms |
4692 KB |
Output is correct |
15 |
Correct |
2 ms |
4692 KB |
Output is correct |
16 |
Correct |
11 ms |
4740 KB |
Output is correct |
17 |
Correct |
11 ms |
4692 KB |
Output is correct |
18 |
Correct |
61 ms |
9368 KB |
Output is correct |
19 |
Correct |
73 ms |
9920 KB |
Output is correct |
20 |
Correct |
78 ms |
9432 KB |
Output is correct |
21 |
Correct |
70 ms |
8820 KB |
Output is correct |
22 |
Correct |
63 ms |
9404 KB |
Output is correct |
23 |
Correct |
75 ms |
9788 KB |
Output is correct |
24 |
Correct |
10 ms |
4692 KB |
Output is correct |
25 |
Correct |
14 ms |
4708 KB |
Output is correct |
26 |
Correct |
43 ms |
7660 KB |
Output is correct |
27 |
Correct |
33 ms |
7112 KB |
Output is correct |
28 |
Correct |
66 ms |
10316 KB |
Output is correct |
29 |
Correct |
69 ms |
11060 KB |
Output is correct |
30 |
Correct |
68 ms |
11132 KB |
Output is correct |
31 |
Correct |
89 ms |
11136 KB |
Output is correct |
32 |
Correct |
2 ms |
4692 KB |
Output is correct |
33 |
Correct |
2 ms |
4692 KB |
Output is correct |
34 |
Correct |
2 ms |
4692 KB |
Output is correct |
35 |
Correct |
2 ms |
4692 KB |
Output is correct |
36 |
Correct |
2 ms |
4692 KB |
Output is correct |
37 |
Correct |
3 ms |
4712 KB |
Output is correct |
38 |
Correct |
3 ms |
4712 KB |
Output is correct |
39 |
Correct |
2 ms |
4692 KB |
Output is correct |
40 |
Correct |
2 ms |
4692 KB |
Output is correct |
41 |
Correct |
4 ms |
4852 KB |
Output is correct |
42 |
Correct |
3 ms |
4692 KB |
Output is correct |
43 |
Correct |
3 ms |
4740 KB |
Output is correct |
44 |
Correct |
3 ms |
4692 KB |
Output is correct |
45 |
Correct |
4 ms |
4692 KB |
Output is correct |
46 |
Correct |
3 ms |
4692 KB |
Output is correct |
47 |
Correct |
3 ms |
4820 KB |
Output is correct |
48 |
Correct |
23 ms |
7020 KB |
Output is correct |
49 |
Correct |
23 ms |
7252 KB |
Output is correct |
50 |
Correct |
23 ms |
7124 KB |
Output is correct |
51 |
Correct |
22 ms |
7140 KB |
Output is correct |
52 |
Correct |
28 ms |
7208 KB |
Output is correct |
53 |
Correct |
43 ms |
9064 KB |
Output is correct |
54 |
Correct |
7 ms |
5184 KB |
Output is correct |
55 |
Correct |
17 ms |
6228 KB |
Output is correct |
56 |
Correct |
3 ms |
4692 KB |
Output is correct |
57 |
Correct |
7 ms |
5108 KB |
Output is correct |
58 |
Correct |
4 ms |
4948 KB |
Output is correct |
59 |
Correct |
112 ms |
13744 KB |
Output is correct |
60 |
Correct |
184 ms |
16460 KB |
Output is correct |
61 |
Correct |
187 ms |
16064 KB |
Output is correct |
62 |
Correct |
180 ms |
15920 KB |
Output is correct |
63 |
Correct |
174 ms |
17440 KB |
Output is correct |
64 |
Correct |
190 ms |
15956 KB |
Output is correct |
65 |
Correct |
192 ms |
15864 KB |
Output is correct |
66 |
Correct |
67 ms |
9744 KB |
Output is correct |
67 |
Correct |
185 ms |
16860 KB |
Output is correct |
68 |
Correct |
87 ms |
13092 KB |
Output is correct |
69 |
Correct |
77 ms |
9468 KB |
Output is correct |
70 |
Correct |
126 ms |
13276 KB |
Output is correct |
71 |
Correct |
2 ms |
4692 KB |
Output is correct |
72 |
Correct |
2 ms |
4692 KB |
Output is correct |
73 |
Correct |
2 ms |
4692 KB |
Output is correct |
74 |
Correct |
2 ms |
4692 KB |
Output is correct |
75 |
Correct |
2 ms |
4692 KB |
Output is correct |
76 |
Correct |
2 ms |
4692 KB |
Output is correct |
77 |
Correct |
10 ms |
4692 KB |
Output is correct |
78 |
Correct |
10 ms |
4712 KB |
Output is correct |
79 |
Correct |
9 ms |
4692 KB |
Output is correct |
80 |
Correct |
10 ms |
4708 KB |
Output is correct |
81 |
Correct |
123 ms |
11396 KB |
Output is correct |
82 |
Correct |
135 ms |
12884 KB |
Output is correct |
83 |
Correct |
144 ms |
13444 KB |
Output is correct |
84 |
Correct |
236 ms |
17584 KB |
Output is correct |
85 |
Correct |
221 ms |
17408 KB |
Output is correct |
86 |
Correct |
297 ms |
19316 KB |
Output is correct |
87 |
Correct |
285 ms |
19132 KB |
Output is correct |
88 |
Correct |
3 ms |
4692 KB |
Output is correct |
89 |
Correct |
342 ms |
19380 KB |
Output is correct |
90 |
Correct |
193 ms |
16600 KB |
Output is correct |
91 |
Correct |
199 ms |
16248 KB |
Output is correct |