CP Python LibraryGitHub

Rolling Hash

Calculates a hash of all substrings so that it can be compared in O(1)O(1).

__init__

Calculates the hash of all substrings.

Arguments

Complexities

where nn represents the length of the string S.

add

Concatenates two hashes of strings.

Arguments

Returns

Complexities

__getitem__

Returns the hash of the substring S[l:r]S[l:r].

Arguments

Returns

Complexities

__setitem__

Changes the character at index i to c.

Arguments

Complexities

Code Test