// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
const ll maxn = 100005;
set<ll> heights[maxn];
vector<ll> realheights[maxn];
unorderd_map<ll,ll> fish[maxn];
unorderd_map<ll,ll> weights[maxn];
unorderd_map<ll,ll> p[maxn];
vector<array<ll,2>> dp[maxn];
unorderd_map<ll,ll> pref[maxn][2];
unorderd_map<ll,ll> pref2[maxn][2];
unorderd_map<ll,ll> suff[maxn][2];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
FOR(i,0,M){
Y[i]++;
fish[X[i]][Y[i]] = 1;
weights[X[i]][Y[i]] = W[i];
if (X[i] > 0) heights[X[i]-1].insert(Y[i]);
if (X[i] > 1) heights[X[i]-2].insert(Y[i]);
heights[X[i]].insert(Y[i]);
heights[X[i]+1].insert(Y[i]);
heights[X[i]+2].insert(Y[i]);
}
FOR(i,0,maxn) heights[i].insert(0);
FOR(i,0,maxn) heights[i].insert(maxn);
FOR(i,0,maxn){
p[i][0] = 0;
ll prev = 0;
for (auto j : heights[i]){
if (j==0) continue;
p[i][j] = p[i][prev] + weights[i][j];
prev = j;
}
}
FOR(i,0,maxn){
for (auto k : heights[i]) realheights[i].push_back(k);
}
FOR(i,0,maxn){
dp[i].resize(heights[i].size());
}
FOR(i,1,N+1){
FOR(X,0,dp[i].size()){
ll j = realheights[i][X];
FOR(k,0,2){
if (i<2) continue;
ll temp = 0;
ll add = 0;
if (k==0){
if (X==dp[i].size()-1) continue;
temp = max(temp, suff[i-1][0][j] - p[i-1][j]);
temp = max(temp, suff[i-1][1][j] - p[i-1][j]);
// FOR(p,j+1,N+1){
// if (fish[i-1][p]) add += weights[i-1][p];
// temp = max(temp, dp[i-1][p][0] + add);
// temp = max(temp, dp[i-1][p][1] + add);
// }
}else{
temp = max(temp, pref[i-1][0][j]);
temp = max(temp, pref[i-1][1][j] + p[i-2][j]);
// FOR(p,0,j+1) if (fish[i-2][p]) add += weights[i-2][p];
// FOR(p,0,j+1){
// if (fish[i-2][p]) add -= weights[i-2][p];
// temp = max(temp, dp[i-1][p][0]);
// temp = max(temp, dp[i-1][p][1] + add);
// }
}
dp[i][X][k] = temp;
}
}
ll sz = realheights[i].size();
FOR(k,0,2){
ll tempadd = 0;
ll tempadd2 = 0;
FOR(j,0,sz){
tempadd += weights[i][realheights[i][j]];
suff[i][k][realheights[i][j]] = dp[i][j][k]+tempadd;
}
FOR(j,0,sz){
tempadd2 -= weights[i-1][realheights[i][j]];
pref[i][k][realheights[i][j]] = dp[i][j][k] + tempadd2;
pref2[i][k][realheights[i][j]] = dp[i][j][k];
}
ll prev = 0;
FOR(j,1,sz){
pref[i][k][realheights[i][j]] = max(pref[i][k][realheights[i][j]], pref[i][k][prev]);
pref2[i][k][realheights[i][j]] = max(pref2[i][k][realheights[i][j]], pref2[i][k][prev]);
prev = realheights[i][j];
}
prev = realheights[i][sz-1];
FORNEG(j,sz-2,-1){
suff[i][k][realheights[i][j]] = max(suff[i][k][realheights[i][j]], suff[i][k][prev]);
prev = realheights[i][j];
}
}
// cout << i << endl;
// cout << suff[2][2][0] << "FUCK" << endl;
}
// cout << dp[3][2][0] << endl;
ll ans = 0;
FOR(i,0,N+1){
FOR(j,0,dp[i].size()){
ans = max(dp[i][j][0], ans);
ans = max(dp[i][j][1], ans);
}
}
return ans;
}
Compilation message
fish.cpp:18:1: error: 'unorderd_map' does not name a type
18 | unorderd_map<ll,ll> fish[maxn];
| ^~~~~~~~~~~~
fish.cpp:19:1: error: 'unorderd_map' does not name a type
19 | unorderd_map<ll,ll> weights[maxn];
| ^~~~~~~~~~~~
fish.cpp:21:1: error: 'unorderd_map' does not name a type
21 | unorderd_map<ll,ll> p[maxn];
| ^~~~~~~~~~~~
fish.cpp:25:1: error: 'unorderd_map' does not name a type
25 | unorderd_map<ll,ll> pref[maxn][2];
| ^~~~~~~~~~~~
fish.cpp:26:1: error: 'unorderd_map' does not name a type
26 | unorderd_map<ll,ll> pref2[maxn][2];
| ^~~~~~~~~~~~
fish.cpp:27:1: error: 'unorderd_map' does not name a type
27 | unorderd_map<ll,ll> suff[maxn][2];
| ^~~~~~~~~~~~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:35:9: error: 'fish' was not declared in this scope
35 | fish[X[i]][Y[i]] = 1;
| ^~~~
fish.cpp:36:9: error: 'weights' was not declared in this scope; did you mean 'heights'?
36 | weights[X[i]][Y[i]] = W[i];
| ^~~~~~~
| heights
fish.cpp:49:9: error: 'p' was not declared in this scope
49 | p[i][0] = 0;
| ^
fish.cpp:53:36: error: 'weights' was not declared in this scope; did you mean 'heights'?
53 | p[i][j] = p[i][prev] + weights[i][j];
| ^~~~~~~
| heights
fish.cpp:9:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
67 | FOR(X,0,dp[i].size()){
| ~~~~~~~~~~~~~~~~
fish.cpp:67:9: note: in expansion of macro 'FOR'
67 | FOR(X,0,dp[i].size()){
| ^~~
fish.cpp:76:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | if (X==dp[i].size()-1) continue;
| ~^~~~~~~~~~~~~~~~
fish.cpp:77:38: error: 'suff' was not declared in this scope
77 | temp = max(temp, suff[i-1][0][j] - p[i-1][j]);
| ^~~~
fish.cpp:77:56: error: 'p' was not declared in this scope
77 | temp = max(temp, suff[i-1][0][j] - p[i-1][j]);
| ^
fish.cpp:86:38: error: 'pref' was not declared in this scope
86 | temp = max(temp, pref[i-1][0][j]);
| ^~~~
fish.cpp:87:56: error: 'p' was not declared in this scope
87 | temp = max(temp, pref[i-1][1][j] + p[i-2][j]);
| ^
fish.cpp:74:20: warning: unused variable 'add' [-Wunused-variable]
74 | ll add = 0;
| ^~~
fish.cpp:109:28: error: 'weights' was not declared in this scope; did you mean 'heights'?
109 | tempadd += weights[i][realheights[i][j]];
| ^~~~~~~
| heights
fish.cpp:110:17: error: 'suff' was not declared in this scope
110 | suff[i][k][realheights[i][j]] = dp[i][j][k]+tempadd;
| ^~~~
fish.cpp:114:29: error: 'weights' was not declared in this scope; did you mean 'heights'?
114 | tempadd2 -= weights[i-1][realheights[i][j]];
| ^~~~~~~
| heights
fish.cpp:115:17: error: 'pref' was not declared in this scope
115 | pref[i][k][realheights[i][j]] = dp[i][j][k] + tempadd2;
| ^~~~
fish.cpp:116:17: error: 'pref2' was not declared in this scope
116 | pref2[i][k][realheights[i][j]] = dp[i][j][k];
| ^~~~~
fish.cpp:120:17: error: 'pref' was not declared in this scope; did you mean 'prev'?
120 | pref[i][k][realheights[i][j]] = max(pref[i][k][realheights[i][j]], pref[i][k][prev]);
| ^~~~
| prev
fish.cpp:121:17: error: 'pref2' was not declared in this scope
121 | pref2[i][k][realheights[i][j]] = max(pref2[i][k][realheights[i][j]], pref2[i][k][prev]);
| ^~~~~
fish.cpp:126:17: error: 'suff' was not declared in this scope
126 | suff[i][k][realheights[i][j]] = max(suff[i][k][realheights[i][j]], suff[i][k][prev]);
| ^~~~
fish.cpp:9:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
145 | FOR(j,0,dp[i].size()){
| ~~~~~~~~~~~~~~~~
fish.cpp:145:9: note: in expansion of macro 'FOR'
145 | FOR(j,0,dp[i].size()){
| ^~~