Advertisement
hurmawe

2 задача. функция set()

Feb 12th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. void set(const int old_id,const int new_element,const int x,const int lx,const int rx, vector<int>& array)
  2. {
  3.     if (rx - lx == 1)
  4.     {
  5.         array[x] = new_element;
  6.         return;
  7.     }
  8.     int m = (rx+lx) / 2;
  9.     if (old_id < m)
  10.     {
  11.         set(old_id, new_element, 2 * x + 1, lx, m,  array);
  12.     }
  13.     else
  14.     {
  15.         set(old_id, new_element, 2 * x + 2, m, rx, array);
  16.     }
  17.     array[x] = array[2 * x + 2] + array[2 * x + 1];
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement