Fenwick Tree with Linear Algebra

Revision en2, by dangcaominh, 2024-05-07 12:35:11

Hello everyone!

While I am solving this problem 1967C - Fenwick Tree, I read Elegia matrix solution and finally came up with my own solution that is based on his approach, using the matrix of linear transformation. Throughout the solution is tons of "heavy-math" knowledges and assumptions that is considered to be hard to see. Motivated enough, I have my heart set on writing an entire blog here with an ambition to prove every details in my solution.

Let's first quote the problem here

Let $$$\operatorname{lowbit}(x)$$$ denote the value of the lowest binary bit of $$$x$$$, e.g. $$$\operatorname{lowbit}(12)=4, \operatorname{lowbit}(8)=8.$$$

For an array $$$a$$$ of length $$$n$$$, if an array $$$s$$$ of length $$$n$$$ satisfies $$$s_k=\left(\sum\limits_{i=k-\operatorname{lowbit}(k)+1}^{k}a_i\right)\bmod 998\,244\,353$$$ for all $$$k$$$, then $$$s$$$ is called the Fenwick Tree of $$$a$$$. Let's denote it as $$$s=f(a).$$$

For a positive integer $$$k$$$ and an array $$$a$$$, $$$f_k(a)$$$ is defined as follows:

$$$ f^k(a)= \begin{cases} f(a)&\textrm{if }k=1\\ f(f^{k-1}(a))&\textrm{otherwise.}\\ \end{cases} $$$

You are given an array $$$b$$$ of length $$$n$$$ and a positive integer $$$k$$$. Find an array $$$a$$$ that satisfies $$$0\leq a_i <998244353$$$ and $$$f_k(a)=b$$$. It can be proved that an answer always exists. If there are multiple possible answers, you may print any of them.

The definition of $$$s_k$$$ makes us think of the linear map $$$T: \mathbb{R_n}\rightarrow \mathbb{R_n}$$$ which map a vetor array $$$a$$$ to the Fenwick Tree of $$$a$$$, in other words $$$T(a)=f(a)$$$. Note that $$$R_n$$$ here is the set of all matrices with size $$$n\times 1$$$ and if $$$a \in \mathbb{R_n}$$$ then

$$$ a = \begin{pmatrix} a_1 \\ a_2 \\ \vdots \\ a_n \end{pmatrix}. $$$

From the definition of $$$s_k$$$ we can see that the matrix $$$T$$$ of the linear map is

$$$ T = (t_{ij})_{1\leq i, j \leq n} $$$

and satisfy

$$$ t_{ij}= \begin{cases} 1&\textrm{if } i-\operatorname{lowbit}(i)+1\leq j\leq i\\ 0&\textrm{otherwise.}\\ \end{cases},\forall 1\leq i, j \leq n $$$

For example, with $$$n=10$$$, we have

$$$ T = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 \end{pmatrix}. $$$
Tags linear algebra, cayley-hamilton, fenwick tree, math

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en11 English dangcaominh 2024-09-20 13:28:41 69
en10 English dangcaominh 2024-05-08 10:09:21 2527 (published)
en9 English dangcaominh 2024-05-08 09:44:06 3162 (saved to drafts)
en8 English dangcaominh 2024-05-07 18:26:44 1 (published)
en7 English dangcaominh 2024-05-07 18:26:15 72
en6 English dangcaominh 2024-05-07 18:23:10 1658
en5 English dangcaominh 2024-05-07 17:20:50 1725
en4 English dangcaominh 2024-05-07 16:32:39 1499
en3 English dangcaominh 2024-05-07 13:28:08 664
en2 English dangcaominh 2024-05-07 12:35:11 2483 Tiny change: 'lem:1967C] , I read [' -> 'lem:1967C], I read ['
en1 English dangcaominh 2024-05-07 09:29:16 60 Initial revision (saved to drafts)