#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
struct Seg{
long long n, st;
vector<long long> tr, lazy;
Seg(long long m):n(m + 4){
tr.resize(n * 4 * 3, -(long long)1e18);
lazy.resize(n * 4 * 3, -(long long)1e18);
st = m;
}
void update(int x, int s, int e){
tr[x] = max(tr[x], lazy[x]);
if(s < e){
lazy[x * 2] = max(lazy[x * 2], lazy[x]);
lazy[x * 2 + 1] = max(lazy[x * 2 + 1], lazy[x]);
}
lazy[x] = -(long long)1e18;
}
void push(long long x, long long s, long long e, int ps, int pe, long long val){
if(pe < s || ps > e){
return;
}
if(ps <= s && pe >= e){
lazy[x] = max(lazy[x], val);
update(x, s, e);
return;
}
update(x, s, e);
int m = s + e >> 1;
push(x * 2, s, m, ps, pe, val);
push(x * 2 + 1, m + 1, e, ps, pe, val);
tr[x] = max(tr[x * 2], tr[x * 2 + 1]);
}
long long get(long long x, long long s, long long e, long long fs, long long fe){
if(fe < s || fs > e || fs > fe) return -(long long)1e18;
update(x, s, e);
if(fs <= s && fe >= e){
return tr[x];
}
long long m = s + e >> 1;
return max(get(x * 2, s, m, fs, fe), get(x * 2 + 1, m + 1, e, fs, fe));
}
};
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vector<vector<long long>> a(M);
for(long long i = 0; i < M; ++i){
a[i] = {X[i], Y[i] + 1, W[i]};
}
sort(a.begin(), a.end());
Seg dp1(N), dp2(N);
int mx = N * 3 + 1;
//cout << mx << endl;
dp1.push(1, 0, mx, 0, mx, 0);
long long ans = 0;
for(long long i = 0, j = 0; i < N; ++i){
long long hval = dp1.get(1, 0, mx, 0, mx);
dp1.push(1, 0, mx, 0, mx, dp2.get(1, 0, mx, 0, mx));
long long l = j, r = j - 1;
while(r + 1 < M && a[r + 1][0] == i){
++r;
}
//cout << i << ' ' << l << ' ' << r << endl;
dp1.st -= 1;
dp2.st += 1;
for(long long x = l; x <= r; ++x){
dp1.push(1, 0, mx, a[x][1] + dp1.st, mx, dp1.get(1, 0, mx, a[x][1] + dp1.st, a[x][1] + dp1.st) + a[x][2]);
}
for(long long x = r; x >= l; --x){
//cout << a[x][1] << ' ' << dp2.st << endl;
dp2.push(1, 0, mx, 0, a[x][1] + dp2.st, dp2.get(1, 0, mx, a[x][1] + dp2.st, a[x][1] + dp2.st) + a[x][2]);
}
dp2.push(1, 0, mx, 0, mx, hval);
j = r + 1;
// for(int i = 1; i <= N; ++i){
// cout << dp1.get(1, 0, mx, i + dp1.st, i + dp1.st) << ' ';
// }
// cout << endl;
// for(int i = 1; i <= N; ++i){
// cout << dp2.get(1, 0, mx, i + dp1.st, i + dp1.st) << ' ';
// }
// cout << endl;
ans = max(ans, dp2.get(1, 0, mx, 0, mx));
if(i < N - 1){
ans = max(ans, dp1.get(1, 0, mx, 0, mx));
}
}
return ans;
}
Compilation message
fish.cpp: In member function 'void Seg::push(long long int, long long int, long long int, int, int, long long int)':
fish.cpp:39:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int m = s + e >> 1;
| ~~^~~
fish.cpp: In member function 'long long int Seg::get(long long int, long long int, long long int, long long int, long long int)':
fish.cpp:53:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
53 | long long m = s + e >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
40396 KB |
Output is correct |
2 |
Correct |
173 ms |
45704 KB |
Output is correct |
3 |
Correct |
21 ms |
37844 KB |
Output is correct |
4 |
Correct |
20 ms |
37880 KB |
Output is correct |
5 |
Correct |
557 ms |
61388 KB |
Output is correct |
6 |
Correct |
600 ms |
61408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
286 ms |
46724 KB |
Output is correct |
3 |
Correct |
356 ms |
53540 KB |
Output is correct |
4 |
Correct |
146 ms |
40404 KB |
Output is correct |
5 |
Correct |
173 ms |
45784 KB |
Output is correct |
6 |
Correct |
1 ms |
288 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
20 ms |
37844 KB |
Output is correct |
11 |
Correct |
21 ms |
37808 KB |
Output is correct |
12 |
Correct |
139 ms |
40400 KB |
Output is correct |
13 |
Correct |
171 ms |
45692 KB |
Output is correct |
14 |
Correct |
142 ms |
40588 KB |
Output is correct |
15 |
Correct |
160 ms |
44848 KB |
Output is correct |
16 |
Correct |
139 ms |
40492 KB |
Output is correct |
17 |
Correct |
154 ms |
44784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
37844 KB |
Output is correct |
2 |
Correct |
20 ms |
37784 KB |
Output is correct |
3 |
Correct |
101 ms |
38320 KB |
Output is correct |
4 |
Correct |
73 ms |
41064 KB |
Output is correct |
5 |
Correct |
168 ms |
45992 KB |
Output is correct |
6 |
Correct |
164 ms |
45892 KB |
Output is correct |
7 |
Correct |
174 ms |
46028 KB |
Output is correct |
8 |
Correct |
169 ms |
45908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
44 ms |
4668 KB |
Output is correct |
18 |
Correct |
44 ms |
4564 KB |
Output is correct |
19 |
Correct |
44 ms |
4652 KB |
Output is correct |
20 |
Correct |
44 ms |
4692 KB |
Output is correct |
21 |
Correct |
43 ms |
4656 KB |
Output is correct |
22 |
Correct |
90 ms |
8856 KB |
Output is correct |
23 |
Correct |
9 ms |
1236 KB |
Output is correct |
24 |
Correct |
30 ms |
3372 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
8 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
44 ms |
4668 KB |
Output is correct |
18 |
Correct |
44 ms |
4564 KB |
Output is correct |
19 |
Correct |
44 ms |
4652 KB |
Output is correct |
20 |
Correct |
44 ms |
4692 KB |
Output is correct |
21 |
Correct |
43 ms |
4656 KB |
Output is correct |
22 |
Correct |
90 ms |
8856 KB |
Output is correct |
23 |
Correct |
9 ms |
1236 KB |
Output is correct |
24 |
Correct |
30 ms |
3372 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
8 ms |
1108 KB |
Output is correct |
27 |
Correct |
5 ms |
1644 KB |
Output is correct |
28 |
Correct |
252 ms |
21212 KB |
Output is correct |
29 |
Correct |
436 ms |
30528 KB |
Output is correct |
30 |
Correct |
417 ms |
30432 KB |
Output is correct |
31 |
Correct |
436 ms |
30540 KB |
Output is correct |
32 |
Correct |
348 ms |
29052 KB |
Output is correct |
33 |
Correct |
425 ms |
30416 KB |
Output is correct |
34 |
Correct |
425 ms |
30420 KB |
Output is correct |
35 |
Correct |
146 ms |
12516 KB |
Output is correct |
36 |
Correct |
417 ms |
30432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
37844 KB |
Output is correct |
2 |
Correct |
20 ms |
37784 KB |
Output is correct |
3 |
Correct |
101 ms |
38320 KB |
Output is correct |
4 |
Correct |
73 ms |
41064 KB |
Output is correct |
5 |
Correct |
168 ms |
45992 KB |
Output is correct |
6 |
Correct |
164 ms |
45892 KB |
Output is correct |
7 |
Correct |
174 ms |
46028 KB |
Output is correct |
8 |
Correct |
169 ms |
45908 KB |
Output is correct |
9 |
Correct |
171 ms |
45992 KB |
Output is correct |
10 |
Correct |
152 ms |
27080 KB |
Output is correct |
11 |
Correct |
335 ms |
53884 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
20 ms |
37812 KB |
Output is correct |
19 |
Correct |
19 ms |
37844 KB |
Output is correct |
20 |
Correct |
20 ms |
37844 KB |
Output is correct |
21 |
Correct |
21 ms |
37780 KB |
Output is correct |
22 |
Correct |
206 ms |
47684 KB |
Output is correct |
23 |
Correct |
332 ms |
57024 KB |
Output is correct |
24 |
Correct |
331 ms |
57544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
40396 KB |
Output is correct |
2 |
Correct |
173 ms |
45704 KB |
Output is correct |
3 |
Correct |
21 ms |
37844 KB |
Output is correct |
4 |
Correct |
20 ms |
37880 KB |
Output is correct |
5 |
Correct |
557 ms |
61388 KB |
Output is correct |
6 |
Correct |
600 ms |
61408 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
286 ms |
46724 KB |
Output is correct |
9 |
Correct |
356 ms |
53540 KB |
Output is correct |
10 |
Correct |
146 ms |
40404 KB |
Output is correct |
11 |
Correct |
173 ms |
45784 KB |
Output is correct |
12 |
Correct |
1 ms |
288 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
20 ms |
37844 KB |
Output is correct |
17 |
Correct |
21 ms |
37808 KB |
Output is correct |
18 |
Correct |
139 ms |
40400 KB |
Output is correct |
19 |
Correct |
171 ms |
45692 KB |
Output is correct |
20 |
Correct |
142 ms |
40588 KB |
Output is correct |
21 |
Correct |
160 ms |
44848 KB |
Output is correct |
22 |
Correct |
139 ms |
40492 KB |
Output is correct |
23 |
Correct |
154 ms |
44784 KB |
Output is correct |
24 |
Correct |
19 ms |
37844 KB |
Output is correct |
25 |
Correct |
20 ms |
37784 KB |
Output is correct |
26 |
Correct |
101 ms |
38320 KB |
Output is correct |
27 |
Correct |
73 ms |
41064 KB |
Output is correct |
28 |
Correct |
168 ms |
45992 KB |
Output is correct |
29 |
Correct |
164 ms |
45892 KB |
Output is correct |
30 |
Correct |
174 ms |
46028 KB |
Output is correct |
31 |
Correct |
169 ms |
45908 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
3 ms |
596 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
436 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
2 ms |
468 KB |
Output is correct |
48 |
Correct |
44 ms |
4668 KB |
Output is correct |
49 |
Correct |
44 ms |
4564 KB |
Output is correct |
50 |
Correct |
44 ms |
4652 KB |
Output is correct |
51 |
Correct |
44 ms |
4692 KB |
Output is correct |
52 |
Correct |
43 ms |
4656 KB |
Output is correct |
53 |
Correct |
90 ms |
8856 KB |
Output is correct |
54 |
Correct |
9 ms |
1236 KB |
Output is correct |
55 |
Correct |
30 ms |
3372 KB |
Output is correct |
56 |
Correct |
2 ms |
468 KB |
Output is correct |
57 |
Correct |
8 ms |
1108 KB |
Output is correct |
58 |
Correct |
5 ms |
1644 KB |
Output is correct |
59 |
Correct |
252 ms |
21212 KB |
Output is correct |
60 |
Correct |
436 ms |
30528 KB |
Output is correct |
61 |
Correct |
417 ms |
30432 KB |
Output is correct |
62 |
Correct |
436 ms |
30540 KB |
Output is correct |
63 |
Correct |
348 ms |
29052 KB |
Output is correct |
64 |
Correct |
425 ms |
30416 KB |
Output is correct |
65 |
Correct |
425 ms |
30420 KB |
Output is correct |
66 |
Correct |
146 ms |
12516 KB |
Output is correct |
67 |
Correct |
417 ms |
30432 KB |
Output is correct |
68 |
Correct |
171 ms |
45992 KB |
Output is correct |
69 |
Correct |
152 ms |
27080 KB |
Output is correct |
70 |
Correct |
335 ms |
53884 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
340 KB |
Output is correct |
73 |
Correct |
1 ms |
212 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
0 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
20 ms |
37812 KB |
Output is correct |
78 |
Correct |
19 ms |
37844 KB |
Output is correct |
79 |
Correct |
20 ms |
37844 KB |
Output is correct |
80 |
Correct |
21 ms |
37780 KB |
Output is correct |
81 |
Correct |
206 ms |
47684 KB |
Output is correct |
82 |
Correct |
332 ms |
57024 KB |
Output is correct |
83 |
Correct |
331 ms |
57544 KB |
Output is correct |
84 |
Correct |
567 ms |
63456 KB |
Output is correct |
85 |
Correct |
550 ms |
66828 KB |
Output is correct |
86 |
Correct |
592 ms |
63680 KB |
Output is correct |
87 |
Correct |
598 ms |
67788 KB |
Output is correct |
88 |
Correct |
1 ms |
212 KB |
Output is correct |
89 |
Correct |
623 ms |
67660 KB |
Output is correct |
90 |
Correct |
507 ms |
66704 KB |
Output is correct |
91 |
Correct |
496 ms |
66508 KB |
Output is correct |