This documentation is automatically generated by online-judge-tools/verification-helper
 ds/segtree/segtree.hpp
 ds/segtree/segtree.hpp
    
#include "ds/segtree/segtree.hpp" View error logs on GitHub Actions
 View error logs on GitHub Actions
 ds/offline_query/range_mex_query.hpp
 ds/offline_query/range_mex_query.hpp
            
         ds/offline_query/uniqueproductquery.hpp
 ds/offline_query/uniqueproductquery.hpp
            
         ds/rmq/range_add_range_max.hpp
 ds/rmq/range_add_range_max.hpp
            
         ds/rmq/range_add_range_min.hpp
 ds/rmq/range_add_range_min.hpp
            
         ds/segtree/range_assignment_segtree.hpp
 ds/segtree/range_assignment_segtree.hpp
            
         ds/segtree/sortable_segtree.hpp
 ds/segtree/sortable_segtree.hpp
            
         geo/manhattan_nns.hpp
 geo/manhattan_nns.hpp
            
         graph/ds/tree_monoid.hpp
 graph/ds/tree_monoid.hpp
            
         graph/minimum_spanning_tree.hpp
 graph/minimum_spanning_tree.hpp
            
         graph/optimal_product_on_tree.hpp
 graph/optimal_product_on_tree.hpp
            
         string/basic_substring_structure.hpp
 string/basic_substring_structure.hpp
            
         string/lex_max_suffix_for_all_prefix.hpp
 string/lex_max_suffix_for_all_prefix.hpp
            
         string/longest_common_substring.hpp
 string/longest_common_substring.hpp
            
         string/many_string_compare.hpp
 string/many_string_compare.hpp
            
         string/sort_substrings.hpp
 string/sort_substrings.hpp
            
         string/substring_count_in_substring.hpp
 string/substring_count_in_substring.hpp
            
         string/substring_shortest_border.hpp
 string/substring_shortest_border.hpp
            
         string/suffix_array.hpp
 string/suffix_array.hpp
            
         string/suffix_lcp_change.hpp
 string/suffix_lcp_change.hpp
            
         string/suffix_tree.hpp
 string/suffix_tree.hpp
            
         test/1_mytest/lex_minmax_suffix.test.cpp
 test/1_mytest/lex_minmax_suffix.test.cpp
            
         test/1_mytest/longest_common_substr.test.cpp
 test/1_mytest/longest_common_substr.test.cpp
            
         test/1_mytest/manhattan_nns.test.cpp
 test/1_mytest/manhattan_nns.test.cpp
            
         test/1_mytest/mo_on_tree.test.cpp
 test/1_mytest/mo_on_tree.test.cpp
            
         test/1_mytest/range_add_range_max.test.cpp
 test/1_mytest/range_add_range_max.test.cpp
            
         test/1_mytest/range_add_range_min.test.cpp
 test/1_mytest/range_add_range_min.test.cpp
            
         test/1_mytest/range_assign.test.cpp
 test/1_mytest/range_assign.test.cpp
            
         test/1_mytest/range_mex.test.cpp
 test/1_mytest/range_mex.test.cpp
            
         test/1_mytest/segtree_xor_prod.test.cpp
 test/1_mytest/segtree_xor_prod.test.cpp
            
         test/1_mytest/suffix_lcp_change.test.cpp
 test/1_mytest/suffix_lcp_change.test.cpp
            
         test/1_mytest/wavelet_matrix.test.cpp
 test/1_mytest/wavelet_matrix.test.cpp
            
         test/2_library_checker/data_structure/point_add_rectangle_sum_wm_mono.test.cpp
 test/2_library_checker/data_structure/point_add_rectangle_sum_wm_mono.test.cpp
            
         test/2_library_checker/data_structure/point_set_range_composite_monoid.test.cpp
 test/2_library_checker/data_structure/point_set_range_composite_monoid.test.cpp
            
         test/2_library_checker/data_structure/predecessor_problem_3.test.cpp
 test/2_library_checker/data_structure/predecessor_problem_3.test.cpp
            
         test/2_library_checker/data_structure/range_set_range_composite.test.cpp
 test/2_library_checker/data_structure/range_set_range_composite.test.cpp
            
         test/2_library_checker/data_structure/sort_segtree.test.cpp
 test/2_library_checker/data_structure/sort_segtree.test.cpp
            
         test/2_library_checker/data_structure/sort_segtree_1.test.cpp
 test/2_library_checker/data_structure/sort_segtree_1.test.cpp
            
         test/2_library_checker/data_structure/staticrmq_seg.test.cpp
 test/2_library_checker/data_structure/staticrmq_seg.test.cpp
            
         test/2_library_checker/string/longest_common_substring.test.cpp
 test/2_library_checker/string/longest_common_substring.test.cpp
            
         test/2_library_checker/string/number_of_substrings.test.cpp
 test/2_library_checker/string/number_of_substrings.test.cpp
            
         test/2_library_checker/string/suffix_array.test.cpp
 test/2_library_checker/string/suffix_array.test.cpp
            
         test/2_library_checker/string/suffix_array_vec.test.cpp
 test/2_library_checker/string/suffix_array_vec.test.cpp
            
         test/2_library_checker/tree/mst.test.cpp
 test/2_library_checker/tree/mst.test.cpp
            
         test/2_library_checker/tree/rooted_tree_topological_order_with_minimum_inversions.test.cpp
 test/2_library_checker/tree/rooted_tree_topological_order_with_minimum_inversions.test.cpp
            
         test/2_library_checker/tree/vertex_add_path_sum_monoid_c.test.cpp
 test/2_library_checker/tree/vertex_add_path_sum_monoid_c.test.cpp
            
         test/2_library_checker/tree/vertex_add_subtree_sum_monoid.test.cpp
 test/2_library_checker/tree/vertex_add_subtree_sum_monoid.test.cpp
            
         test/2_library_checker/tree/vertex_set_path_composite_monoid.test.cpp
 test/2_library_checker/tree/vertex_set_path_composite_monoid.test.cpp
            
         test/3_yukicoder/1036_2.test.cpp
 test/3_yukicoder/1036_2.test.cpp
            
         test/3_yukicoder/1212.test.cpp
 test/3_yukicoder/1212.test.cpp
            
         test/3_yukicoder/1435.test.cpp
 test/3_yukicoder/1435.test.cpp
            
         test/3_yukicoder/1549.test.cpp
 test/3_yukicoder/1549.test.cpp
            
         test/3_yukicoder/1625_2.test.cpp
 test/3_yukicoder/1625_2.test.cpp
            
         test/3_yukicoder/2361.test.cpp
 test/3_yukicoder/2361.test.cpp
            
         test/3_yukicoder/2595.test.cpp
 test/3_yukicoder/2595.test.cpp
            
         test/3_yukicoder/2859.test.cpp
 test/3_yukicoder/2859.test.cpp
            
         test/3_yukicoder/2890.test.cpp
 test/3_yukicoder/2890.test.cpp
            
         test/3_yukicoder/2897.test.cpp
 test/3_yukicoder/2897.test.cpp
            
         test/3_yukicoder/3148.test.cpp
 test/3_yukicoder/3148.test.cpp
            
         test/3_yukicoder/426.test.cpp
 test/3_yukicoder/426.test.cpp
            
         test/3_yukicoder/529.test.cpp
 test/3_yukicoder/529.test.cpp
            
         test/4_aoj/GRL_2_A.test.cpp
 test/4_aoj/GRL_2_A.test.cpp
            
         test/4_aoj/ITP2_3_B.test.cpp
 test/4_aoj/ITP2_3_B.test.cpp
            
        #pragma once
template <class Monoid>
struct SegTree {
  using MX = Monoid;
  using X = typename MX::value_type;
  using value_type = X;
  vc<X> dat;
  int n, log, size;
  SegTree() {}
  SegTree(int n) { build(n); }
  template <typename F>
  SegTree(int n, F f) {
    build(n, f);
  }
  SegTree(const vc<X>& v) { build(v); }
  void build(int m) {
    build(m, [](int i) -> X { return MX::unit(); });
  }
  void build(const vc<X>& v) {
    build(len(v), [&](int i) -> X { return v[i]; });
  }
  template <typename F>
  void build(int m, F f) {
    n = m, log = 1;
    while ((1 << log) < n) ++log;
    size = 1 << log;
    dat.assign(size << 1, MX::unit());
    FOR(i, n) dat[size + i] = f(i);
    FOR_R(i, 1, size) update(i);
  }
  X get(int i) { return dat[size + i]; }
  vc<X> get_all() { return {dat.begin() + size, dat.begin() + size + n}; }
  void update(int i) { dat[i] = Monoid::op(dat[2 * i], dat[2 * i + 1]); }
  void set(int i, const X& x) {
    assert(i < n);
    dat[i += size] = x;
    while (i >>= 1) update(i);
  }
  void multiply(int i, const X& x) {
    assert(i < n);
    i += size;
    dat[i] = Monoid::op(dat[i], x);
    while (i >>= 1) update(i);
  }
  X prod(int L, int R) {
    assert(0 <= L && L <= R && R <= n);
    X vl = Monoid::unit(), vr = Monoid::unit();
    L += size, R += size;
    while (L < R) {
      if (L & 1) vl = Monoid::op(vl, dat[L++]);
      if (R & 1) vr = Monoid::op(dat[--R], vr);
      L >>= 1, R >>= 1;
    }
    return Monoid::op(vl, vr);
  }
  vc<int> prod_ids(int L, int R) {
    assert(0 <= L && L <= R && R <= n);
    vc<int> I, J;
    L += size, R += size;
    while (L < R) {
      if (L & 1) I.eb(L++);
      if (R & 1) J.eb(--R);
      L >>= 1, R >>= 1;
    }
    reverse(all(J));
    concat(I, J);
    return I;
  }
  X prod_all() { return dat[1]; }
  template <class F>
  int max_right(F check, int L) {
    assert(0 <= L && L <= n && check(Monoid::unit()));
    if (L == n) return n;
    L += size;
    X sm = Monoid::unit();
    do {
      while (L % 2 == 0) L >>= 1;
      if (!check(Monoid::op(sm, dat[L]))) {
        while (L < size) {
          L = 2 * L;
          if (check(Monoid::op(sm, dat[L]))) {
            sm = Monoid::op(sm, dat[L++]);
          }
        }
        return L - size;
      }
      sm = Monoid::op(sm, dat[L++]);
    } while ((L & -L) != L);
    return n;
  }
  template <class F>
  int min_left(F check, int R) {
    assert(0 <= R && R <= n && check(Monoid::unit()));
    if (R == 0) return 0;
    R += size;
    X sm = Monoid::unit();
    do {
      --R;
      while (R > 1 && (R % 2)) R >>= 1;
      if (!check(Monoid::op(dat[R], sm))) {
        while (R < size) {
          R = 2 * R + 1;
          if (check(Monoid::op(dat[R], sm))) {
            sm = Monoid::op(dat[R--], sm);
          }
        }
        return R + 1 - size;
      }
      sm = Monoid::op(dat[R], sm);
    } while ((R & -R) != R);
    return 0;
  }
  // prod_{l<=i<r} A[i xor x]
  X xor_prod(int l, int r, int xor_val) {
    static_assert(Monoid::commute);
    X x = Monoid::unit();
    for (int k = 0; k < log + 1; ++k) {
      if (l >= r) break;
      if (l & 1) {
        x = Monoid::op(x, dat[(size >> k) + ((l++) ^ xor_val)]);
      }
      if (r & 1) {
        x = Monoid::op(x, dat[(size >> k) + ((--r) ^ xor_val)]);
      }
      l /= 2, r /= 2, xor_val /= 2;
    }
    return x;
  }
};#line 2 "ds/segtree/segtree.hpp"
template <class Monoid>
struct SegTree {
  using MX = Monoid;
  using X = typename MX::value_type;
  using value_type = X;
  vc<X> dat;
  int n, log, size;
  SegTree() {}
  SegTree(int n) { build(n); }
  template <typename F>
  SegTree(int n, F f) {
    build(n, f);
  }
  SegTree(const vc<X>& v) { build(v); }
  void build(int m) {
    build(m, [](int i) -> X { return MX::unit(); });
  }
  void build(const vc<X>& v) {
    build(len(v), [&](int i) -> X { return v[i]; });
  }
  template <typename F>
  void build(int m, F f) {
    n = m, log = 1;
    while ((1 << log) < n) ++log;
    size = 1 << log;
    dat.assign(size << 1, MX::unit());
    FOR(i, n) dat[size + i] = f(i);
    FOR_R(i, 1, size) update(i);
  }
  X get(int i) { return dat[size + i]; }
  vc<X> get_all() { return {dat.begin() + size, dat.begin() + size + n}; }
  void update(int i) { dat[i] = Monoid::op(dat[2 * i], dat[2 * i + 1]); }
  void set(int i, const X& x) {
    assert(i < n);
    dat[i += size] = x;
    while (i >>= 1) update(i);
  }
  void multiply(int i, const X& x) {
    assert(i < n);
    i += size;
    dat[i] = Monoid::op(dat[i], x);
    while (i >>= 1) update(i);
  }
  X prod(int L, int R) {
    assert(0 <= L && L <= R && R <= n);
    X vl = Monoid::unit(), vr = Monoid::unit();
    L += size, R += size;
    while (L < R) {
      if (L & 1) vl = Monoid::op(vl, dat[L++]);
      if (R & 1) vr = Monoid::op(dat[--R], vr);
      L >>= 1, R >>= 1;
    }
    return Monoid::op(vl, vr);
  }
  vc<int> prod_ids(int L, int R) {
    assert(0 <= L && L <= R && R <= n);
    vc<int> I, J;
    L += size, R += size;
    while (L < R) {
      if (L & 1) I.eb(L++);
      if (R & 1) J.eb(--R);
      L >>= 1, R >>= 1;
    }
    reverse(all(J));
    concat(I, J);
    return I;
  }
  X prod_all() { return dat[1]; }
  template <class F>
  int max_right(F check, int L) {
    assert(0 <= L && L <= n && check(Monoid::unit()));
    if (L == n) return n;
    L += size;
    X sm = Monoid::unit();
    do {
      while (L % 2 == 0) L >>= 1;
      if (!check(Monoid::op(sm, dat[L]))) {
        while (L < size) {
          L = 2 * L;
          if (check(Monoid::op(sm, dat[L]))) {
            sm = Monoid::op(sm, dat[L++]);
          }
        }
        return L - size;
      }
      sm = Monoid::op(sm, dat[L++]);
    } while ((L & -L) != L);
    return n;
  }
  template <class F>
  int min_left(F check, int R) {
    assert(0 <= R && R <= n && check(Monoid::unit()));
    if (R == 0) return 0;
    R += size;
    X sm = Monoid::unit();
    do {
      --R;
      while (R > 1 && (R % 2)) R >>= 1;
      if (!check(Monoid::op(dat[R], sm))) {
        while (R < size) {
          R = 2 * R + 1;
          if (check(Monoid::op(dat[R], sm))) {
            sm = Monoid::op(dat[R--], sm);
          }
        }
        return R + 1 - size;
      }
      sm = Monoid::op(dat[R], sm);
    } while ((R & -R) != R);
    return 0;
  }
  // prod_{l<=i<r} A[i xor x]
  X xor_prod(int l, int r, int xor_val) {
    static_assert(Monoid::commute);
    X x = Monoid::unit();
    for (int k = 0; k < log + 1; ++k) {
      if (l >= r) break;
      if (l & 1) {
        x = Monoid::op(x, dat[(size >> k) + ((l++) ^ xor_val)]);
      }
      if (r & 1) {
        x = Monoid::op(x, dat[(size >> k) + ((--r) ^ xor_val)]);
      }
      l /= 2, r /= 2, xor_val /= 2;
    }
    return x;
  }
};