Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct node // добавлено ячейка дополнительной суммы
- {
- int value_node = NULL;
- int size = NULL;
- int sum;
- int add;
- node* left = nullptr;
- node* right = nullptr;
- node(int new_value)
- {
- value_node = new_value;
- size = 1;
- }
- };
- void add_plant(node* A,int x, const int& left_face, const int& right_face,int left,int right) // размещение дополнительного значение
- {
- Pair left = split(A, left_face);
- Pair right = split(left.second, right_face);
- right.first->add = x;
- left.second = merge(right.first, right.second);
- merge(left.first, left.second);
- }
- void push_down(node* A) // проталкивание
- {
- if (A->left != nullptr)
- {
- A->left->add = A->add;
- }
- if (A->right != nullptr)
- {
- A->right->add = A->add;
- }
- A->value_node += A->add;
- A->add = 0;
- }
- Pair split(node* A,const int& x) // пример расположение функции
- {
- push_down(A);
- if (!A) return { NULL ,NULL };
- int l = A->left->size;
- if (l >= x)
- {
- Pair q = split(A->left, x);
- A->left = q.second;
- update(A);
- return { q.first, A };
- }
- else
- {
- Pair q = split(A->right, x-l-1);
- A->right = q.first;
- update(A);
- return {A, q.second};
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement