MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / build_segtree

Function build_segtree

CPP/Segment Tree/Sum query.cpp:100–110  ·  view source on GitHub ↗

------------------------Do not write above this line----------------------------------------------------------------------------------------------------------------- Segment-Tree (Sum-Update, Sum-Query) 1-based indexing pass the vectors as reference

Source from the content-addressed store, hash-verified

98//1-based indexing
99//pass the vectors as reference
100void build_segtree(vl &vec,ll curr,ll l,ll r,vl &segtree){
101 if(l==r){
102 segtree[curr]=vec[l];
103 }
104 else{
105 int mid=(l+r)/2;
106 build_segtree(vec,2*curr,l,mid,segtree);
107 build_segtree(vec,2*curr+1,mid+1,r,segtree);
108 segtree[curr]=segtree[2*curr]+segtree[2*curr+1];
109 }
110}
111
112ll sum_segtree(ll curr,ll curr_l,ll curr_r,ll l,ll r,vl &segtree){
113 if(l>r){

Callers 1

solveFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected