Блог пользователя 5k_sync_closer

Автор 5k_sync_closer, история, 33 часа назад, По-английски

My IP has been banned from luogu for some reason, so I'm asking this question on CF.

Question:

If string S and T with same length has $$$k$$$ or less different characters, we say S matches T,

then if A and B are given, how to find every substring of A that matches B?

My English is poor, so there would be some grammar mistakes, but I think u can understand what I mean.

I don't need trivial solutions such as $$$O(n^2)$$$ (brute) or $$$O(nk\log n)$$$ (hash) or $$$O(\dfrac{n^2\Sigma}w)$$$ (bitset, probably not faster than brute).

  • Проголосовать: нравится
  • +14
  • Проголосовать: не нравится

»
33 часа назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

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

»
33 часа назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

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

»
33 часа назад, # |
  Проголосовать: нравится -6 Проголосовать: не нравится

Just check if B has $$$\leqslant k$$$ distinct characters. If yes — the answer is $$$\max(0, |S| - |T| + 1)$$$, if no — the answer is $$$0$$$. This is $$$O(n \log n)$$$ or $$$O(n)$$$ depending on your computational model and implementation.

»
33 часа назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

can you describe the bitset solution in details ?

  • »
    »
    33 часа назад, # ^ |
      Проголосовать: нравится -8 Проголосовать: не нравится

    Find every substring $$$S$$$ of length $$$|B|$$$ in A,for each letter $$$c$$$(from a to z) extract the bitset of the $$$c$$$'s occurrence in $$$S$$$ and in $$$B$$$, then count bits that is $$$1$$$ in $$$S$$$'s bitset and is $$$0$$$ in $$$B$$$'s.

»
33 часа назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

OK now I know the solution: FFT. $$$O(n\Sigma\log n)$$$.

but I gtg so goodbye