zhengqingyuan's blog

By zhengqingyuan, history, 2 months ago, In English

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:

  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.

written at the end of the blog

We would like to thank:

  1. Masters who invent the method;
  2. zhengqingyuan edit the blog;
  3. unalive to give advice and make the blog better.
  4. adamant suggest a good problem as an example of using the trick.
  • Vote: I like it
  • +21
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it +5 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can you explain in more detail?

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      2 months ago, # ^ |
      Rev. 2   Vote: I like it +26 Vote: I do not like it

      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:

      1. It can be constructed in $$$O(f(n))$$$ offline by inserting $$$n$$$ elements.
      2. It can be queried online.
      3. The query for a data structure constructed by inserting elements from set $$$S$$$ can be found by uniting queries from a set of data structures built on a partition of $$$S$$$ in $$$O(g(n, m))$$$ time where $$$m$$$ is number of subsets in partition (associativity).

      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:

      1. At every step we maintain the partition of $$$S$$$ such that all the subsets in the partition have sizes equal to different powers of two. For every subset, we will also have a data structure built on elements contained in it.
      2. To handle an element's insertion, we create a singleton set containing this element, insert this set into our partition, and then merge sets with equal sizes until no two sets have equal sizes anymore. Every time we merge two sets with equal sizes, we delete the data structure corresponding to them and create a data structure for the newly created set. It is easy to see that this process works like "carries" in binary addition and our invariant in 1. is maintained.
      3. To process queries, we simply query every currently alive data structure and unite the returned values of these queries.
»
2 months ago, # |
  Vote: I like it +10 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it +5 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it +5 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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