| 110 | } |
| 111 | |
| 112 | ll sum_segtree(ll curr,ll curr_l,ll curr_r,ll l,ll r,vl &segtree){ |
| 113 | if(l>r){ |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | if(l==curr_l and r==curr_r){ |
| 118 | return segtree[curr]; |
| 119 | } |
| 120 | |
| 121 | ll mid=(curr_l+curr_r)/2; |
| 122 | return sum_segtree(2*curr,curr_l,mid,l,min(r,mid),segtree)+sum_segtree(2*curr+1,mid+1,curr_r,max(l,mid+1),r,segtree); |
| 123 | } |
| 124 | |
| 125 | void update_segtree(ll curr,ll l,ll r,ll pos,ll new_val,vl &segtree){ |
| 126 | if(l==r){ |