segment_tree.h
Go to the documentation of this file.
1 /*
2  * This file is part of the alglib project.
3  *
4  * (c) Divyanshu Kakwani <divkakwani@gmail.com>
5  *
6  * For the full copyright and license information, please view the LICENSE file
7  * that was distributed with this source code.
8  */
9 
10 #pragma once
11 
23 template<typename AssocT, typename Aggr>
24 class SegmentTree {
25 
26  private:
27 
28  vector<AssocT> sat_data;
29 
30  int left(int node) { return node << 1; }
31  int right(int node) { return (node << 1) + 1; }
32 
33 
34 
35 
36  public:
37 
38  SegmentTree(std::vector<AssocT>& v);
39 
40  // Point update
41  void update(int i, AssocT& new_val);
42 
43  // Range update
44  template<typename UnaryFunc>
45  void update(int i, int j, UnaryFunc change);
46 
47 
48 
49  AssocT range_query(int i, int j);
50 
51 
52 };
53 
Segment tree class templatized by the type associated with every interval and the means of combining ...
Definition: segment_tree.h:24
void update(int i, AssocT &new_val)
AssocT range_query(int i, int j)
SegmentTree(std::vector< AssocT > &v)