This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void chmax(ll& a, ll b){ if(a < b) a = b; }
// range chmax・1 点取得 で O(M log N)
struct SegTree {
ll n;
vector<ll> seg;
SegTree(ll n): n(n), seg(n * 2) {}
void range_chmax(ll l, ll r, ll x) {
l += n;
r += n;
while(l < r){
if(l & 1) chmax(seg[l++], x);
if(r & 1) chmax(seg[--r], x);
l >>= 1; r >>= 1;
}
}
ll operator[](ll i) const {
i += n;
ll x = 0;
do chmax(x, seg[i]); while(i >>= 1);
return x;
}
};
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
vector fish(N, vector<pair<ll, ll>>{});
for (ll i = 0; i < M; i++) {
fish[X[i]].emplace_back(Y[i], W[i]);
}
for (auto& v : fish) sort(v.begin(), v.end());
SegTree up(N + 1), down(N + 1);
ll zero = 0;
for(ll x = 0; x + 1 < N; x++) {
for(auto [y, w] : fish[x]) {
up.range_chmax(y + 1, N + 1, up[y] + w);
}
reverse(fish[x + 1].begin(), fish[x + 1].end());
for(auto [y, w] : fish[x + 1]) {
down.range_chmax(0, y + 1, down[y + 1] + w);
}
reverse(fish[x + 1].begin(), fish[x + 1].end());
const ll zero_ = exchange(zero, down[0]);
down.range_chmax(0, N + 1, max(up[N], zero_));
up.range_chmax(0, N + 1, zero_);
}
return max({zero, down[0], up[N]});
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |