Skip to content

Commit 6b20059

Browse files
authored
Merge pull request #379 from hitonanode/add-range-add-chmax-range-min-tree
add range-add-chmax-range-min segtree
2 parents 94694ec + 5ca38fd commit 6b20059

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
#include "../acl_lazysegtree.hpp"
3+
#include <algorithm>
4+
5+
namespace RangeAddChmaxRangeMin {
6+
7+
using S = long long;
8+
constexpr S INF = 1LL << 60;
9+
10+
S e() { return INF; }
11+
12+
S op(S l, S r) { return std::min(l, r); }
13+
14+
struct F {
15+
// meaning: max(lower_bound, x) + bias
16+
S lower_bound, bias;
17+
F() : lower_bound(-INF), bias(0) {}
18+
F(S lower_bound, S bias) : lower_bound(lower_bound), bias(bias) {}
19+
static F chmax(S x) { return F(x, S()); }
20+
static F add(S x) { return F(-INF, x); }
21+
};
22+
23+
F id() { return F(); }
24+
25+
S mapping(F f, S x) { return std::max(f.lower_bound, x) + f.bias; }
26+
27+
F composition(F fnew, F gold) {
28+
return F(std::max(gold.lower_bound + gold.bias, fnew.lower_bound) - gold.bias,
29+
gold.bias + fnew.bias);
30+
}
31+
32+
using segtree = atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>;
33+
}; // namespace RangeAddChmaxRangeMin

0 commit comments

Comments
 (0)