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 | |
std::vector< int64_t > | range_queries::prefix_sum_array::PSA (1, 0) |
void | range_queries::prefix_sum_array::build (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. | |
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 | ( | 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 80 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 52 of file prefix_sum_array.cpp.
|
static |
Self-test implementations.
Definition at line 61 of file prefix_sum_array.cpp.