#include <bits/stdc++.h>
#define mp make_pair
#define all(a) a.begin(),a.end()
using namespace std;
using pii = pair <long long, long long>;
constexpr int maxn = 1e5 + 10;
constexpr long long inf = 1e17 + 10;
vector <pii> tree (maxn << 2, mp (0, -inf));
vector <pii> A (maxn << 2, mp (-inf, -inf));
inline void push (int v, int t_l, int t_r) {
tree[v].first = max (tree[v].first, A[v].first);
tree[v].second = max (tree[v].second, A[v].second);
if (t_l != t_r) {
A[v << 1].first = max (A[v << 1].first, A[v].first);
A[v << 1].second = max (A[v << 1].second, A[v].second);
A[v << 1 | 1].first = max (A[v << 1 | 1].first, A[v].first);
A[v << 1 | 1].second = max (A[v << 1 | 1].second, A[v].second);
}
A[v] = mp (-inf, -inf);
}
inline void update (int l, int r, pii x, int v, int t_l, int t_r) {
push (v, t_l, t_r);
if (l > t_r || t_l > r) return;
if (l <= t_l && t_r <= r) {
A[v] = x;
push (v, t_l, t_r);
return;
}
int t_m = t_l + t_r >> 1;
update (l, r, x, v << 1, t_l, t_m);
update (l, r, x, v << 1 | 1, t_m + 1, t_r);
tree[v].first = max (tree[v << 1].first, tree[v << 1 | 1].first);
tree[v].second = max (tree[v << 1].second, tree[v << 1 | 1].second);
}
inline pii get (int i, int v, int t_l, int t_r) {
if (i > t_r || t_l > i) return mp (-inf, -inf);
push (v, t_l, t_r);
if (t_l == t_r) return tree[v];
int t_m = t_l + t_r >> 1;
return max (get (i, v << 1, t_l, t_m), get (i, v << 1 | 1, t_m + 1, t_r));
}
vector <pii> pos [maxn];
long long last = 0;
long long max_weights (int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
for (int i = 0; i < M; ++i) {
pos[X[i] + 1].push_back (mp (Y[i] + 1, W[i]));
}
int n = N;
for (int i = 1; i <= n; ++i) sort (all (pos[i]));
for (int i = 1; i <= n; ++i) {
for (pii j : pos[i]) {
long long am = get (j.first, 1, 0, n + 1).first + j.second;
update (j.first + 1, n + 1, mp (am, -inf), 1, 0, n + 1);
}
for (int _j = (int) pos[i].size () - 1; _j >= 0; --_j) {
pii j = pos[i][_j];
long long am = get (j.first, 1, 0, n + 1).second + j.second;
update (0, j.first - 1, mp (-inf, am), 1, 0, n + 1);
}
long long to = get (n + 1, 1, 0, n + 1).first, from = get (0, 1, 0, n + 1).second;
update (0, n + 1, mp (from, last), 1, 0, n + 1);
last = max (to, from);
}
return get (0, 1, 0, n + 1).second;
}
Compilation message
fish.cpp: In function 'void update(int, int, pii, int, int, int)':
fish.cpp:32:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int t_m = t_l + t_r >> 1;
| ~~~~^~~~~
fish.cpp: In function 'pii get(int, int, int, int)':
fish.cpp:43:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | int t_m = t_l + t_r >> 1;
| ~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
19188 KB |
Output is correct |
2 |
Correct |
222 ms |
20200 KB |
Output is correct |
3 |
Correct |
53 ms |
15176 KB |
Output is correct |
4 |
Correct |
52 ms |
15164 KB |
Output is correct |
5 |
Correct |
549 ms |
28220 KB |
Output is correct |
6 |
Correct |
669 ms |
30712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15188 KB |
Output is correct |
2 |
Correct |
293 ms |
22136 KB |
Output is correct |
3 |
Correct |
395 ms |
23768 KB |
Output is correct |
4 |
Correct |
176 ms |
19648 KB |
Output is correct |
5 |
Correct |
212 ms |
20196 KB |
Output is correct |
6 |
Correct |
7 ms |
15188 KB |
Output is correct |
7 |
Correct |
7 ms |
15188 KB |
Output is correct |
8 |
Correct |
7 ms |
15184 KB |
Output is correct |
9 |
Correct |
7 ms |
15188 KB |
Output is correct |
10 |
Correct |
53 ms |
15168 KB |
Output is correct |
11 |
Correct |
51 ms |
15188 KB |
Output is correct |
12 |
Correct |
175 ms |
20056 KB |
Output is correct |
13 |
Correct |
211 ms |
20396 KB |
Output is correct |
14 |
Correct |
189 ms |
19512 KB |
Output is correct |
15 |
Correct |
206 ms |
19764 KB |
Output is correct |
16 |
Correct |
175 ms |
19520 KB |
Output is correct |
17 |
Correct |
197 ms |
19736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
15432 KB |
Output is correct |
2 |
Correct |
49 ms |
15172 KB |
Output is correct |
3 |
Correct |
154 ms |
18124 KB |
Output is correct |
4 |
Correct |
113 ms |
17156 KB |
Output is correct |
5 |
Correct |
247 ms |
20652 KB |
Output is correct |
6 |
Correct |
229 ms |
20592 KB |
Output is correct |
7 |
Correct |
249 ms |
20652 KB |
Output is correct |
8 |
Correct |
251 ms |
20652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
15060 KB |
Output is correct |
2 |
Correct |
7 ms |
15164 KB |
Output is correct |
3 |
Correct |
8 ms |
15188 KB |
Output is correct |
4 |
Correct |
9 ms |
15160 KB |
Output is correct |
5 |
Correct |
9 ms |
15188 KB |
Output is correct |
6 |
Correct |
9 ms |
15188 KB |
Output is correct |
7 |
Correct |
8 ms |
15188 KB |
Output is correct |
8 |
Correct |
7 ms |
15124 KB |
Output is correct |
9 |
Correct |
8 ms |
15208 KB |
Output is correct |
10 |
Correct |
11 ms |
15188 KB |
Output is correct |
11 |
Correct |
8 ms |
15188 KB |
Output is correct |
12 |
Correct |
12 ms |
15188 KB |
Output is correct |
13 |
Correct |
10 ms |
15188 KB |
Output is correct |
14 |
Correct |
9 ms |
15188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
15060 KB |
Output is correct |
2 |
Correct |
7 ms |
15164 KB |
Output is correct |
3 |
Correct |
8 ms |
15188 KB |
Output is correct |
4 |
Correct |
9 ms |
15160 KB |
Output is correct |
5 |
Correct |
9 ms |
15188 KB |
Output is correct |
6 |
Correct |
9 ms |
15188 KB |
Output is correct |
7 |
Correct |
8 ms |
15188 KB |
Output is correct |
8 |
Correct |
7 ms |
15124 KB |
Output is correct |
9 |
Correct |
8 ms |
15208 KB |
Output is correct |
10 |
Correct |
11 ms |
15188 KB |
Output is correct |
11 |
Correct |
8 ms |
15188 KB |
Output is correct |
12 |
Correct |
12 ms |
15188 KB |
Output is correct |
13 |
Correct |
10 ms |
15188 KB |
Output is correct |
14 |
Correct |
9 ms |
15188 KB |
Output is correct |
15 |
Correct |
8 ms |
15104 KB |
Output is correct |
16 |
Correct |
9 ms |
15212 KB |
Output is correct |
17 |
Correct |
51 ms |
17132 KB |
Output is correct |
18 |
Correct |
50 ms |
17760 KB |
Output is correct |
19 |
Correct |
47 ms |
17512 KB |
Output is correct |
20 |
Correct |
47 ms |
17508 KB |
Output is correct |
21 |
Correct |
48 ms |
17504 KB |
Output is correct |
22 |
Correct |
97 ms |
20044 KB |
Output is correct |
23 |
Correct |
17 ms |
15720 KB |
Output is correct |
24 |
Correct |
48 ms |
17064 KB |
Output is correct |
25 |
Correct |
9 ms |
15176 KB |
Output is correct |
26 |
Correct |
18 ms |
15688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
15060 KB |
Output is correct |
2 |
Correct |
7 ms |
15164 KB |
Output is correct |
3 |
Correct |
8 ms |
15188 KB |
Output is correct |
4 |
Correct |
9 ms |
15160 KB |
Output is correct |
5 |
Correct |
9 ms |
15188 KB |
Output is correct |
6 |
Correct |
9 ms |
15188 KB |
Output is correct |
7 |
Correct |
8 ms |
15188 KB |
Output is correct |
8 |
Correct |
7 ms |
15124 KB |
Output is correct |
9 |
Correct |
8 ms |
15208 KB |
Output is correct |
10 |
Correct |
11 ms |
15188 KB |
Output is correct |
11 |
Correct |
8 ms |
15188 KB |
Output is correct |
12 |
Correct |
12 ms |
15188 KB |
Output is correct |
13 |
Correct |
10 ms |
15188 KB |
Output is correct |
14 |
Correct |
9 ms |
15188 KB |
Output is correct |
15 |
Correct |
8 ms |
15104 KB |
Output is correct |
16 |
Correct |
9 ms |
15212 KB |
Output is correct |
17 |
Correct |
51 ms |
17132 KB |
Output is correct |
18 |
Correct |
50 ms |
17760 KB |
Output is correct |
19 |
Correct |
47 ms |
17512 KB |
Output is correct |
20 |
Correct |
47 ms |
17508 KB |
Output is correct |
21 |
Correct |
48 ms |
17504 KB |
Output is correct |
22 |
Correct |
97 ms |
20044 KB |
Output is correct |
23 |
Correct |
17 ms |
15720 KB |
Output is correct |
24 |
Correct |
48 ms |
17064 KB |
Output is correct |
25 |
Correct |
9 ms |
15176 KB |
Output is correct |
26 |
Correct |
18 ms |
15688 KB |
Output is correct |
27 |
Correct |
14 ms |
15368 KB |
Output is correct |
28 |
Correct |
242 ms |
26900 KB |
Output is correct |
29 |
Correct |
377 ms |
30116 KB |
Output is correct |
30 |
Correct |
420 ms |
29656 KB |
Output is correct |
31 |
Correct |
393 ms |
29688 KB |
Output is correct |
32 |
Correct |
304 ms |
31744 KB |
Output is correct |
33 |
Correct |
399 ms |
29668 KB |
Output is correct |
34 |
Correct |
390 ms |
29652 KB |
Output is correct |
35 |
Correct |
148 ms |
21788 KB |
Output is correct |
36 |
Correct |
399 ms |
31584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
15432 KB |
Output is correct |
2 |
Correct |
49 ms |
15172 KB |
Output is correct |
3 |
Correct |
154 ms |
18124 KB |
Output is correct |
4 |
Correct |
113 ms |
17156 KB |
Output is correct |
5 |
Correct |
247 ms |
20652 KB |
Output is correct |
6 |
Correct |
229 ms |
20592 KB |
Output is correct |
7 |
Correct |
249 ms |
20652 KB |
Output is correct |
8 |
Correct |
251 ms |
20652 KB |
Output is correct |
9 |
Correct |
223 ms |
20652 KB |
Output is correct |
10 |
Correct |
238 ms |
20044 KB |
Output is correct |
11 |
Correct |
412 ms |
25064 KB |
Output is correct |
12 |
Correct |
7 ms |
15188 KB |
Output is correct |
13 |
Correct |
7 ms |
15132 KB |
Output is correct |
14 |
Correct |
8 ms |
15164 KB |
Output is correct |
15 |
Correct |
7 ms |
15116 KB |
Output is correct |
16 |
Correct |
7 ms |
15188 KB |
Output is correct |
17 |
Correct |
7 ms |
15060 KB |
Output is correct |
18 |
Correct |
58 ms |
15060 KB |
Output is correct |
19 |
Correct |
58 ms |
15168 KB |
Output is correct |
20 |
Correct |
52 ms |
15188 KB |
Output is correct |
21 |
Correct |
55 ms |
15176 KB |
Output is correct |
22 |
Correct |
238 ms |
20464 KB |
Output is correct |
23 |
Correct |
442 ms |
25416 KB |
Output is correct |
24 |
Correct |
383 ms |
25612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
19188 KB |
Output is correct |
2 |
Correct |
222 ms |
20200 KB |
Output is correct |
3 |
Correct |
53 ms |
15176 KB |
Output is correct |
4 |
Correct |
52 ms |
15164 KB |
Output is correct |
5 |
Correct |
549 ms |
28220 KB |
Output is correct |
6 |
Correct |
669 ms |
30712 KB |
Output is correct |
7 |
Correct |
7 ms |
15188 KB |
Output is correct |
8 |
Correct |
293 ms |
22136 KB |
Output is correct |
9 |
Correct |
395 ms |
23768 KB |
Output is correct |
10 |
Correct |
176 ms |
19648 KB |
Output is correct |
11 |
Correct |
212 ms |
20196 KB |
Output is correct |
12 |
Correct |
7 ms |
15188 KB |
Output is correct |
13 |
Correct |
7 ms |
15188 KB |
Output is correct |
14 |
Correct |
7 ms |
15184 KB |
Output is correct |
15 |
Correct |
7 ms |
15188 KB |
Output is correct |
16 |
Correct |
53 ms |
15168 KB |
Output is correct |
17 |
Correct |
51 ms |
15188 KB |
Output is correct |
18 |
Correct |
175 ms |
20056 KB |
Output is correct |
19 |
Correct |
211 ms |
20396 KB |
Output is correct |
20 |
Correct |
189 ms |
19512 KB |
Output is correct |
21 |
Correct |
206 ms |
19764 KB |
Output is correct |
22 |
Correct |
175 ms |
19520 KB |
Output is correct |
23 |
Correct |
197 ms |
19736 KB |
Output is correct |
24 |
Correct |
65 ms |
15432 KB |
Output is correct |
25 |
Correct |
49 ms |
15172 KB |
Output is correct |
26 |
Correct |
154 ms |
18124 KB |
Output is correct |
27 |
Correct |
113 ms |
17156 KB |
Output is correct |
28 |
Correct |
247 ms |
20652 KB |
Output is correct |
29 |
Correct |
229 ms |
20592 KB |
Output is correct |
30 |
Correct |
249 ms |
20652 KB |
Output is correct |
31 |
Correct |
251 ms |
20652 KB |
Output is correct |
32 |
Correct |
11 ms |
15060 KB |
Output is correct |
33 |
Correct |
7 ms |
15164 KB |
Output is correct |
34 |
Correct |
8 ms |
15188 KB |
Output is correct |
35 |
Correct |
9 ms |
15160 KB |
Output is correct |
36 |
Correct |
9 ms |
15188 KB |
Output is correct |
37 |
Correct |
9 ms |
15188 KB |
Output is correct |
38 |
Correct |
8 ms |
15188 KB |
Output is correct |
39 |
Correct |
7 ms |
15124 KB |
Output is correct |
40 |
Correct |
8 ms |
15208 KB |
Output is correct |
41 |
Correct |
11 ms |
15188 KB |
Output is correct |
42 |
Correct |
8 ms |
15188 KB |
Output is correct |
43 |
Correct |
12 ms |
15188 KB |
Output is correct |
44 |
Correct |
10 ms |
15188 KB |
Output is correct |
45 |
Correct |
9 ms |
15188 KB |
Output is correct |
46 |
Correct |
8 ms |
15104 KB |
Output is correct |
47 |
Correct |
9 ms |
15212 KB |
Output is correct |
48 |
Correct |
51 ms |
17132 KB |
Output is correct |
49 |
Correct |
50 ms |
17760 KB |
Output is correct |
50 |
Correct |
47 ms |
17512 KB |
Output is correct |
51 |
Correct |
47 ms |
17508 KB |
Output is correct |
52 |
Correct |
48 ms |
17504 KB |
Output is correct |
53 |
Correct |
97 ms |
20044 KB |
Output is correct |
54 |
Correct |
17 ms |
15720 KB |
Output is correct |
55 |
Correct |
48 ms |
17064 KB |
Output is correct |
56 |
Correct |
9 ms |
15176 KB |
Output is correct |
57 |
Correct |
18 ms |
15688 KB |
Output is correct |
58 |
Correct |
14 ms |
15368 KB |
Output is correct |
59 |
Correct |
242 ms |
26900 KB |
Output is correct |
60 |
Correct |
377 ms |
30116 KB |
Output is correct |
61 |
Correct |
420 ms |
29656 KB |
Output is correct |
62 |
Correct |
393 ms |
29688 KB |
Output is correct |
63 |
Correct |
304 ms |
31744 KB |
Output is correct |
64 |
Correct |
399 ms |
29668 KB |
Output is correct |
65 |
Correct |
390 ms |
29652 KB |
Output is correct |
66 |
Correct |
148 ms |
21788 KB |
Output is correct |
67 |
Correct |
399 ms |
31584 KB |
Output is correct |
68 |
Correct |
223 ms |
20652 KB |
Output is correct |
69 |
Correct |
238 ms |
20044 KB |
Output is correct |
70 |
Correct |
412 ms |
25064 KB |
Output is correct |
71 |
Correct |
7 ms |
15188 KB |
Output is correct |
72 |
Correct |
7 ms |
15132 KB |
Output is correct |
73 |
Correct |
8 ms |
15164 KB |
Output is correct |
74 |
Correct |
7 ms |
15116 KB |
Output is correct |
75 |
Correct |
7 ms |
15188 KB |
Output is correct |
76 |
Correct |
7 ms |
15060 KB |
Output is correct |
77 |
Correct |
58 ms |
15060 KB |
Output is correct |
78 |
Correct |
58 ms |
15168 KB |
Output is correct |
79 |
Correct |
52 ms |
15188 KB |
Output is correct |
80 |
Correct |
55 ms |
15176 KB |
Output is correct |
81 |
Correct |
238 ms |
20464 KB |
Output is correct |
82 |
Correct |
442 ms |
25416 KB |
Output is correct |
83 |
Correct |
383 ms |
25612 KB |
Output is correct |
84 |
Correct |
550 ms |
28440 KB |
Output is correct |
85 |
Correct |
573 ms |
28640 KB |
Output is correct |
86 |
Correct |
666 ms |
30584 KB |
Output is correct |
87 |
Correct |
625 ms |
30520 KB |
Output is correct |
88 |
Correct |
7 ms |
15188 KB |
Output is correct |
89 |
Correct |
696 ms |
30640 KB |
Output is correct |
90 |
Correct |
565 ms |
30412 KB |
Output is correct |
91 |
Correct |
553 ms |
30312 KB |
Output is correct |