Loading...
Searching...
No Matches
A data structure to quickly do operations on ranges: the Segment Tree algorithm implementation. More...
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
Go to the source code of this file.
static void test () Self-test implementations.A data structure to quickly do operations on ranges: the Segment Tree algorithm implementation.
Implementation of the segment tree data structre
Can do point updates (updates the value of some position) and range queries, where it gives the value of some associative opperation done on a range
Both of these operations take O(log N) time
Definition in file segment_tree.cpp.
◆ main()Main function.
Definition at line 130 of file segment_tree.cpp.
130 {
132 return 0;
133}
static void test()
Self-test implementations.
◆ test()Self-test implementations.
Definition at line 112 of file segment_tree.cpp.
112 {
114 t.update(1, 1);
115 t.update(2, 2);
116 t.update(3, 3);
117 t.update(4, 4);
118 t.update(5, 5);
119 assert(t.range_comb(1, 3) == 6);
120 t.update(1, 3);
121 assert(t.range_comb(1, 3) == 8);
122
123 std::cout << "All tests have successfully passed!\n";
124}
class representation of the segment tree
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4