/**
_ _ __ _ _ _ _ _ _
|a ||t ||o d | |o |
| __ _| | _ | __| _ |
| __ |/_ | __ /__\ / _\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 100000;
const int M_MAX = 300000;
const ll INF = LLONG_MAX / 3;
int N, M;
int X[M_MAX + 2], Y[M_MAX + 2], W[M_MAX + 2];
vector <int> onX[N_MAX + 2];
ll Fen[N_MAX + 2];
vector <int> updi;
void init () {
while (updi.empty() == false) {
Fen[updi.back()] = -INF;
updi.pop_back();
}
}
void update (int pos, ll val) {
for (int i = pos; i <= N; i += i & -i) {
updi.push_back(i);
Fen[i] = max(Fen[i], val);
}
}
ll query (int pos) {
ll val = -INF;
for (int i = pos; i >= 1; i -= i & -i) {
val = max(val, Fen[i]);
}
return val;
}
ll dpUp[M_MAX + 2];
ll dpDown[M_MAX + 2];
ll fullUp[M_MAX + 2];
ll fullDown[M_MAX + 2];
ll max_weights (int _N, int _M, vector <int> _X, vector <int> _Y, vector <int> _W) {
N = _N; M = _M;
for (int i = 1; i <= M; i++) {
X[i] = _X[i - 1] + 1;
Y[i] = _Y[i - 1] + 1;
W[i] = _W[i - 1];
onX[X[i]].push_back(i);
}
fill(Fen + 1, Fen + N + 1, -INF);
fullUp[0] = -INF;
for (int x = 1; x <= N; x++) {
sort(onX[x].begin(), onX[x].end(), [&] (const int &i, const int &j) {
return Y[i] < Y[j];
});
init();
for (int i : onX[x - 1]) {
update(Y[i], dpUp[i]);
}
for (int i : onX[x]) {
dpUp[i] = max(fullDown[x], query(Y[i] - 1)) + W[i];
update(Y[i], dpUp[i]);
}
fullUp[x + 1] = max({fullUp[x], fullDown[x], query(N)});
reverse(onX[x].begin(), onX[x].end());
init();
for (int i : onX[x - 1]) {
update((N - Y[i] + 1), dpDown[i]);
}
for (int i : onX[x]) {
dpDown[i] = max(fullUp[x - 1], query((N - Y[i] + 1) - 1)) + W[i];
update((N - Y[i] + 1), dpDown[i]);
}
fullDown[x + 1] = max({fullUp[x], fullDown[x], query(N)});
reverse(onX[x].begin(), onX[x].end());
}
return max(fullDown[N + 1], fullUp[N]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
11964 KB |
Output is correct |
2 |
Correct |
95 ms |
15804 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4972 KB |
Output is correct |
5 |
Correct |
255 ms |
31096 KB |
Output is correct |
6 |
Correct |
268 ms |
29556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
138 ms |
20520 KB |
Output is correct |
3 |
Correct |
186 ms |
26468 KB |
Output is correct |
4 |
Correct |
69 ms |
13440 KB |
Output is correct |
5 |
Correct |
92 ms |
15716 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2676 KB |
Output is correct |
9 |
Correct |
2 ms |
2672 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
5 ms |
4948 KB |
Output is correct |
12 |
Correct |
69 ms |
13500 KB |
Output is correct |
13 |
Correct |
99 ms |
15828 KB |
Output is correct |
14 |
Correct |
73 ms |
13512 KB |
Output is correct |
15 |
Correct |
79 ms |
14936 KB |
Output is correct |
16 |
Correct |
68 ms |
13512 KB |
Output is correct |
17 |
Correct |
78 ms |
14704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
5 ms |
4948 KB |
Output is correct |
3 |
Correct |
54 ms |
9096 KB |
Output is correct |
4 |
Correct |
35 ms |
8576 KB |
Output is correct |
5 |
Correct |
80 ms |
14840 KB |
Output is correct |
6 |
Correct |
77 ms |
14196 KB |
Output is correct |
7 |
Correct |
87 ms |
14700 KB |
Output is correct |
8 |
Correct |
103 ms |
14732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2808 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
3 ms |
2772 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
3 ms |
2684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2808 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
3 ms |
2772 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
3 ms |
2684 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
3 ms |
2772 KB |
Output is correct |
17 |
Correct |
28 ms |
5968 KB |
Output is correct |
18 |
Correct |
27 ms |
6100 KB |
Output is correct |
19 |
Correct |
26 ms |
6100 KB |
Output is correct |
20 |
Correct |
27 ms |
6000 KB |
Output is correct |
21 |
Correct |
29 ms |
6092 KB |
Output is correct |
22 |
Correct |
49 ms |
9476 KB |
Output is correct |
23 |
Correct |
7 ms |
3284 KB |
Output is correct |
24 |
Correct |
20 ms |
4860 KB |
Output is correct |
25 |
Correct |
3 ms |
2772 KB |
Output is correct |
26 |
Correct |
8 ms |
3460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2808 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
3 ms |
2772 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
3 ms |
2684 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
3 ms |
2772 KB |
Output is correct |
17 |
Correct |
28 ms |
5968 KB |
Output is correct |
18 |
Correct |
27 ms |
6100 KB |
Output is correct |
19 |
Correct |
26 ms |
6100 KB |
Output is correct |
20 |
Correct |
27 ms |
6000 KB |
Output is correct |
21 |
Correct |
29 ms |
6092 KB |
Output is correct |
22 |
Correct |
49 ms |
9476 KB |
Output is correct |
23 |
Correct |
7 ms |
3284 KB |
Output is correct |
24 |
Correct |
20 ms |
4860 KB |
Output is correct |
25 |
Correct |
3 ms |
2772 KB |
Output is correct |
26 |
Correct |
8 ms |
3460 KB |
Output is correct |
27 |
Correct |
4 ms |
2940 KB |
Output is correct |
28 |
Correct |
136 ms |
19132 KB |
Output is correct |
29 |
Correct |
217 ms |
25760 KB |
Output is correct |
30 |
Correct |
199 ms |
25260 KB |
Output is correct |
31 |
Correct |
201 ms |
25316 KB |
Output is correct |
32 |
Correct |
189 ms |
25632 KB |
Output is correct |
33 |
Correct |
205 ms |
25232 KB |
Output is correct |
34 |
Correct |
208 ms |
25328 KB |
Output is correct |
35 |
Correct |
70 ms |
11472 KB |
Output is correct |
36 |
Correct |
218 ms |
25844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
5 ms |
4948 KB |
Output is correct |
3 |
Correct |
54 ms |
9096 KB |
Output is correct |
4 |
Correct |
35 ms |
8576 KB |
Output is correct |
5 |
Correct |
80 ms |
14840 KB |
Output is correct |
6 |
Correct |
77 ms |
14196 KB |
Output is correct |
7 |
Correct |
87 ms |
14700 KB |
Output is correct |
8 |
Correct |
103 ms |
14732 KB |
Output is correct |
9 |
Correct |
92 ms |
14496 KB |
Output is correct |
10 |
Correct |
81 ms |
12256 KB |
Output is correct |
11 |
Correct |
156 ms |
21764 KB |
Output is correct |
12 |
Correct |
2 ms |
2668 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
3 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4976 KB |
Output is correct |
21 |
Correct |
4 ms |
4976 KB |
Output is correct |
22 |
Correct |
99 ms |
14284 KB |
Output is correct |
23 |
Correct |
184 ms |
21772 KB |
Output is correct |
24 |
Correct |
162 ms |
22348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
11964 KB |
Output is correct |
2 |
Correct |
95 ms |
15804 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4972 KB |
Output is correct |
5 |
Correct |
255 ms |
31096 KB |
Output is correct |
6 |
Correct |
268 ms |
29556 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
138 ms |
20520 KB |
Output is correct |
9 |
Correct |
186 ms |
26468 KB |
Output is correct |
10 |
Correct |
69 ms |
13440 KB |
Output is correct |
11 |
Correct |
92 ms |
15716 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2668 KB |
Output is correct |
14 |
Correct |
2 ms |
2676 KB |
Output is correct |
15 |
Correct |
2 ms |
2672 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
5 ms |
4948 KB |
Output is correct |
18 |
Correct |
69 ms |
13500 KB |
Output is correct |
19 |
Correct |
99 ms |
15828 KB |
Output is correct |
20 |
Correct |
73 ms |
13512 KB |
Output is correct |
21 |
Correct |
79 ms |
14936 KB |
Output is correct |
22 |
Correct |
68 ms |
13512 KB |
Output is correct |
23 |
Correct |
78 ms |
14704 KB |
Output is correct |
24 |
Correct |
4 ms |
4948 KB |
Output is correct |
25 |
Correct |
5 ms |
4948 KB |
Output is correct |
26 |
Correct |
54 ms |
9096 KB |
Output is correct |
27 |
Correct |
35 ms |
8576 KB |
Output is correct |
28 |
Correct |
80 ms |
14840 KB |
Output is correct |
29 |
Correct |
77 ms |
14196 KB |
Output is correct |
30 |
Correct |
87 ms |
14700 KB |
Output is correct |
31 |
Correct |
103 ms |
14732 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
2 ms |
2644 KB |
Output is correct |
40 |
Correct |
2 ms |
2644 KB |
Output is correct |
41 |
Correct |
3 ms |
2808 KB |
Output is correct |
42 |
Correct |
2 ms |
2644 KB |
Output is correct |
43 |
Correct |
3 ms |
2772 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
3 ms |
2684 KB |
Output is correct |
46 |
Correct |
2 ms |
2644 KB |
Output is correct |
47 |
Correct |
3 ms |
2772 KB |
Output is correct |
48 |
Correct |
28 ms |
5968 KB |
Output is correct |
49 |
Correct |
27 ms |
6100 KB |
Output is correct |
50 |
Correct |
26 ms |
6100 KB |
Output is correct |
51 |
Correct |
27 ms |
6000 KB |
Output is correct |
52 |
Correct |
29 ms |
6092 KB |
Output is correct |
53 |
Correct |
49 ms |
9476 KB |
Output is correct |
54 |
Correct |
7 ms |
3284 KB |
Output is correct |
55 |
Correct |
20 ms |
4860 KB |
Output is correct |
56 |
Correct |
3 ms |
2772 KB |
Output is correct |
57 |
Correct |
8 ms |
3460 KB |
Output is correct |
58 |
Correct |
4 ms |
2940 KB |
Output is correct |
59 |
Correct |
136 ms |
19132 KB |
Output is correct |
60 |
Correct |
217 ms |
25760 KB |
Output is correct |
61 |
Correct |
199 ms |
25260 KB |
Output is correct |
62 |
Correct |
201 ms |
25316 KB |
Output is correct |
63 |
Correct |
189 ms |
25632 KB |
Output is correct |
64 |
Correct |
205 ms |
25232 KB |
Output is correct |
65 |
Correct |
208 ms |
25328 KB |
Output is correct |
66 |
Correct |
70 ms |
11472 KB |
Output is correct |
67 |
Correct |
218 ms |
25844 KB |
Output is correct |
68 |
Correct |
92 ms |
14496 KB |
Output is correct |
69 |
Correct |
81 ms |
12256 KB |
Output is correct |
70 |
Correct |
156 ms |
21764 KB |
Output is correct |
71 |
Correct |
2 ms |
2668 KB |
Output is correct |
72 |
Correct |
2 ms |
2644 KB |
Output is correct |
73 |
Correct |
3 ms |
2644 KB |
Output is correct |
74 |
Correct |
2 ms |
2644 KB |
Output is correct |
75 |
Correct |
2 ms |
2644 KB |
Output is correct |
76 |
Correct |
2 ms |
2644 KB |
Output is correct |
77 |
Correct |
4 ms |
4948 KB |
Output is correct |
78 |
Correct |
4 ms |
4948 KB |
Output is correct |
79 |
Correct |
4 ms |
4976 KB |
Output is correct |
80 |
Correct |
4 ms |
4976 KB |
Output is correct |
81 |
Correct |
99 ms |
14284 KB |
Output is correct |
82 |
Correct |
184 ms |
21772 KB |
Output is correct |
83 |
Correct |
162 ms |
22348 KB |
Output is correct |
84 |
Correct |
269 ms |
29120 KB |
Output is correct |
85 |
Correct |
320 ms |
28868 KB |
Output is correct |
86 |
Correct |
267 ms |
29440 KB |
Output is correct |
87 |
Correct |
356 ms |
30000 KB |
Output is correct |
88 |
Correct |
2 ms |
2644 KB |
Output is correct |
89 |
Correct |
324 ms |
30008 KB |
Output is correct |
90 |
Correct |
282 ms |
28320 KB |
Output is correct |
91 |
Correct |
230 ms |
27764 KB |
Output is correct |