#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<pair<int, int> > fishes[100005];
struct SegmentTree{
ll tree[1 << 18];
void init() {
memset(tree, 0xcf, sizeof(tree));
}
void upd(int idx, int s, int e, int l, int r, ll val) {
if (e < l || r < s) return;
if (l <= s && e <= r) {
tree[idx] = max(tree[idx], val);
return;
}
int mid = (s + e) / 2;
upd(2 * idx, s, mid, l, r, val);
upd(2 * idx + 1, mid + 1, e, l, r, val);
}
ll qry(int idx, int s, int e, int x) {
if (s == e) return tree[i];
int mid = (s + e) / 2;
if (x <= mid) return max(tree[idx], qry(2 * idx, s, mid, x));
return max(tree[idx], qry(2 * idx + 1, mid + 1, e, x));
}
} st_up, st_down;
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
for (int i = 0; i < M; i++) fishes[X[i] + 1].push_back({Y[i] + 1, W[i]});
ll till_now = 0;
st_down.init();
for (int i = 1; i <= N; i++) {
sort(fishes[i].begin(), fishes[i].end());
for (auto [j, w] : fishes[i]) st_up.upd(1, 0, N + 1, j + 1, N + 1, st_up.qry(1, 0, N + 1, j) + val);
reverse(fishes[i].begin(), fishes[i].end());
for (auto [j, w] : fishes[i]) st_down.upd(1, 0, N + 1, 0, j - 1, st_down.qry(1, 0, N + 1, j) + val);
ll u_res = st_up.qry(1, 0, N + 1, N + 1), d_res = st_down.qry(1, 0, N + 1, 0);
st_up.upd(1, 0, N + 1, 0, N + 1, d_res);
st_down.upd(1, 0, N + 1, 0, N + 1, till_now);
till_now = max(u_res, d_res);
}
return st_down.qry(1, 0, N + 1, 0);
}
Compilation message
fish.cpp: In member function 'll SegmentTree::qry(int, int, int, int)':
fish.cpp:24:33: error: 'i' was not declared in this scope
24 | if (s == e) return tree[i];
| ^
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:37:105: error: 'val' was not declared in this scope
37 | for (auto [j, w] : fishes[i]) st_up.upd(1, 0, N + 1, j + 1, N + 1, st_up.qry(1, 0, N + 1, j) + val);
| ^~~
fish.cpp:39:104: error: 'val' was not declared in this scope
39 | for (auto [j, w] : fishes[i]) st_down.upd(1, 0, N + 1, 0, j - 1, st_down.qry(1, 0, N + 1, j) + val);
| ^~~