![]() |
TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Prefix Sum Array data structure implementation. More...
#include <cassert>#include <iostream>#include <vector>Go to the source code of this file.
Namespaces | |
| namespace | range_queries |
| for std::vector | |
| namespace | prefix_sum_array |
| Range sum queries using prefix-sum-array. | |
Functions | |
| void | range_queries::prefix_sum_array::build (const std::vector< int64_t > &original_array) |
| function that builds the PSA | |
| int64_t | range_queries::prefix_sum_array::query (int64_t beg, int64_t end) |
| query function | |
| static void | test () |
| Self-test implementations. | |
| int | main () |
| Main function. | |
Variables | |
| std::vector< int64_t > | range_queries::prefix_sum_array::PSA {} |
Prefix Sum Array data structure implementation.
Prefix Sum Array is a data structure, that allows answering sum in some range queries. It can answer most sum range queries in O(1), with a build time complexity of O(N). But it hasn't an update querie.
Definition in file prefix_sum_array.cpp.
| void range_queries::prefix_sum_array::build | ( | const std::vector< int64_t > & | original_array | ) |
function that builds the PSA
| original_array | original array of values |
Definition at line 41 of file prefix_sum_array.cpp.
| int main | ( | void | ) |
Main function.
Definition at line 82 of file prefix_sum_array.cpp.
| int64_t range_queries::prefix_sum_array::query | ( | int64_t | beg, |
| int64_t | end ) |
query function
| beg | begin of the interval to sum |
| end | end of the interval to sum |
Definition at line 54 of file prefix_sum_array.cpp.
|
static |
Self-test implementations.
Definition at line 63 of file prefix_sum_array.cpp.
| std::vector<int64_t> range_queries::prefix_sum_array::PSA {} |
Definition at line 34 of file prefix_sum_array.cpp.