I have $P$ vectors of size $N$ with elements in $\{0,1\}$. Each vector $v$ has a value $\alpha_v$.
I would like to Fill a square matrix $M$ of size $N\times N$ in the following way:
$$\forall i,j \in \{1,2,...,N\}~ M_{i,j} = \sum_{\text{vectors}~v : v_i v_j =1} \alpha_v$$
Is it possible to fill the matrix $M$ in time complexity better than $O(P\cdot N^2)$?
Assuming that each vector has at most $Q$ elements equal to $1$, is it possible to do better than $O(P\cdot(N+Q^2))$ ?