MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / sum

Function sum

CSES_Problems/Range-Sum Query 1/Range-Sum Query.cpp:18–24  ·  view source on GitHub ↗

Function to answer queries in logN time,what we are doing here is we are traversing the whole tree and we are going to it's their child then if current range in tree is exist inside the range [l,r],then we will add that value

Source from the content-addressed store, hash-verified

16}
17//Function to answer queries in logN time,what we are doing here is we are traversing the whole tree and we are going to it's their child then if current range in tree is exist inside the range [l,r],then we will add that value
18ll sum(ll v,ll tl,ll tr,ll l,ll r,ll dp[])
19{
20 if(l>r)return 0;
21 if(tl==l&&tr==r)return dp[v];
22 ll tm=(tl+tr)/2;
23 return sum(v*2,tl,tm,l,min(r,tm),dp)+sum(v*2+1,tm+1,tr,max(l,tm+1),r,dp);
24}
25int main()
26{
27 ll n,q; cin>>n>>q; ll a[n+10],i,dp[4*n+10],tl,tr,v;

Callers 10

rolldice_sum_probFunction · 0.85
hIndexMethod · 0.85
runningSumMethod · 0.85
maxsetFunction · 0.85
mainFunction · 0.85
organizingContainersFunction · 0.85
fibonacciFunction · 0.85
miniMaxSumFunction · 0.85
checkFunction · 0.85
funcFunction · 0.85

Calls 2

minFunction · 0.85
maxFunction · 0.85

Tested by

no test coverage detected