diff --git a/d0/d5a/skip__list_8cpp.html b/d0/d5a/skip__list_8cpp.html index 831eb669f..37206c2f7 100644 --- a/d0/d5a/skip__list_8cpp.html +++ b/d0/d5a/skip__list_8cpp.html @@ -190,7 +190,7 @@ constexpr float data_struc
Here is the call graph for this function:
-
+
diff --git a/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map b/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map index 77b900410..66ab18522 100644 --- a/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map +++ b/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map @@ -1,10 +1,11 @@ - - - - - - - - + + + + + + + + + diff --git a/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 b/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 index 2dc206677..a29f0faef 100644 --- a/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 +++ b/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 @@ -1 +1 @@ -a69a3eaa8b41f050beea8bf77ae4d68b \ No newline at end of file +c520674ae7f7b7ad4a360d4c1159ef43 \ No newline at end of file diff --git a/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg b/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg index ca0968887..455919373 100644 --- a/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg +++ b/d0/d5a/skip__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg @@ -4,11 +4,11 @@ - - + + main - + Node1 @@ -22,76 +22,76 @@ Node2 - -data_structures::SkipList -::displayList + +data_structures::SkipList +::displayList Node1->Node2 - - + + Node4 - -data_structures::SkipList -::insertElement + +data_structures::SkipList +::insertElement Node1->Node4 - - + + Node6 - -std::rand + +std::rand - + Node1->Node6 - - + + - - -Node7 - + + +Node8 + std::srand - - -Node1->Node7 + + +Node1->Node8 - - -Node8 - + + +Node9 + std::time - - -Node1->Node8 + + +Node1->Node9 @@ -99,44 +99,65 @@ Node3 - -std::endl + +std::endl Node2->Node3 - - + + Node4->Node3 - - + + Node5 - -data_structures::SkipList -::randomLevel + +data_structures::SkipList +::randomLevel Node4->Node5 - - + + + + + +Node7 + + +update + + + + + +Node4->Node7 + + Node5->Node6 - - + + + + + +Node7->Node7 + + diff --git a/d1/d9e/prefix__sum__array_8cpp.html b/d1/d9e/prefix__sum__array_8cpp.html index c694729a8..d8c0030c5 100644 --- a/d1/d9e/prefix__sum__array_8cpp.html +++ b/d1/d9e/prefix__sum__array_8cpp.html @@ -218,7 +218,7 @@ Here is the call graph for this function:
Here is the call graph for this function:
-
+
@@ -296,16 +296,23 @@ Here is the call graph for this function:
65 range_queries::prefix_sum_array::build(values);
66 // queries are of the type: sum of the range [a, b] = psa[b] - psa[a-1]
67
-
68 assert(range_queries::prefix_sum_array::query(1, 10) ==
+
68 assert(range_queries::prefix_sum_array::query(1, 10) ==
69 173); // sum of the entire array
-
70 assert(range_queries::prefix_sum_array::query(4, 6) ==
+
70 assert(range_queries::prefix_sum_array::query(4, 6) ==
71 27); // the sum of the interval [4, 6]
-
72 assert(range_queries::prefix_sum_array::query(5, 9) ==
+
72 assert(range_queries::prefix_sum_array::query(5, 9) ==
73 51); // the sum of the interval [5, 9]
74}
void build(std::vector< int64_t > original_array)
function that builds the PSA
Definition: prefix_sum_array.cpp:41
+
int64_t query(std::vector< int64_t > *segtree, std::vector< int64_t > *lazy, uint64_t qlow, uint64_t qhigh, uint64_t low, uint64_t high, uint64_t pos)
Returns the sum of all elements in a range.
Definition: segtree.cpp:62
- +
+Here is the call graph for this function:
+
+
+
+
+ diff --git a/d1/d9e/prefix__sum__array_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map b/d1/d9e/prefix__sum__array_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map new file mode 100644 index 000000000..7b9e62410 --- /dev/null +++ b/d1/d9e/prefix__sum__array_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/d1/d9e/prefix__sum__array_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 b/d1/d9e/prefix__sum__array_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 new file mode 100644 index 000000000..caee2071e --- /dev/null +++ b/d1/d9e/prefix__sum__array_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 @@ -0,0 +1 @@ +f4b2de5e1d80209e03c2c1f60670568b \ No newline at end of file diff --git a/d1/d9e/prefix__sum__array_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg b/d1/d9e/prefix__sum__array_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg new file mode 100644 index 000000000..512595489 --- /dev/null +++ b/d1/d9e/prefix__sum__array_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg @@ -0,0 +1,43 @@ + + + + + + +test + + + +Node1 + + +test + + + + + +Node2 + + +query + + + + + +Node1->Node2 + + + + + +Node2->Node2 + + + + + diff --git a/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map b/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map index d700ab878..6346afe5a 100644 --- a/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map +++ b/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map @@ -1,4 +1,5 @@ - - + + + diff --git a/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 b/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 index f93ad06ff..8f9e24ff8 100644 --- a/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 +++ b/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 @@ -1 +1 @@ -a0f50f064e17dc3de597c81c20292210 \ No newline at end of file +48919acd9bf2bea9236d12aa3f959490 \ No newline at end of file diff --git a/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg b/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg index 8ddae4d58..de146a5f6 100644 --- a/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg +++ b/d1/d9e/prefix__sum__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg @@ -4,11 +4,11 @@ - - + + main - + Node1 @@ -33,5 +33,26 @@ + + +Node3 + + +query + + + + + +Node2->Node3 + + + + + +Node3->Node3 + + + diff --git a/d2/d45/segtree_8cpp.html b/d2/d45/segtree_8cpp.html new file mode 100644 index 000000000..64577989c --- /dev/null +++ b/d2/d45/segtree_8cpp.html @@ -0,0 +1,596 @@ + + + + + + + +Algorithms_in_C++: range_queries/segtree.cpp File Reference + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
Algorithms_in_C++ 1.0.0 +
+
Set of algorithms implemented in C++.
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+ +
segtree.cpp File Reference
+
+
+ +

Implementation of Segment Tree data structure. +More...

+
#include <cassert>
+#include <cmath>
+#include <iostream>
+#include <vector>
+
+Include dependency graph for segtree.cpp:
+
+
+
+
+
+ + + + + + + + + + + + + + + + +

+Functions

void ConsTree (const std::vector< int64_t > &arr, std::vector< int64_t > *segtree, uint64_t low, uint64_t high, uint64_t pos)
 for std::vector More...
 
int64_t query (std::vector< int64_t > *segtree, std::vector< int64_t > *lazy, uint64_t qlow, uint64_t qhigh, uint64_t low, uint64_t high, uint64_t pos)
 Returns the sum of all elements in a range. More...
 
void update (std::vector< int64_t > *segtree, std::vector< int64_t > *lazy, int64_t start, int64_t end, int64_t delta, uint64_t low, uint64_t high, uint64_t pos)
 Updates a range of the segment tree. More...
 
static void test ()
 Self-test implementation. More...
 
int main ()
 Main function. More...
 
+

Detailed Description

+

Implementation of Segment Tree data structure.

+

A segment tree, also known as a statistic tree, is a tree data structure used for storing information about intervals, or segments. Its classical version allows querying which of the stored segments contain a given point, but our modification allows us to perform (query) any binary operation on any range in the array in O(logN) time. Here, we have used addition (+). For range updates, we have used lazy propagation.

+
    +
  • Space Complexity : O(NlogN)
    +
  • +
  • Build Time Complexity : O(NlogN)
    +
  • +
  • Query Time Complexity : O(logN)
    +
    Author
    Madhav Gaba
    +
    +Soham Roy
    +
  • +
+

Function Documentation

+ +

◆ ConsTree()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void ConsTree (const std::vector< int64_t > & arr,
std::vector< int64_t > * segtree,
uint64_t low,
uint64_t high,
uint64_t pos 
)
+
+ +

for std::vector

+

for assert for log2 for IO operations

+

Constructs the initial segment tree

+
Parameters
+ + + + + + +
arrinput to construct the tree out of
segtreethe segment tree
lowinclusive lowest index of arr to begin at
highinclusive highest index of arr to end at
posindex of segtree to fill (eg. root node)
+
+
+
Returns
void
+
38 {
+
39 if (low == high) {
+
40 (*segtree)[pos] = arr[low];
+
41 return;
+
42 }
+
43
+
44 uint64_t mid = (low + high) / 2;
+
45 ConsTree(arr, segtree, low, mid, 2 * pos + 1);
+
46 ConsTree(arr, segtree, mid + 1, high, 2 * pos + 2);
+
47 (*segtree)[pos] = (*segtree)[2 * pos + 1] + (*segtree)[2 * pos + 2];
+
48}
+
void ConsTree(const std::vector< int64_t > &arr, std::vector< int64_t > *segtree, uint64_t low, uint64_t high, uint64_t pos)
for std::vector
Definition: segtree.cpp:37
+
+Here is the call graph for this function:
+
+
+
+
+ +
+
+ +

◆ main()

+ +
+
+ + + + + + + + +
int main (void )
+
+ +

Main function.

+
Returns
0 on exit
+
167 {
+
168 test(); // run self-test implementations
+
169
+
170 std::cout << "Enter number of elements: ";
+
171
+
172 uint64_t n = 0;
+
173 std::cin >> n;
+
174
+
175 uint64_t max = static_cast<uint64_t>(2 * pow(2, ceil(log2(n))) - 1);
+
176 std::vector<int64_t> arr(n), lazy(max), segtree(max);
+
177
+
178 int choice = 0;
+
179 std::cout << "\nDo you wish to enter each number?:\n"
+
180 "1: Yes\n"
+
181 "0: No (default initialize them to 0)\n";
+
182
+
183 std::cin >> choice;
+
184 if (choice == 1) {
+
185 std::cout << "Enter " << n << " numbers:\n";
+
186 for (int i = 1; i <= n; i++) {
+
187 std::cout << i << ": ";
+
188 std::cin >> arr[i];
+
189 }
+
190 }
+
191
+
192 ConsTree(arr, &segtree, 0, n - 1, 0);
+
193
+
194 do {
+
195 std::cout << "\nMake your choice:\n"
+
196 "1: Range update (input)\n"
+
197 "2: Range query (output)\n"
+
198 "0: Exit\n";
+
199 std::cin >> choice;
+
200
+
201 if (choice == 1) {
+
202 std::cout << "Enter 1-indexed lower bound, upper bound & value:\n";
+
203
+
204 uint64_t p = 1, q = 1, v = 0;
+
205 std::cin >> p >> q >> v;
+
206 update(&segtree, &lazy, p - 1, q - 1, v, 0, n - 1, 0);
+
207 } else if (choice == 2) {
+
208 std::cout << "Enter 1-indexed lower bound & upper bound:\n";
+
209
+
210 uint64_t p = 1, q = 1;
+
211 std::cin >> p >> q;
+
212 std::cout << query(&segtree, &lazy, p - 1, q - 1, 0, n - 1, 0);
+
213 std::cout << "\n";
+
214 }
+
215 } while (choice > 0);
+
216
+
217 return 0;
+
218}
+ + +
T ceil(T... args)
+
T max(T... args)
+
T pow(T... args)
+
int64_t query(std::vector< int64_t > *segtree, std::vector< int64_t > *lazy, uint64_t qlow, uint64_t qhigh, uint64_t low, uint64_t high, uint64_t pos)
Returns the sum of all elements in a range.
Definition: segtree.cpp:62
+
static void test()
Self-test implementation.
Definition: segtree.cpp:146
+
void update(std::vector< int64_t > *segtree, std::vector< int64_t > *lazy, int64_t start, int64_t end, int64_t delta, uint64_t low, uint64_t high, uint64_t pos)
Updates a range of the segment tree.
Definition: segtree.cpp:102
+ +
+Here is the call graph for this function:
+
+
+
+
+ +
+
+ +

◆ query()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int64_t query (std::vector< int64_t > * segtree,
std::vector< int64_t > * lazy,
uint64_t qlow,
uint64_t qhigh,
uint64_t low,
uint64_t high,
uint64_t pos 
)
+
+ +

Returns the sum of all elements in a range.

+
Parameters
+ + + + + + + + +
segtreethe segment tree
lazyfor lazy propagation
qlowlower index of the required query
qhighhigher index of the required query
lowlower index of query for this function call
highhigher index of query for this function call
posindex of segtree to consider (eg. root node)
+
+
+
Returns
result of the range query for this function call
+
64 {
+
65 if (low > high || qlow > high || low > qhigh) {
+
66 return 0;
+
67 }
+
68
+
69 if ((*lazy)[pos] != 0) {
+
70 (*segtree)[pos] += (*lazy)[pos] * (high - low + 1);
+
71
+
72 if (low != high) {
+
73 (*lazy)[2 * pos + 1] += (*lazy)[pos];
+
74 (*lazy)[2 * pos + 2] += (*lazy)[pos];
+
75 }
+
76 (*lazy)[pos] = 0;
+
77 }
+
78
+
79 if (qlow <= low && qhigh >= high) {
+
80 return (*segtree)[pos];
+
81 }
+
82
+
83 uint64_t mid = (low + high) / 2;
+
84
+
85 return query(segtree, lazy, qlow, qhigh, low, mid, 2 * pos + 1) +
+
86 query(segtree, lazy, qlow, qhigh, mid + 1, high, 2 * pos + 2);
+
87}
+
+Here is the call graph for this function:
+
+
+
+
+ +
+
+ +

◆ test()

+ +
+
+ + + + + +
+ + + + + + + +
static void test ()
+
+static
+
+ +

Self-test implementation.

+
Returns
void
+
146 {
+
147 int64_t max = static_cast<int64_t>(2 * pow(2, ceil(log2(7))) - 1);
+
148 assert(max == 15);
+
149
+
150 std::vector<int64_t> arr{1, 2, 3, 4, 5, 6, 7}, lazy(max), segtree(max);
+
151 ConsTree(arr, &segtree, 0, 7 - 1, 0);
+
152
+
153 assert(query(&segtree, &lazy, 1, 5, 0, 7 - 1, 0) == 2 + 3 + 4 + 5 + 6);
+
154
+
155 update(&segtree, &lazy, 2, 4, 1, 0, 7 - 1, 0);
+
156 assert(query(&segtree, &lazy, 1, 5, 0, 7 - 1, 0) == 2 + 4 + 5 + 6 + 6);
+
157
+
158 update(&segtree, &lazy, 0, 6, -2, 0, 7 - 1, 0);
+
159 assert(query(&segtree, &lazy, 0, 4, 0, 7 - 1, 0) == -1 + 0 + 2 + 3 + 4);
+
160}
+
+Here is the call graph for this function:
+
+
+
+
+ +
+
+ +

◆ update()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void update (std::vector< int64_t > * segtree,
std::vector< int64_t > * lazy,
int64_t start,
int64_t end,
int64_t delta,
uint64_t low,
uint64_t high,
uint64_t pos 
)
+
+ +

Updates a range of the segment tree.

+
Parameters
+ + + + + + + + + +
segtreethe segment tree
lazyfor lazy propagation
startlower index of the required query
endhigher index of the required query
deltainteger to add to each element of the range
lowlower index of query for this function call
highhigher index of query for this function call
posindex of segtree to consider (eg. root node)
+
+
+
Returns
void
+
104 {
+
105 if (low > high) {
+
106 return;
+
107 }
+
108
+
109 if ((*lazy)[pos] != 0) {
+
110 (*segtree)[pos] += (*lazy)[pos] * (high - low + 1);
+
111
+
112 if (low != high) {
+
113 (*lazy)[2 * pos + 1] += (*lazy)[pos];
+
114 (*lazy)[2 * pos + 2] += (*lazy)[pos];
+
115 }
+
116 (*lazy)[pos] = 0;
+
117 }
+
118
+
119 if (start > high || end < low) {
+
120 return;
+
121 }
+
122
+
123 if (start <= low && end >= high) {
+
124 (*segtree)[pos] += delta * (high - low + 1);
+
125
+
126 if (low != high) {
+
127 (*lazy)[2 * pos + 1] += delta;
+
128 (*lazy)[2 * pos + 2] += delta;
+
129 }
+
130
+
131 return;
+
132 }
+
133
+
134 uint64_t mid = (low + high) / 2;
+
135
+
136 update(segtree, lazy, start, end, delta, low, mid, 2 * pos + 1);
+
137 update(segtree, lazy, start, end, delta, mid + 1, high, 2 * pos + 2);
+
138 (*segtree)[pos] = (*segtree)[2 * pos + 1] + (*segtree)[2 * pos + 2];
+
139}
+
+Here is the call graph for this function:
+
+
+
+
+ +
+
+
+
+ + + + diff --git a/d2/d45/segtree_8cpp.js b/d2/d45/segtree_8cpp.js new file mode 100644 index 000000000..a3e4f9d23 --- /dev/null +++ b/d2/d45/segtree_8cpp.js @@ -0,0 +1,8 @@ +var segtree_8cpp = +[ + [ "ConsTree", "d2/d45/segtree_8cpp.html#ae752659b7c1719d68fdb2ca538a93696", null ], + [ "main", "d2/d45/segtree_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ], + [ "query", "d2/d45/segtree_8cpp.html#a423a97ea0c7ea6e33b5844a6858d902d", null ], + [ "test", "d2/d45/segtree_8cpp.html#aa8dca7b867074164d5f45b0f3851269d", null ], + [ "update", "d2/d45/segtree_8cpp.html#abd3e818681fb2e29cf08f4f60f82c8e0", null ] +]; \ No newline at end of file diff --git a/d2/d45/segtree_8cpp_a423a97ea0c7ea6e33b5844a6858d902d_cgraph.map b/d2/d45/segtree_8cpp_a423a97ea0c7ea6e33b5844a6858d902d_cgraph.map new file mode 100644 index 000000000..fe2b36fef --- /dev/null +++ b/d2/d45/segtree_8cpp_a423a97ea0c7ea6e33b5844a6858d902d_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/d2/d45/segtree_8cpp_a423a97ea0c7ea6e33b5844a6858d902d_cgraph.md5 b/d2/d45/segtree_8cpp_a423a97ea0c7ea6e33b5844a6858d902d_cgraph.md5 new file mode 100644 index 000000000..3281fb778 --- /dev/null +++ b/d2/d45/segtree_8cpp_a423a97ea0c7ea6e33b5844a6858d902d_cgraph.md5 @@ -0,0 +1 @@ +8d1b572d3bf33c468bcf287b1b2812c4 \ No newline at end of file diff --git a/d2/d45/segtree_8cpp_a423a97ea0c7ea6e33b5844a6858d902d_cgraph.svg b/d2/d45/segtree_8cpp_a423a97ea0c7ea6e33b5844a6858d902d_cgraph.svg new file mode 100644 index 000000000..c25ed6975 --- /dev/null +++ b/d2/d45/segtree_8cpp_a423a97ea0c7ea6e33b5844a6858d902d_cgraph.svg @@ -0,0 +1,28 @@ + + + + + + +query + + + +Node1 + + +query + + + + + +Node1->Node1 + + + + + diff --git a/d2/d45/segtree_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map b/d2/d45/segtree_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map new file mode 100644 index 000000000..20192fdbe --- /dev/null +++ b/d2/d45/segtree_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map @@ -0,0 +1,6 @@ + + + + + + diff --git a/d2/d45/segtree_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 b/d2/d45/segtree_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 new file mode 100644 index 000000000..d6ef646eb --- /dev/null +++ b/d2/d45/segtree_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 @@ -0,0 +1 @@ +48d5daf737194344f345cb33b5a9bd3c \ No newline at end of file diff --git a/d2/d45/segtree_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg b/d2/d45/segtree_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg new file mode 100644 index 000000000..c2d3f777e --- /dev/null +++ b/d2/d45/segtree_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg @@ -0,0 +1,85 @@ + + + + + + +test + + + +Node1 + + +test + + + + + +Node2 + + +ConsTree + + + + + +Node1->Node2 + + + + + +Node3 + + +query + + + + + +Node1->Node3 + + + + + +Node4 + + +update + + + + + +Node1->Node4 + + + + + +Node2->Node2 + + + + + +Node3->Node3 + + + + + +Node4->Node4 + + + + + diff --git a/d2/d45/segtree_8cpp_abd3e818681fb2e29cf08f4f60f82c8e0_cgraph.map b/d2/d45/segtree_8cpp_abd3e818681fb2e29cf08f4f60f82c8e0_cgraph.map new file mode 100644 index 000000000..1551226eb --- /dev/null +++ b/d2/d45/segtree_8cpp_abd3e818681fb2e29cf08f4f60f82c8e0_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/d2/d45/segtree_8cpp_abd3e818681fb2e29cf08f4f60f82c8e0_cgraph.md5 b/d2/d45/segtree_8cpp_abd3e818681fb2e29cf08f4f60f82c8e0_cgraph.md5 new file mode 100644 index 000000000..4674bbdec --- /dev/null +++ b/d2/d45/segtree_8cpp_abd3e818681fb2e29cf08f4f60f82c8e0_cgraph.md5 @@ -0,0 +1 @@ +21917203159ef052b59a5fbf8d0d61f3 \ No newline at end of file diff --git a/d2/d45/segtree_8cpp_abd3e818681fb2e29cf08f4f60f82c8e0_cgraph.svg b/d2/d45/segtree_8cpp_abd3e818681fb2e29cf08f4f60f82c8e0_cgraph.svg new file mode 100644 index 000000000..11eaf4570 --- /dev/null +++ b/d2/d45/segtree_8cpp_abd3e818681fb2e29cf08f4f60f82c8e0_cgraph.svg @@ -0,0 +1,28 @@ + + + + + + +update + + + +Node1 + + +update + + + + + +Node1->Node1 + + + + + diff --git a/d2/d45/segtree_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map b/d2/d45/segtree_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map new file mode 100644 index 000000000..befe637dd --- /dev/null +++ b/d2/d45/segtree_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map @@ -0,0 +1,7 @@ + + + + + + + diff --git a/d2/d45/segtree_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 b/d2/d45/segtree_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 new file mode 100644 index 000000000..07cb578cb --- /dev/null +++ b/d2/d45/segtree_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 @@ -0,0 +1 @@ +d31b00bcedd7e042db28c1402546a42a \ No newline at end of file diff --git a/d2/d45/segtree_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg b/d2/d45/segtree_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg new file mode 100644 index 000000000..0ea0127f7 --- /dev/null +++ b/d2/d45/segtree_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg @@ -0,0 +1,118 @@ + + + + + + +main + + + +Node1 + + +main + + + + + +Node2 + + +ConsTree + + + + + +Node1->Node2 + + + + + +Node3 + + +query + + + + + +Node1->Node3 + + + + + +Node4 + + +test + + + + + +Node1->Node4 + + + + + +Node5 + + +update + + + + + +Node1->Node5 + + + + + +Node2->Node2 + + + + + +Node3->Node3 + + + + + +Node4->Node2 + + + + + +Node4->Node3 + + + + + +Node4->Node5 + + + + + +Node5->Node5 + + + + + diff --git a/d2/d45/segtree_8cpp_ae752659b7c1719d68fdb2ca538a93696_cgraph.map b/d2/d45/segtree_8cpp_ae752659b7c1719d68fdb2ca538a93696_cgraph.map new file mode 100644 index 000000000..7b78deeea --- /dev/null +++ b/d2/d45/segtree_8cpp_ae752659b7c1719d68fdb2ca538a93696_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/d2/d45/segtree_8cpp_ae752659b7c1719d68fdb2ca538a93696_cgraph.md5 b/d2/d45/segtree_8cpp_ae752659b7c1719d68fdb2ca538a93696_cgraph.md5 new file mode 100644 index 000000000..9e8c0c75f --- /dev/null +++ b/d2/d45/segtree_8cpp_ae752659b7c1719d68fdb2ca538a93696_cgraph.md5 @@ -0,0 +1 @@ +2fa841aa2ef8e7f2d3fff01b92b93bbe \ No newline at end of file diff --git a/d2/d45/segtree_8cpp_ae752659b7c1719d68fdb2ca538a93696_cgraph.svg b/d2/d45/segtree_8cpp_ae752659b7c1719d68fdb2ca538a93696_cgraph.svg new file mode 100644 index 000000000..c060cc3fd --- /dev/null +++ b/d2/d45/segtree_8cpp_ae752659b7c1719d68fdb2ca538a93696_cgraph.svg @@ -0,0 +1,28 @@ + + + + + + +ConsTree + + + +Node1 + + +ConsTree + + + + + +Node1->Node1 + + + + + diff --git a/d4/d90/classdata__structures_1_1_skip_list.html b/d4/d90/classdata__structures_1_1_skip_list.html index 21868c76e..b0065b2c9 100644 --- a/d4/d90/classdata__structures_1_1_skip_list.html +++ b/d4/d90/classdata__structures_1_1_skip_list.html @@ -194,14 +194,14 @@ int level
133 {
135
- -
137 update.fill(nullptr);
+ +
137 update.fill(nullptr);
138
139 for (int i = level; i >= 0; i--) {
140 while (x->forward[i] != nullptr && x->forward[i]->key < key) {
141 x = x->forward[i];
142 }
-
143 update[i] = x;
+
143 update[i] = x;
144 }
145
146 x = x->forward[0];
@@ -210,10 +210,10 @@ int level
149
150 if (!doesnt_exist) {
151 for (int i = 0; i <= level; i++) {
-
152 if (update[i]->forward[i] != x) {
+
152 if (update[i]->forward[i] != x) {
153 break;
154 }
-
155 update[i]->forward[i] = x->forward[i];
+
155 update[i]->forward[i] = x->forward[i];
156 }
157 /* Remove empty levels*/
158 while (level > 0 && header->forward[level] == nullptr) level--;
@@ -225,11 +225,12 @@ int level
T endl(T... args)
+
void update(std::vector< int64_t > *segtree, std::vector< int64_t > *lazy, int64_t start, int64_t end, int64_t delta, uint64_t low, uint64_t high, uint64_t pos)
Updates a range of the segment tree.
Definition: segtree.cpp:102
Here is the call graph for this function:
-
+
@@ -323,14 +324,14 @@ Here is the call graph for this function:
90 {
91 std::cout << "Inserting" << key << "...";
- -
94 update.fill(nullptr);
+ +
94 update.fill(nullptr);
95
96 for (int i = level; i >= 0; i--) {
97 while (x->forward[i] != nullptr && x->forward[i]->key < key) {
98 x = x->forward[i];
99 }
-
100 update[i] = x;
+
100 update[i] = x;
101 }
102
103 x = x->forward[0];
@@ -340,7 +341,7 @@ Here is the call graph for this function:
107 int rlevel = randomLevel();
108
109 if (rlevel > level) {
-
110 for (int i = level + 1; i < rlevel + 1; i++) update[i] = header;
+
110 for (int i = level + 1; i < rlevel + 1; i++) update[i] = header;
111
112 // Update current level
113 level = rlevel;
@@ -349,8 +350,8 @@ Here is the call graph for this function:
116 std::shared_ptr<Node> n =
117 std::make_shared<Node>(key, rlevel, value);
118 for (int i = 0; i <= rlevel; i++) {
-
119 n->forward[i] = update[i]->forward[i];
-
120 update[i]->forward[i] = n;
+
119 n->forward[i] = update[i]->forward[i];
+
120 update[i]->forward[i] = n;
121 }
122 std::cout << "Inserted" << std::endl;
123
@@ -362,7 +363,7 @@ Here is the call graph for this function:
Here is the call graph for this function:
-
+
diff --git a/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.map b/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.map index a35078fed..cb960361d 100644 --- a/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.map +++ b/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.map @@ -1,6 +1,7 @@ - + + diff --git a/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.md5 b/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.md5 index 5955fbf0f..c235504d9 100644 --- a/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.md5 +++ b/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.md5 @@ -1 +1 @@ -4d2d7fdb4639b7eb2e6b9f9cb3052f5e \ No newline at end of file +f9485b3804fc7ce3951dc366b873c78f \ No newline at end of file diff --git a/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.svg b/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.svg index 2dd5628d9..c7f69f34c 100644 --- a/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.svg +++ b/d4/d90/classdata__structures_1_1_skip_list_a40a4042bdf0b6683b5f21ae7854de8a9_cgraph.svg @@ -4,18 +4,18 @@ - - + + data_structures::SkipList::insertElement - + Node1 - -data_structures::SkipList -::insertElement + +data_structures::SkipList +::insertElement @@ -23,47 +23,68 @@ Node2 - -std::endl + +std::endl Node1->Node2 - - + + Node3 - -data_structures::SkipList -::randomLevel + +data_structures::SkipList +::randomLevel Node1->Node3 - - + + + + + +Node5 + + +update + + + + + +Node1->Node5 + + Node4 - -std::rand + +std::rand Node3->Node4 - - + + + + + +Node5->Node5 + + diff --git a/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.map b/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.map index db6e8d986..57dad5897 100644 --- a/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.map +++ b/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.map @@ -1,4 +1,5 @@ - - + + + diff --git a/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.md5 b/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.md5 index 5ed46af3e..63a10db9c 100644 --- a/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.md5 +++ b/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.md5 @@ -1 +1 @@ -95cab6fb91495582002f6254d98cb111 \ No newline at end of file +6c3cc026ffb7d042d941d8bcd327c497 \ No newline at end of file diff --git a/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.svg b/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.svg index 0b9438b1d..c2836fc09 100644 --- a/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.svg +++ b/d4/d90/classdata__structures_1_1_skip_list_a86925c53e139cc6c3f7df1e9003bb0b0_cgraph.svg @@ -4,18 +4,18 @@ - - + + data_structures::SkipList::deleteElement - + Node1 - -data_structures::SkipList -::deleteElement + +data_structures::SkipList +::deleteElement @@ -23,16 +23,37 @@ Node2 - -std::endl + +std::endl Node1->Node2 - - + + + + + +Node3 + + +update + + + + + +Node1->Node3 + + + + + +Node3->Node3 + + diff --git a/de/db6/segtree_8cpp__incl.map b/de/db6/segtree_8cpp__incl.map new file mode 100644 index 000000000..9d7299d56 --- /dev/null +++ b/de/db6/segtree_8cpp__incl.map @@ -0,0 +1,7 @@ + + + + + + + diff --git a/de/db6/segtree_8cpp__incl.md5 b/de/db6/segtree_8cpp__incl.md5 new file mode 100644 index 000000000..673390d51 --- /dev/null +++ b/de/db6/segtree_8cpp__incl.md5 @@ -0,0 +1 @@ +677eb5bdf1a762b45f2fbf6fce12b807 \ No newline at end of file diff --git a/de/db6/segtree_8cpp__incl.svg b/de/db6/segtree_8cpp__incl.svg new file mode 100644 index 000000000..c36a9abc3 --- /dev/null +++ b/de/db6/segtree_8cpp__incl.svg @@ -0,0 +1,82 @@ + + + + + + +range_queries/segtree.cpp + + + +Node1 + + +range_queries/segtree.cpp + + + + + +Node2 + + +cassert + + + + + +Node1->Node2 + + + + + +Node3 + + +cmath + + + + + +Node1->Node3 + + + + + +Node4 + + +iostream + + + + + +Node1->Node4 + + + + + +Node5 + + +vector + + + + + +Node1->Node5 + + + + + diff --git a/dir_074119ce3a874b57120c49a0cc4bb5ad.html b/dir_074119ce3a874b57120c49a0cc4bb5ad.html index 512417aff..51a14cc5d 100644 --- a/dir_074119ce3a874b57120c49a0cc4bb5ad.html +++ b/dir_074119ce3a874b57120c49a0cc4bb5ad.html @@ -108,6 +108,9 @@ Files
file  prefix_sum_array.cpp
 Prefix Sum Array data structure implementation.

  +file  segtree.cpp + Implementation of Segment Tree data structure.
+  file  sparse_table.cpp  Implementation of Sparse Table data structure.
  diff --git a/dir_074119ce3a874b57120c49a0cc4bb5ad.js b/dir_074119ce3a874b57120c49a0cc4bb5ad.js index a3d83df29..9a303641c 100644 --- a/dir_074119ce3a874b57120c49a0cc4bb5ad.js +++ b/dir_074119ce3a874b57120c49a0cc4bb5ad.js @@ -4,5 +4,6 @@ var dir_074119ce3a874b57120c49a0cc4bb5ad = [ "heavy_light_decomposition.cpp", "d2/de9/heavy__light__decomposition_8cpp.html", "d2/de9/heavy__light__decomposition_8cpp" ], [ "persistent_seg_tree_lazy_prop.cpp", "d5/d58/persistent__seg__tree__lazy__prop_8cpp.html", "d5/d58/persistent__seg__tree__lazy__prop_8cpp" ], [ "prefix_sum_array.cpp", "d1/d9e/prefix__sum__array_8cpp.html", "d1/d9e/prefix__sum__array_8cpp" ], + [ "segtree.cpp", "d2/d45/segtree_8cpp.html", "d2/d45/segtree_8cpp" ], [ "sparse_table.cpp", "d4/d96/range__queries_2sparse__table_8cpp.html", "d4/d96/range__queries_2sparse__table_8cpp" ] ]; \ No newline at end of file diff --git a/files.html b/files.html index 2fc28dd40..9f45c061c 100644 --- a/files.html +++ b/files.html @@ -302,7 +302,8 @@ solve-a-rat-in-a-maze-c-java-pytho/"  heavy_light_decomposition.cppHeavy Light Decomposition implementation  persistent_seg_tree_lazy_prop.cppPersistent segment tree with range updates (lazy propagation)  prefix_sum_array.cppPrefix Sum Array data structure implementation - sparse_table.cppImplementation of Sparse Table data structure + segtree.cppImplementation of Segment Tree data structure + sparse_table.cppImplementation of Sparse Table data structure   search  binary_search.cppBinary search algorithm  exponential_search.cppExponential search algorithm diff --git a/globals_c.html b/globals_c.html index e4bd8f573..336fa7200 100644 --- a/globals_c.html +++ b/globals_c.html @@ -102,6 +102,7 @@ $(document).ready(function(){initNavTree('globals_c.html',''); initResizable();
  • CombSort() : comb_sort.cpp
  • compare() : shell_sort2.cpp
  • complex_str() : durand_kerner_roots.cpp
  • +
  • ConsTree() : segtree.cpp
  • create_list() : hash_search.cpp
  • create_matrix() : qr_eigen_values.cpp
  • create_random_array() : insertion_sort.cpp
  • diff --git a/globals_func_c.html b/globals_func_c.html index 20ba50281..bff1a8ede 100644 --- a/globals_func_c.html +++ b/globals_func_c.html @@ -100,6 +100,7 @@ $(document).ready(function(){initNavTree('globals_func_c.html',''); initResizabl
  • CombSort() : comb_sort.cpp
  • compare() : shell_sort2.cpp
  • complex_str() : durand_kerner_roots.cpp
  • +
  • ConsTree() : segtree.cpp
  • create_list() : hash_search.cpp
  • create_matrix() : qr_eigen_values.cpp
  • create_random_array() : insertion_sort.cpp
  • diff --git a/globals_func_m.html b/globals_func_m.html index fdc700c45..14ca66774 100644 --- a/globals_func_m.html +++ b/globals_func_m.html @@ -93,7 +93,7 @@ $(document).ready(function(){initNavTree('globals_func_m.html',''); initResizabl  

    - m -

    diff --git a/globals_func_t.html b/globals_func_t.html index 45bf3b4c3..6cd8f8433 100644 --- a/globals_func_t.html +++ b/globals_func_t.html @@ -94,7 +94,7 @@ $(document).ready(function(){initNavTree('globals_func_t.html',''); initResizabl

    - t -

    diff --git a/globals_m.html b/globals_m.html index 5f9d060c4..ee4361ac3 100644 --- a/globals_m.html +++ b/globals_m.html @@ -93,7 +93,7 @@ $(document).ready(function(){initNavTree('globals_m.html',''); initResizable();
    Here is a list of all documented file members with links to the documentation:

    - m -