#include <bits/stdc++.H>
#define ii pair<int, int>
#define fi first
#define se second
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n, m, x[N], y[N], w[N], f[3][2][2], g[3][2][2], res;
ii p[3][2][2], t[3][3];
vector <int> col[N], pref[N], _h[N], lst;
ii check(int i, int j, int k) {
ii ret = t[0][i];
if(!ret.fi) ret.fi = t[1][j].fi;
else if(ret.fi == 2 && j) return {1e9, 1e9};
if(!ret.se) ret.se = t[2][k].se;
else if(ret.se == 1 && k) return {1e9, 1e9};
return ret;
}
long long cal(int c, int h) {
if(c < 0 || col[c].empty()) return 0;
int it = lower_bound(_h[c].begin(), _h[c].end(), h) - _h[c].begin();
return pref[c][it];
}
long long max_weights(int n, int m, int x[], int y[], int w[]) {
t[0][2] = {1, 2};
t[0][0].fi = 2; t[0][1].se = 1;
t[1][1].fi = 1; t[2][1].se = 2;
for(int i = 0; i < m; i++) col[x[i]].push_back(i);
for(int i = 0; i < n; i++) col[i].push_back(m), y[m] = n, m++;
for(int c = 0; c < n; c++) {
sort(col[c].begin(), col[c].end(), [&] (int i, int j) {
return y[i] < y[j];
});
pref[c].push_back(0);
for(int i : col[c]) {
pref[c].push_back(pref[c].back() + w[i]);
_h[c].push_back(y[i]);
}
}
for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++)
p[x1][x2][x3] = check(x1, x2, x3);
for(int c = 0; c < n; c++) {
for(int i : col[c]) {
int v1 = cal(c - 1, y[i]), v2 = cal(c, y[i]), v3 = cal(c + 1, y[i]);
for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++) {
int v = v1 * x2 + v3 * x3 - v2 * (x1 < 2);
for(int y1 = 0; y1 < 3; y1++) for(int y2 = 0; y2 < 2; y2++) for(int y3 = 0; y3 < 2; y3++) {
if(p[x1][x2][x3].fi == 1e9 || p[y1][y2][y3].se == 1e9) continue;
if(p[x1][x2][x3].fi && p[x1][x2][x3].fi != p[y1][y2][y3].se) continue ;
if(x2 != (y1 % 2))continue ;
if((y3 == 1 && x1 != 0) || (y3 == 0 && x1 == 0)) continue;
f[x1][x2][x3] = max(f[x1][x2][x3], g[y1][y2][y3] + v);
}
}
}
for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++)
g[x1][x2][x3] = f[x1][x2][x3],
f[x1][x2][x3] = 0;
}
for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++)
res = max(res, g[x1][x2][x3]);
return res;
}
//main () {
// cin.tie(0)->sync_with_stdio(0);
// if(fopen("task.inp", "r")) {
// freopen("task.inp", "r", stdin);
// freopen("wa.out", "w", stdout);
// }
// cin >> n >> m;
// for(int i = 0; i < m; i++) cin >> x[i] >> y[i] >> w[i];
// cout << max_weights(n, m, x, y, w) << "\n";
//}
Compilation message
fish.cpp:1:10: fatal error: bits/stdc++.H: No such file or directory
1 | #include <bits/stdc++.H>
| ^~~~~~~~~~~~~~~
compilation terminated.