#include <bits/stdc++.h>
#define int long long
#define X first
#define Y second
#define mp make_pair
#define all(a) a.begin(),a.end()
using namespace std;
using pii = pair <int, int>;
constexpr int maxn = 1e5 + 10;
constexpr long long inf = 1e17 + 10;
vector <pii> tree (maxn << 2, mp (0, -inf));
vector <pii> A (maxn << 2, mp (-inf, -inf));
inline void push (int v, int t_l, int t_r) {
tree[v].X = max (tree[v].X, A[v].X);
tree[v].Y = max (tree[v].Y, A[v].Y);
if (t_l != t_r) {
A[v << 1].X = max (A[v << 1].X, A[v].X);
A[v << 1].Y = max (A[v << 1].Y, A[v].Y);
A[v << 1 | 1].X = max (A[v << 1 | 1].X, A[v].X);
A[v << 1 | 1].Y = max (A[v << 1 | 1].Y, A[v].Y);
}
A[v] = mp (-inf, -inf);
}
inline void update (int l, int r, pii x, int v, int t_l, int t_r) {
push (v, t_l, t_r);
if (l > t_r || t_l > r) return;
if (l <= t_l && t_r <= r) {
A[v] = x;
push (v, t_l, t_r);
return;
}
int t_m = t_l + t_r >> 1;
update (l, r, x, v << 1, t_l, t_m);
update (l, r, x, v << 1 | 1, t_m + 1, t_r);
tree[v].X = max (tree[v << 1].X, tree[v << 1 | 1].X);
tree[v].Y = max (tree[v << 1].Y, tree[v << 1 | 1].Y);
}
inline pii get (int i, int v, int t_l, int t_r) {
if (i > t_r || t_l > i) return mp (-inf, -inf);
push (v, t_l, t_r);
if (t_l == t_r) return tree[v];
int t_m = t_l + t_r >> 1;
return max (get (i, v << 1, t_l, t_m), get (i, v << 1 | 1, t_m + 1, t_r));
}
vector <pii> pos [maxn];
int last = 0;
int max_weights (int n, int m, vector <int> x, vector <int> y, vector <int> w) {
for (int i = 0; i < m; ++i) {
pos[x[i] + 1].push_back (mp (y[i] + 1, w[i]));
}
for (int i = 1; i <= n; ++i) sort (all (pos[i]));
for (int i = 1; i <= n; ++i) {
for (pii j : pos[i]) {
int am = get (j.X, 1, 0, n).X + j.Y;
update (j.X + 1, n, mp (am, -inf), 1, 0, n);
}
for (int _j = (int) pos[i].size () - 1; _j >= 0; --_j) {
pii j = pos[i][_j];
int am = get (j.X, 1, 0, n).Y + j.Y;
update (0, j.X - 1, mp (-inf, am), 1, 0, n);
}
int to = get (n, 1, 0, n).X, from = get (0, 1, 0, n).Y;
update (0, n, mp (from, last), 1, 0, n);
last = max (to, from);
}
return get (0, 1, 0, n).Y;
}
Compilation message
fish.cpp: In function 'void update(long long int, long long int, pii, long long int, long long int, long long int)':
fish.cpp:35:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int t_m = t_l + t_r >> 1;
| ~~~~^~~~~
fish.cpp: In function 'pii get(long long int, long long int, long long int, long long int)':
fish.cpp:46:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int t_m = t_l + t_r >> 1;
| ~~~~^~~~~
/usr/bin/ld: /tmp/cc8fudxU.o: in function `main':
grader.cpp:(.text.startup+0x25e): undefined reference to `max_weights(int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status