版本比较
论:用AtCoder Library解决洛谷题目
正文
增加 27 行删除 27 行
387 行未改动全部展开3883893903913923923933943943953963963973983983994004004014024034044054064064074084084094104114124134144154164174184184194204214224234244244254264264274284294304314314324334334344354364374384394394404414414424434434444454454464474484494 行未改动45445545645745845845946046146246346446546546646746846947047047147247347447547647647747847948048148248348448548548648748748848949049118 行未改动51051151251351451451551651751818 行未改动53753853954054154154254354454554554654754854854955055055155255355427 行未改动387 行未改动全部展开#include <bit>#endif
namespace atcoder {
namespace internal {
#if __cplusplus >= 202002L
using std::bit_ceil;
#else
unsigned int bit_ceil(unsigned int n) { unsigned int x = 1; while (x < (unsigned int)(n)) x *= 2; return x; }
#endif
int countr_zero(unsigned int n) {#ifdef _MSC_VER unsigned long index; _BitScanForward(&index, n); return index;#else return __builtin_ctz(n);#endif }
constexpr int countr_zero_constexpr(unsigned int n) { int x = 0; while (!(n & (1 << x))) x++; return x; }
} // namespace internal
} // namespace atcoder
namespace atcoder {
#if __cplusplus >= 201703L
template <class S, auto op, auto e> struct segtree { static_assert(std::is_convertible_v<decltype(op), std::function<S(S, S)>>, "op must work as S(S, S)"); static_assert(std::is_convertible_v<decltype(e), std::function<S()>>, "e must work as S()");
#else
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
#endif
public: segtree() : segtree(0) {} explicit segtree(int n) : segtree(std::vector<S>(n, e())) {} explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {4 行未改动 for (int i = size - 1; i >= 1; i--) { update(i); } }
void set(int p, S x) { assert(0 <= p && p < _n); p += size; d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); }
S get(int p) const { assert(0 <= p && p < _n); return d[p + size]; }
S prod(int l, int r) const { assert(0 <= l && l <= r && r <= _n); S sml = e(), smr = e(); l += size; r += size;
while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); }
S all_prod() const { return d[1]; }
template <bool (*f)(S)> int max_right(int l) const { return max_right(l, [](S x) { return f(x); }); } template <class F> int max_right(int l, F f) const {18 行未改动 l++; } while ((l & -l) != l); return _n; }
template <bool (*f)(S)> int min_left(int r) const { return min_left(r, [](S x) { return f(x); }); } template <class F> int min_left(int r, F f) const {18 行未改动 sm = op(d[r], sm); } while ((r & -r) != r); return 0; }
private: int _n, size, log; std::vector<S> d;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } };
} // namespace atcoder
#include<bits/stdc++.h>#define int long longusing namespace std;using namespace atcoder;27 行未改动