A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d1/d9e/prefix__sum__array_8cpp_source.html below:

TheAlgorithms/C++: range_queries/prefix_sum_array.cpp Source File

Go to the documentation of this file. 34

std::vector<int64_t> PSA{};

41void build

(

const

std::vector<int64_t>& original_array) {

44 for

(std::size_t i = 1; i < original_array.size(); ++i) {

45

PSA.push_back(PSA.back() + original_array[i]);

54

int64_t

query

(int64_t beg, int64_t end) {

return

PSA[end] - PSA[beg - 1]; }

64

std::vector<int64_t> values{0, 123, 0, 2, -2, 5,

Range sum queries using prefix-sum-array.

int64_t query(int64_t beg, int64_t end)

query function

void build(const std::vector< int64_t > &original_array)

function that builds the PSA

static void test()

Self-test implementations.

int main()

Main function.


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