# 1.Introduction

Binary grouping is a way to implent dynamic insertion.If you found that the query for a data structure constructed by inserted elements from set $$$s$$$ can be answered online and be solved by uniting querys from a set of data structures built on a partition of $$$S$$$ in $$$O(h(n,m))$$$ as $$$m$$$ is the number of subsets in the partition and you can construct a data structure in $$$O(\operatorname{f}(n))$$$,It means that you can divide the elements in groups,for $$$n = \sum 2 ^ {a_i}(a_i > a_{i + 1})$$$,We can divide $$$n$$$ elements into groups,each group has $$$2^{a_k}$$$ elements,in this way we divided elements to $$$\log_2{n}$$$ groups.Then we build a data structure for each group of insertions using the construct algorithm.

When we insert a new element,we divide it in a group,and when we found a group that its size is the same as the new group,we merge the two groups into one group and rebuild a data structure with the elements in the group.Using the method,we get a way to implent dynamic insertion and the method to construct is $$$O(\sum {f(x)})(\sum x = n \log_2 n) \approx O(f(n)\log_2 n)$$$ in total and $$$O(h(n,\log_2 n))$$$ for each query.

# 2.Examples

It can be used for kd-tree,but I haven't found an example on the site,so please leave a comment if you found the example.

The example of using the method on kd-tree is P4148 on luogu,in the problem,the elements is the points in the first operation and we can use kd-tree to deal with the elements and answer the query online.But we have to implent dynamic insertion,so we use this method.

**code**

In CF710F,we use the method on AC-Automation.In the task,we use a group to deal with the inserted string and an another group for deleted strings.In both of the groups,we devide the strings into groups and deal with insertions using the method and make ACAM for each group. When we insert a string,we insert it to the group of inserted strings and insert it to the group of deleted string when we delete it.For querys,if $$$x_i$$$ means that How many string is concluded if we arrive index $$$i$$$ while running the ACAM,$$$y_i$$$ is how many string ends here in the trie,we get $$$x_i = y_i + x_{fail_i}$$$,and the way to get answer is:

- Run all the ACAMs in the group of inserted strings and add $$$x_i$$$ to answer while arriving index $$$i$$$.
- Run all the ACAMs in the group of deleted strings and minus answer by $$$x_i$$$ while arriving index $$$i$$$.

Here is the Accepted submission.

# written at the end of the blog

We would like to thank:

- Masters who invent the method;
- zhengqingyuan edit the blog;
- unalive to give advice and make the blog better.
- adamant suggest a good problem as an example of using the trick.

Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Can you explain in more detail?

Recent comment is deleted,and which part needs more detail?

Maybe I have skill issue, but I like very detailed explanations. I wrote the following in my notes after understanding it.

This trick requires a data structure which satisfies the following:

offlineby inserting $$$n$$$ elements.Now, using this trick we can maintain a set of data structures built on a partition of set $$$S$$$ while processing online queries and also insertions to $$$S$$$. The total amortized time taken for processing insertions will be $$$O(\sum{f(x)}) \; ( \sum{x} = n\log{n})$$$ and the time taken to answer each query will be $$$O(g(n, \log{n}))$$$ (where $$$n$$$ is the total number of elements we insert).

The trick works as follows:

differentpowers of two. For every subset, we will also have a data structure built on elements contained in it.Thank you

upvoted

Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).Auto comment: topic has been updated by zhengqingyuan (previous revision, new revision, compare).