#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
const int SZ = 131072;
const ll INF = ll(1e18);
struct Seg {
ll d[2 * SZ];
void u(int x, ll v) {
for(x += SZ; x; x /= 2) d[x] = max(d[x], v);
}
ll g(int s = 0, int e = SZ - 1) {
ll r = -INF;
for(s += SZ, e += SZ; s <= e; s /= 2, e /= 2) {
if(s & 1) r = max(r, d[s++]);
if(~e& 1) r = max(r, d[e--]);
}
return r;
}
} U[3], D[3];
ll max_weights(int N, int M, vint X, vint Y, vint W) {
vector<vpil> a(N);
vector<vpll> d(N);
for(int i = 0; i < M; i++) {
a[X[i]].emplace_back(Y[i], W[i]);
d[X[i]].emplace_back(-INF, -INF);
}
for(int i = 0; i < N; i++) {
sort(all(a[i]));
sort(all(d[i]));
}
for(int i = 0; i < N; i++) {
for(int j = 1; j <= 2; j++) if(i - j >= 0)
for(int k = 0; k < a[i - j].size(); k++) {
U[j].u(a[i - j][k].x, d[i - j][k].x);
D[j].u(a[i - j][k].x, d[i - j][k].y);
}
int K = a[i].size();
if(i < N - 1) for(int j = 0; j < K; j++) {
d[i][j].x = max(U[0].g(0, a[i][j].x - 1), D[1].g()) + a[i][j].y;
U[0].u(a[i][j].x, d[i][j].x);
}
if(i) for(int j = K - 1; j >= 0; j--) {
d[i][j].y = max(D[0].g(a[i][j].x + 1), U[2].g()) + a[i][j].y;
D[0].u(a[i][j].x, d[i][j].y);
}
}
ll ans = 0;
for(auto &v : d) for(auto &p : v) ans = max({ans, p.x, p.y});
return ans;
}
Compilation message
fish.cpp: In function 'll max_weights(int, int, vint, vint, vint)':
fish.cpp:55:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int k = 0; k < a[i - j].size(); k++) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
16304 KB |
Output is correct |
2 |
Correct |
70 ms |
19276 KB |
Output is correct |
3 |
Correct |
4 ms |
5204 KB |
Output is correct |
4 |
Correct |
5 ms |
5204 KB |
Output is correct |
5 |
Correct |
226 ms |
33320 KB |
Output is correct |
6 |
Correct |
440 ms |
38392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
115 ms |
22248 KB |
Output is correct |
3 |
Correct |
146 ms |
26620 KB |
Output is correct |
4 |
Correct |
56 ms |
17120 KB |
Output is correct |
5 |
Correct |
70 ms |
19448 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
72 ms |
18644 KB |
Output is correct |
13 |
Correct |
82 ms |
20920 KB |
Output is correct |
14 |
Correct |
61 ms |
17912 KB |
Output is correct |
15 |
Correct |
69 ms |
15792 KB |
Output is correct |
16 |
Correct |
61 ms |
17864 KB |
Output is correct |
17 |
Correct |
70 ms |
19568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
50 ms |
9808 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '20783599837907' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Incorrect |
1 ms |
596 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Incorrect |
1 ms |
596 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Incorrect |
1 ms |
596 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
50 ms |
9808 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '20783599837907' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
16304 KB |
Output is correct |
2 |
Correct |
70 ms |
19276 KB |
Output is correct |
3 |
Correct |
4 ms |
5204 KB |
Output is correct |
4 |
Correct |
5 ms |
5204 KB |
Output is correct |
5 |
Correct |
226 ms |
33320 KB |
Output is correct |
6 |
Correct |
440 ms |
38392 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
115 ms |
22248 KB |
Output is correct |
9 |
Correct |
146 ms |
26620 KB |
Output is correct |
10 |
Correct |
56 ms |
17120 KB |
Output is correct |
11 |
Correct |
70 ms |
19448 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
5204 KB |
Output is correct |
17 |
Correct |
4 ms |
5204 KB |
Output is correct |
18 |
Correct |
72 ms |
18644 KB |
Output is correct |
19 |
Correct |
82 ms |
20920 KB |
Output is correct |
20 |
Correct |
61 ms |
17912 KB |
Output is correct |
21 |
Correct |
69 ms |
15792 KB |
Output is correct |
22 |
Correct |
61 ms |
17864 KB |
Output is correct |
23 |
Correct |
70 ms |
19568 KB |
Output is correct |
24 |
Correct |
3 ms |
5204 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Incorrect |
50 ms |
9808 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '20783599837907' |
27 |
Halted |
0 ms |
0 KB |
- |