Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Build(const vector<int64>& data, int cur_h, int l, int cur_d, int ind) {
- if (cur_h == 1) {
- if (l < tree_.size()) {
- int data_ind = (ind<<(h_ - cur_d)) + (1<<(h_ - cur_d - 1)) - 1;
- tree_[l] = (data_ind < data.size()) ? data[data_ind] : data.back();
- }
- return;
- }
- int top_h = (cur_h + 1) / 2;
- int bot_h = cur_h - top_h;
- int top_am = (1<<top_h) - 1;
- int bot_am = (1<<bot_h) - 1;
- Build(data, top_h, l, cur_d, ind);
- int subtree_am = top_am + 1;
- int left = l + top_am;
- int st_ind = ind * (1<<top_h);
- for (int i = 0; i < subtree_am; ++i) {
- Build(data, bot_h, left, cur_d + top_h, st_ind);
- left += bot_am;
- st_ind += 1;
- }
- d_[h + top_h] = cur_h;
- bt_[h + top_h] = cur_d;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement