1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once


#include <concepts><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.


#include "internal/dev_env.hpp"
#include "internal/types.hpp"


namespace uni {


template<std::integral SizeType>
struct segment_tree_rooter {
    using size_type = SizeType;

  private:
    size_type _n = 0;

  public:
    segment_tree_rooter() noexcept = default;

    explicit segment_tree_rooter(const size_type n) noexcept(NO_EXCEPT) : _n(n) {};

    inline size_type size() const noexcept(NO_EXCEPT) { return this->_n; }
    inline size_type allocated() const noexcept(NO_EXCEPT) { return (this->_n << 1) - 1; }

    template<std::invocable<size_type> F>
    void range_to_nodes(size_type l, size_type r, F&& f) noexcept(NO_EXCEPT) {
        l += this->_n;
        r += this->_n;

        while(l < r) {
            if(l & 1) f(l++ - 1);
            if(r & 1) f(--r - 1);
            l >>= 1;
            r >>= 1;
        }
    }

    size_type point_to_node(const size_type p) noexcept(NO_EXCEPT) { return this->_n + p - 1; }

    template<std::invocable<size_type> F>
    void point_to_path(size_type p, F&& f) noexcept(NO_EXCEPT) {
        p += this->_n;
        while(p > 0) f(p - 1), p >>= 1;
    }
};

}