Pagini recente » Istoria paginii utilizator/boss_2007 | Atasamentele paginii Profil Boss_2007 | Profil PlayLikeNeverB4 | Monitorul de evaluare | Diferente pentru blog/square-root-trick intre reviziile 80 si 81
Nu exista diferente intre titluri.
Diferente intre continut:
The update takes constant time, because we have to update the value for A and the value for the corresponding $S$.
!<{margin-right: 20px; auto;display:block;}blog/square-root-trick?image01.png!
The query is interesting. Slices completely contained in our range are summed up fast. The elements of the first and last slice (partially contained in the queried range) have to be traversed one by one.
The query is interesting. The elements of the first and last slice (partially contained in the queried range) have to be traversed one by one, but for slices completely contained in our range we can use the values in $S$ directly and get a performance boost.
!<{margin-right: 20px; auto;display:block;}blog/square-root-trick?image00.png!
return s
==
The query takes less than $k + n/k + k = 2k + n/k$ time. $2k + n/k$ is minimized when $k$ is $O(sqrt(n))$. For $k = sqrt(n)$ the query takes $O(sqrt(n))$ time.
Each query takes less than $k + n/k + k = 2k + n/k$ time. For $k = sqrt(n)$ we get a $O(sqrt(n))$ time complexity query.
This trick also works for other associative operations, like: min, gcd, product etc.
Nu exista diferente intre securitate.
Topicul de forum nu a fost schimbat.