#include "fish.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
long long zero[101010], full[101010];
vector< pair<int, long long> > ylist[101010];
vector< long long > sum[101010], dp[2][101010];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
for (int i = 0; i < M; i++) {
X[i] += 1;
Y[i] += 1;
ylist[X[i]].push_back({Y[i], 0});
ylist[X[i] - 1].push_back({Y[i], 0});
ylist[X[i] + 1].push_back({Y[i], 0});
}
for (int i = 0; i <= N + 1; i++) {
ylist[i].push_back({0, 0});
ylist[i].push_back({N, 0});
sort(ylist[i].begin(), ylist[i].end());
ylist[i].erase(unique(ylist[i].begin(), ylist[i].end()), ylist[i].end());
}
for (int i = 0; i < M; i++) {
int idx = lower_bound(ylist[X[i]].begin(), ylist[X[i]].end(), make_pair(Y[i], 0LL)) - ylist[X[i]].begin();
ylist[X[i]][idx].second = W[i];
}
for (int i = 0; i <= N + 1; i++) {
sum[i].push_back(0);
for (int j = 1; j < ylist[i].size(); j++) {
sum[i].push_back(sum[i].back() + ylist[i][j].second);
}
}
for (int i = 0; i <= N + 1; i++) {
for (int j = 0; j < ylist[i].size(); j++) dp[0][i].push_back(0);
for (int j = 0; j < ylist[i].size(); j++) dp[1][i].push_back(0);
}
for (int j = 1; j < ylist[0].size() - 1; j++) dp[0][0][j] = -1e18;
for (int j = 1; j < ylist[0].size() - 1; j++) dp[1][0][j] = -1e18;
full[0] = -1e18;
for (int i = 2; i <= N + 1; i++) {
vector< pair<int, long long> > temp, all;
merge(ylist[i].begin(), ylist[i].end(), ylist[i - 1].begin(), ylist[i - 1].end(), temp.begin());
merge(temp.begin(), temp.end(), ylist[i - 2].begin(), ylist[i - 2].end(), all.begin());
for (int t = 0; t < all.size(); t++) all[t].second = 0;
all.erase(unique(all.begin(), all.end()), all.end());
for (int t = 1; t < all.size() - 1; t++) {
int j = lower_bound(ylist[i].begin(), ylist[i].end(), all[t]) - ylist[i].begin();
int k = lower_bound(ylist[i - 1].begin(), ylist[i - 1].end(), all[t]) - ylist[i - 1].begin();
zero[i] = max(zero[i], dp[1][i - 1][k] + sum[i][j]);
}
zero[i] = max(zero[i], zero[i - 1]);
zero[i] = max(zero[i], full[i - 1] + sum[i][ylist[i].size() - 1]);
for (int t = 1; t < all.size() - 1; t++) {
int k = lower_bound(ylist[i - 1].begin(), ylist[i - 1].end(), all[t]) - ylist[i - 1].begin();
full[i] = max(full[i], dp[0][i - 1][k] + sum[i - 1][ylist[i - 1].size() - 1] - sum[i - 1][k]);
}
full[i] = max(full[i], full[i - 1]);
full[i] = max(full[i], zero[i - 2] + sum[i - 1][ylist[i - 1].size() - 1]);
full[i] = max(full[i], full[i - 2] + sum[i - 1][ylist[i - 1].size() - 1]);
for (int t = 1; t < all.size() - 1; t++) {
int l = lower_bound(ylist[i - 2].begin(), ylist[i - 2].end(), all[t]) - ylist[i - 2].begin();
full[i] = max(full[i], dp[1][i - 2][l] + sum[i - 1][ylist[i - 1].size() - 1]);
}
long long val0 = 0, val1 = 0;
for (int t = 1; t < all.size() - 1; t++) {
int j = lower_bound(ylist[i].begin(), ylist[i].end(), all[t]) - ylist[i].begin();
int k = lower_bound(ylist[i - 1].begin(), ylist[i - 1].end(), all[t]) - ylist[i - 1].begin();
val0 = max(val0, dp[0][i - 1][k] - sum[i - 1][k]);
val1 = max(val1, dp[1][i - 1][k] + sum[i][j]);
}
for (int t = 1; t < all.size() - 1; t++) {
int j = lower_bound(ylist[i].begin(), ylist[i].end(), all[t]) - ylist[i].begin();
int k = lower_bound(ylist[i - 1].begin(), ylist[i - 1].end(), all[t]) - ylist[i - 1].begin();
dp[0][i][j] = max(dp[0][i][j], val0 + sum[i - 1][k]);
dp[1][i][j] = max(dp[1][i][j], val1 - sum[i][j]);
dp[1][i][j] = max(dp[1][i][j], full[i - 1] + sum[i][ylist[i].size() - 1] - sum[i][j]);
dp[0][i][j] = max(dp[0][i][j], zero[i - 2] + sum[i - 1][k]);
dp[0][i][j] = max(dp[0][i][j], full[i - 2] + sum[i - 1][ylist[i - 1].size() - 1]);
}
long long val2 = 0;
for (int t = 1; t < all.size() - 1; t++) {
int j = lower_bound(ylist[i].begin(), ylist[i].end(), all[t]) - ylist[i].begin();
int k = lower_bound(ylist[i - 1].begin(), ylist[i - 1].end(), all[t]) - ylist[i - 1].begin();
int l = lower_bound(ylist[i - 2].begin(), ylist[i - 2].end(), all[t]) - ylist[i - 2].begin();
val2 = max(val2, dp[1][i - 2][l]);
dp[0][i][j] = max(dp[0][i][j], val2 + sum[i - 1][k]);
}
long long val3 = 0;
for (int t = 1; t < all.size() - 1; t++) {
int j = lower_bound(ylist[i].begin(), ylist[i].end(), all[t]) - ylist[i].begin();
int k = lower_bound(ylist[i - 1].begin(), ylist[i - 1].end(), all[t]) - ylist[i - 1].begin();
int l = lower_bound(ylist[i - 2].begin(), ylist[i - 2].end(), all[t]) - ylist[i - 2].begin();
val3 = max(val3, dp[1][i - 2][l] + sum[i - 1][k]);
dp[0][i][j] = max(dp[0][i][j], val3);
}
}
long long res = 0;
res = zero[N + 1];
return res;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:33:27: 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]
33 | for (int j = 1; j < ylist[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:39:27: 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]
39 | for (int j = 0; j < ylist[i].size(); j++) dp[0][i].push_back(0);
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:40:27: 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]
40 | for (int j = 0; j < ylist[i].size(); j++) dp[1][i].push_back(0);
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:42:23: 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]
42 | for (int j = 1; j < ylist[0].size() - 1; j++) dp[0][0][j] = -1e18;
| ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:43:23: 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]
43 | for (int j = 1; j < ylist[0].size() - 1; j++) dp[1][0][j] = -1e18;
| ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:49:27: 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]
49 | for (int t = 0; t < all.size(); t++) all[t].second = 0;
| ~~^~~~~~~~~~~~
fish.cpp:52:27: 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]
52 | for (int t = 1; t < all.size() - 1; t++) {
| ~~^~~~~~~~~~~~~~~~
fish.cpp:60:27: 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]
60 | for (int t = 1; t < all.size() - 1; t++) {
| ~~^~~~~~~~~~~~~~~~
fish.cpp:67:27: 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]
67 | for (int t = 1; t < all.size() - 1; t++) {
| ~~^~~~~~~~~~~~~~~~
fish.cpp:73:27: 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]
73 | for (int t = 1; t < all.size() - 1; t++) {
| ~~^~~~~~~~~~~~~~~~
fish.cpp:79:27: 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]
79 | for (int t = 1; t < all.size() - 1; t++) {
| ~~^~~~~~~~~~~~~~~~
fish.cpp:89:27: 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]
89 | for (int t = 1; t < all.size() - 1; t++) {
| ~~^~~~~~~~~~~~~~~~
fish.cpp:97:27: 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]
97 | for (int t = 1; t < all.size() - 1; t++) {
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
128 ms |
68516 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
19612 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
48196 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
19544 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
19544 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
19544 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
48196 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
128 ms |
68516 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |