# 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 make the insertions in groups,for $n = \sum 2 ^ {a_i}(a_i > a_{i + 1})$,We can make $n$ insertions into groups,each group has $2^{a_k}$ insertions,in this way we divided insertions to $\log_2{n}$ groups.Then we build a data structure for each group of insertions using the construct algorithm.↵
↵
When we insert a newinsetionelement,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 insertionelements 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)$ to construct 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. ↵
↵
In [CF710F](https://codeforces.me/contest/710/problem/F),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:↵
↵
1. Run all the ACAMs in the group of inserted strings and add $x_i$ to answer while arriving index $i$.↵
2. 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](https://codeforces.me/contest/710/submission/276537869).↵
↵
# written at the end of the blog↵
We would like to thank:↵
↵
1. Masters who invent and use the method;↵
2. [user:zhengqingyuan,2024-09-12] edit the blog;↵
3. [user:unalive,2024-09-12] to give advice and make the blog better.
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 make the insertions in groups,for $n = \sum 2 ^ {a_i}(a_i > a_{i + 1})$,We can make $n$ insertions into groups,each group has $2^{a_k}$ insertions,in this way we divided insertions 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
# 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. ↵
↵
In [CF710F](https://codeforces.me/contest/710/problem/F),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:↵
↵
1. Run all the ACAMs in the group of inserted strings and add $x_i$ to answer while arriving index $i$.↵
2. 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](https://codeforces.me/contest/710/submission/276537869).↵
↵
# written at the end of the blog↵
We would like to thank:↵
↵
1. Masters who invent and use the method;↵
2. [user:zhengqingyuan,2024-09-12] edit the blog;↵
3. [user:unalive,2024-09-12] to give advice and make the blog better.