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
| 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 |
| 18 | ll 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 | } |
| 25 | int main() |
| 26 | { |
| 27 | ll n,q; cin>>n>>q; ll a[n+10],i,dp[4*n+10],tl,tr,v; |
no test coverage detected