# 1.Introduction↵
Binary grouping is a way to implent dynamic insertion.If you found that datas can be partitioned while solving the querys 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 insetion,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 insertions in the group.Using the method,we get a way to implent dynamic insertion and the method is $O(\sum {f(2 ^ {a_k})) * a_k}) \approx O(f(n)\log_2 n)$ in total.↵
# 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).
Binary grouping is a way to implent dynamic insertion.If you found that datas can be partitioned while solving the querys 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 insetion,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 insertions in the group.Using the method,we get a way to implent dynamic insertion and the method is $O(\sum {f(2 ^ {a_k})
# 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).