Pagini recente » Diferente pentru utilizator/sheepboy intre reviziile 7 si 6 | Monitorul de evaluare | Diferente pentru problema/lautari intre reviziile 33 si 32 | Monitorul de evaluare | Diferente pentru blog/square-root-trick intre reviziile 60 si 59
Nu exista diferente intre titluri.
Diferente intre continut:
The code looks like this:
== code(c) |
def update(S, A, i, k, x):
S[i/k] = S[i/k] - A[i] + x
A[i] = x
S[i/k] = S[i/k] - A[i] + x
A[i] = x
==
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 code looks like this:
== code(c) |
def query(S, A, lo, hi, k):
s = 0
i = lo
while (i + 1) % k != 0 and i <= hi:
s += A[i]
i += 1
while i + k <= hi:
s += S[i/k]
i += k
while i <= hi:
s += A[i]
i += 1
return s
i = lo
while (i + 1) % k != 0 and i <= hi:
sum += A[i]
i += 1
while i + k <= hi:
sum += S[i/k]
i += k
while i <= hi:
sum += A[i]
i += 1
==
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.
Nu exista diferente intre securitate.
Topicul de forum nu a fost schimbat.