Pagini recente » Diferente pentru utilizator/vially intre reviziile 19 si 20 | Monitorul de evaluare | Monitorul de evaluare | Diferente pentru minimal-enclosing-circle intre reviziile 33 si 32 | Diferente pentru blog/square-root-trick intre reviziile 81 si 80
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. 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.
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.
!<{margin-right: 20px; auto;display:block;}blog/square-root-trick?image00.png!
return s
==
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.
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.
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.