Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int segment_tree_size;
- vector<int> segment_tree;
- void change(int point, int value){
- point += segment_tree_size - 1;
- segment_tree[point] = value;
- while(point){
- point = (point - 1) / 2;
- segment_tree[point] = segment_tree[point * 2 + 1] + segment_tree[point * 2 + 2];
- }
- }
- int range_sum(int left, int right, int now, int point_left, int point_right){
- if(right <= point_left || point_right <= left){
- return 0;
- }else if(left <= point_left && point_right <= right){
- return segment_tree[now];
- }else{
- return range_sum(left, right, now * 2 + 1, point_left, (point_left + point_right) / 2) +
- range_sum(left, right, now * 2 + 2, (point_left + point_right) / 2, point_right);
- }
- }
Add Comment
Please, Sign In to add comment