Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. void Build(const vector<int64>& data, int cur_h, int l, int cur_d, int ind) {
  2.         if (cur_h == 1) {
  3.             if (l < tree_.size()) {
  4.                 int data_ind = (ind<<(h_ - cur_d)) + (1<<(h_ - cur_d - 1)) - 1;
  5.                 tree_[l] = (data_ind < data.size()) ? data[data_ind] : data.back();
  6.             }
  7.             return;
  8.         }
  9.  
  10.         int top_h = (cur_h + 1) / 2;
  11.         int bot_h = cur_h - top_h;
  12.         int top_am = (1<<top_h) - 1;
  13.         int bot_am = (1<<bot_h) - 1;
  14.  
  15.         Build(data, top_h, l, cur_d, ind);
  16.  
  17.         int subtree_am = top_am + 1;
  18.         int left = l + top_am;
  19.         int st_ind = ind * (1<<top_h);
  20.  
  21.         for (int i = 0; i < subtree_am; ++i) {
  22.             Build(data, bot_h, left, cur_d + top_h, st_ind);
  23.             left += bot_am;
  24.             st_ind += 1;
  25.         }
  26.  
  27.         d_[h + top_h] = cur_h;
  28.         bt_[h + top_h] = cur_d;
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement