I am sorry if the title was misleading, but I really did not know how to address this.
Basically, the problem is the following: we have a bit vector T and a bit vector P.
Let's say P[a1], P[a2], ..., P[ak] are the 1 bits in P. I am interested in knowing, for each position i in T, how many bits of 1 are amongst P[i+a1], P[i+a2], ..., P[i+ak]. It's like putting P as a mask over the substring starting at i and checking how many bits of 1 there are in the end. If the number is impossible to get in good time, checking whether all the bits are 1 should suffice.
Is there a better algorithm that can solve this (better than the O(T*P) "naive" one of "sliding" the pattern from position to position and counting the number of occurences)?
Even a better constant of multiplication would be great in this case. I have heard you can use bitsets on C++ and get something like O( 1/32 * T * (T - P) ), but I am not very familiarized with bitsets and how they operate and such. Are there fast (&) operations on bitsets avaliable?